diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 749b3418f8..7134a235ea 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -195,6 +195,7 @@ class CupertinoSliverNavigationBar extends StatelessWidget { this.automaticallyImplyLeading = true, this.middle, this.trailing, + this.border = _kDefaultNavBarBorder, this.backgroundColor = _kDefaultNavBarBackgroundColor, this.actionsForegroundColor = CupertinoColors.activeBlue, }) : assert(largeTitle != null), @@ -245,6 +246,11 @@ class CupertinoSliverNavigationBar extends StatelessWidget { /// This widget is visible in both collapsed and expanded states. final Widget trailing; + /// The border of the navigation bar. By default renders a single pixel bottom border side. + /// + /// If a border is null, the navigation bar will not display a border. + final Border border; + /// The background color of the navigation bar. If it contains transparency, the /// tab bar will automatically produce a blurring effect to the content /// behind it. @@ -271,6 +277,7 @@ class CupertinoSliverNavigationBar extends StatelessWidget { automaticallyImplyLeading: automaticallyImplyLeading, middle: middle, trailing: trailing, + border: border, backgroundColor: backgroundColor, actionsForegroundColor: actionsForegroundColor, ), @@ -447,8 +454,8 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate this.automaticallyImplyLeading, this.middle, this.trailing, - this.border = _kDefaultNavBarBorder, - this.backgroundColor = _kDefaultNavBarBackgroundColor, + this.border, + this.backgroundColor, this.actionsForegroundColor, }) : assert(persistentHeight != null); @@ -552,6 +559,7 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate || leading != oldDelegate.leading || middle != oldDelegate.middle || trailing != oldDelegate.trailing + || border != oldDelegate.border || backgroundColor != oldDelegate.backgroundColor || actionsForegroundColor != oldDelegate.actionsForegroundColor; } diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index ee572d81e0..fd3e080bf4 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -415,7 +415,10 @@ void main() { ), ); - final DecoratedBox decoratedBox = tester.widgetList(find.byType(DecoratedBox)).elementAt(1); + final DecoratedBox decoratedBox = tester.widgetList(find.descendant( + of: find.byType(CupertinoNavigationBar), + matching: find.byType(DecoratedBox), + )).first; expect(decoratedBox.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = decoratedBox.decoration; @@ -448,7 +451,10 @@ void main() { ), ); - final DecoratedBox decoratedBox = tester.widgetList(find.byType(DecoratedBox)).elementAt(1); + final DecoratedBox decoratedBox = tester.widgetList(find.descendant( + of: find.byType(CupertinoNavigationBar), + matching: find.byType(DecoratedBox), + )).first; expect(decoratedBox.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = decoratedBox.decoration; @@ -477,13 +483,138 @@ void main() { ), ); - final DecoratedBox decoratedBox = tester.widgetList(find.byType(DecoratedBox)).elementAt(1); + final DecoratedBox decoratedBox = tester.widgetList(find.descendant( + of: find.byType(CupertinoNavigationBar), + matching: find.byType(DecoratedBox), + )).first; expect(decoratedBox.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = decoratedBox.decoration; expect(decoration.border, isNull); }); + testWidgets( + 'Border is displayed by default in sliver nav bar', + (WidgetTester tester) async { + await tester.pumpWidget( + new WidgetsApp( + color: const Color(0xFFFFFFFF), + onGenerateRoute: (RouteSettings settings) { + return new CupertinoPageRoute( + settings: settings, + builder: (BuildContext context) { + return new CupertinoPageScaffold( + child: new CustomScrollView( + slivers: const [ + const CupertinoSliverNavigationBar( + largeTitle: const Text('Large Title'), + ), + ], + ), + ); + }, + ); + }, + ), + ); + + final DecoratedBox decoratedBox = tester.widgetList(find.descendant( + of: find.byType(CupertinoSliverNavigationBar), + matching: find.byType(DecoratedBox), + )).first; + expect(decoratedBox.decoration.runtimeType, BoxDecoration); + + final BoxDecoration decoration = decoratedBox.decoration; + expect(decoration.border, isNotNull); + + final BorderSide bottom = decoration.border.bottom; + expect(bottom, isNotNull); + }); + + testWidgets( + 'Border is not displayed when null in sliver nav bar', + (WidgetTester tester) async { + await tester.pumpWidget( + new WidgetsApp( + color: const Color(0xFFFFFFFF), + onGenerateRoute: (RouteSettings settings) { + return new CupertinoPageRoute( + settings: settings, + builder: (BuildContext context) { + return new CupertinoPageScaffold( + child: new CustomScrollView( + slivers: const [ + const CupertinoSliverNavigationBar( + largeTitle: const Text('Large Title'), + border: null, + ), + ], + ), + ); + }, + ); + }, + ), + ); + + final DecoratedBox decoratedBox = tester.widgetList(find.descendant( + of: find.byType(CupertinoSliverNavigationBar), + matching: find.byType(DecoratedBox), + )).first; + expect(decoratedBox.decoration.runtimeType, BoxDecoration); + + final BoxDecoration decoration = decoratedBox.decoration; + expect(decoration.border, isNull); + }); + + testWidgets( + 'Border can be overridden in sliver nav bar', + (WidgetTester tester) async { + await tester.pumpWidget( + new WidgetsApp( + color: const Color(0xFFFFFFFF), + onGenerateRoute: (RouteSettings settings) { + return new CupertinoPageRoute( + settings: settings, + builder: (BuildContext context) { + return new CupertinoPageScaffold( + child: new CustomScrollView( + slivers: const [ + const CupertinoSliverNavigationBar( + largeTitle: const Text('Large Title'), + border: const Border( + bottom: const BorderSide( + color: const Color(0xFFAABBCC), + width: 0.0, + ), + ), + ), + ], + ), + ); + }, + ); + }, + ), + ); + + final DecoratedBox decoratedBox = tester.widgetList(find.descendant( + of: find.byType(CupertinoSliverNavigationBar), + matching: find.byType(DecoratedBox), + )).first; + expect(decoratedBox.decoration.runtimeType, BoxDecoration); + + final BoxDecoration decoration = decoratedBox.decoration; + expect(decoration.border, isNotNull); + + final BorderSide top = decoration.border.top; + expect(top, isNotNull); + expect(top, BorderSide.none); + final BorderSide bottom = decoration.border.bottom; + expect(bottom, isNotNull); + expect(bottom.color, const Color(0xFFAABBCC)); + }); + testWidgets( 'Standard title golden', (WidgetTester tester) async {