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 {
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;
}
......
......@@ -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<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(
'Standard title golden',
(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