From 486aa63b4cf2d645ba411f385d11f03ab9ba434b Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 13 Dec 2017 18:23:33 -0800 Subject: [PATCH] Apply media padding in Cupertino nav bar (#13550) Applies left and right media padding to Cupertino navigation bar large titles. --- .../flutter/lib/src/cupertino/nav_bar.dart | 8 ++- .../flutter/test/cupertino/nav_bar_test.dart | 52 ++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 8d33dbd3a8c..72116ac9f41 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -498,8 +498,12 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate child: new AnimatedOpacity( opacity: showLargeTitle ? 1.0 : 0.0, duration: _kNavBarTitleFadeDuration, - child: title, - ) + child: new SafeArea( + top: false, + bottom: false, + child: title, + ), + ), ), ), ), diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index 74c8e9a00d6..5d3f06888b3 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -116,6 +116,56 @@ void main() { expect(find.byType(SliverPersistentHeader), findsNothing); }); + testWidgets('Media padding is applied to CupertinoSliverNavigationBar', (WidgetTester tester) async { + final ScrollController scrollController = new ScrollController(); + final Key middleKey = new GlobalKey(); + final Key titleKey = new GlobalKey(); + await tester.pumpWidget( + new WidgetsApp( + color: const Color(0xFFFFFFFF), + onGenerateRoute: (RouteSettings settings) { + return new CupertinoPageRoute( + settings: settings, + builder: (BuildContext context) { + return new MediaQuery( + data: const MediaQueryData( + padding: const EdgeInsets.only( + top: 10.0, + left: 20.0, + bottom: 30.0, + right: 40.0, + ), + ), + child: new CupertinoPageScaffold( + child: new CustomScrollView( + controller: scrollController, + slivers: [ + new CupertinoSliverNavigationBar( + middle: new Text('Not-large Title', key: middleKey), + largeTitle: new Text('Large Title', key: titleKey), + ), + new SliverToBoxAdapter( + child: new Container( + height: 1200.0, + ), + ), + ], + ), + ), + ); + }, + ); + }, + ), + ); + + // Top padding is applied to middle. + expect(tester.getTopLeft(find.byKey(middleKey)), const Offset(277.5, 13.5 + 10.0)); + + // Top and left padding is applied to large title. + expect(tester.getTopLeft(find.byKey(titleKey)), const Offset(16.0 + 20.0, 58.0 + 10.0)); + }); + testWidgets('Large title nav bar scrolls', (WidgetTester tester) async { final ScrollController scrollController = new ScrollController(); await tester.pumpWidget( @@ -357,4 +407,4 @@ class _ExpectStyles extends StatelessWidget { count += index; return new Container(); } -} \ No newline at end of file +}