Unverified Commit 364d73c7 authored by xster's avatar xster Committed by GitHub

Make CupertinoNavigationBarBackButton correctly return an assert error (#30815)

parent d6285371
......@@ -1231,7 +1231,7 @@ class CupertinoNavigationBarBackButton extends StatelessWidget {
Widget build(BuildContext context) {
final ModalRoute<dynamic> currentRoute = ModalRoute.of(context);
assert(
currentRoute.canPop,
currentRoute?.canPop == true,
'CupertinoNavigationBarBackButton should only be used in routes that can be popped',
);
......
......@@ -883,6 +883,28 @@ void main() {
);
expect(SystemChrome.latestStyle, SystemUiOverlayStyle.dark);
});
testWidgets('CupertinoNavigationBarBackButton shows an error when manually added outside a route', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoNavigationBarBackButton()
);
final dynamic exception = tester.takeException();
expect(exception, isAssertionError);
expect(exception.toString(), contains('CupertinoNavigationBarBackButton should only be used in routes that can be popped'));
});
testWidgets('CupertinoNavigationBarBackButton shows an error when placed in a route that cannot be popped', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: CupertinoNavigationBarBackButton(),
),
);
final dynamic exception = tester.takeException();
expect(exception, isAssertionError);
expect(exception.toString(), contains('CupertinoNavigationBarBackButton should only be used in routes that can be popped'));
});
}
class _ExpectStyles extends StatelessWidget {
......
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