Commit 4bbd4ce9 authored by Edman P. Anjos's avatar Edman P. Anjos Committed by xster

Surface border parameter in CupertinoSliverNavigationBar (#18194)

* Surface border parameter in CupertinoSliverNavigationBar (#18152)

* Add tests for CupertinoSliverNavigationBar border

* Remove unused keys, find by descendant
parent 199d945b
...@@ -195,6 +195,7 @@ class CupertinoSliverNavigationBar extends StatelessWidget { ...@@ -195,6 +195,7 @@ class CupertinoSliverNavigationBar extends StatelessWidget {
this.automaticallyImplyLeading = true, this.automaticallyImplyLeading = true,
this.middle, this.middle,
this.trailing, this.trailing,
this.border = _kDefaultNavBarBorder,
this.backgroundColor = _kDefaultNavBarBackgroundColor, this.backgroundColor = _kDefaultNavBarBackgroundColor,
this.actionsForegroundColor = CupertinoColors.activeBlue, this.actionsForegroundColor = CupertinoColors.activeBlue,
}) : assert(largeTitle != null), }) : assert(largeTitle != null),
...@@ -245,6 +246,11 @@ class CupertinoSliverNavigationBar extends StatelessWidget { ...@@ -245,6 +246,11 @@ class CupertinoSliverNavigationBar extends StatelessWidget {
/// This widget is visible in both collapsed and expanded states. /// This widget is visible in both collapsed and expanded states.
final Widget trailing; 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 /// The background color of the navigation bar. If it contains transparency, the
/// tab bar will automatically produce a blurring effect to the content /// tab bar will automatically produce a blurring effect to the content
/// behind it. /// behind it.
...@@ -271,6 +277,7 @@ class CupertinoSliverNavigationBar extends StatelessWidget { ...@@ -271,6 +277,7 @@ class CupertinoSliverNavigationBar extends StatelessWidget {
automaticallyImplyLeading: automaticallyImplyLeading, automaticallyImplyLeading: automaticallyImplyLeading,
middle: middle, middle: middle,
trailing: trailing, trailing: trailing,
border: border,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
actionsForegroundColor: actionsForegroundColor, actionsForegroundColor: actionsForegroundColor,
), ),
...@@ -447,8 +454,8 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate ...@@ -447,8 +454,8 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate
this.automaticallyImplyLeading, this.automaticallyImplyLeading,
this.middle, this.middle,
this.trailing, this.trailing,
this.border = _kDefaultNavBarBorder, this.border,
this.backgroundColor = _kDefaultNavBarBackgroundColor, this.backgroundColor,
this.actionsForegroundColor, this.actionsForegroundColor,
}) : assert(persistentHeight != null); }) : assert(persistentHeight != null);
...@@ -552,6 +559,7 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate ...@@ -552,6 +559,7 @@ class _CupertinoLargeTitleNavigationBarSliverDelegate
|| leading != oldDelegate.leading || leading != oldDelegate.leading
|| middle != oldDelegate.middle || middle != oldDelegate.middle
|| trailing != oldDelegate.trailing || trailing != oldDelegate.trailing
|| border != oldDelegate.border
|| backgroundColor != oldDelegate.backgroundColor || backgroundColor != oldDelegate.backgroundColor
|| actionsForegroundColor != oldDelegate.actionsForegroundColor; || actionsForegroundColor != oldDelegate.actionsForegroundColor;
} }
......
...@@ -415,7 +415,10 @@ void main() { ...@@ -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); expect(decoratedBox.decoration.runtimeType, BoxDecoration);
final BoxDecoration decoration = decoratedBox.decoration; final BoxDecoration decoration = decoratedBox.decoration;
...@@ -448,7 +451,10 @@ void main() { ...@@ -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); expect(decoratedBox.decoration.runtimeType, BoxDecoration);
final BoxDecoration decoration = decoratedBox.decoration; final BoxDecoration decoration = decoratedBox.decoration;
...@@ -477,13 +483,138 @@ void main() { ...@@ -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); expect(decoratedBox.decoration.runtimeType, BoxDecoration);
final BoxDecoration decoration = decoratedBox.decoration; final BoxDecoration decoration = decoratedBox.decoration;
expect(decoration.border, isNull); 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<void>(
settings: settings,
builder: (BuildContext context) {
return new CupertinoPageScaffold(
child: new CustomScrollView(
slivers: const <Widget>[
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<void>(
settings: settings,
builder: (BuildContext context) {
return new CupertinoPageScaffold(
child: new CustomScrollView(
slivers: const <Widget>[
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<void>(
settings: settings,
builder: (BuildContext context) {
return new CupertinoPageScaffold(
child: new CustomScrollView(
slivers: const <Widget>[
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( testWidgets(
'Standard title golden', 'Standard title golden',
(WidgetTester tester) async { (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment