Make CupertinoNavigationBarBackButton correctly return an assert error (#30815)
This commit is contained in:
parent
d628537172
commit
364d73c7d8
@ -1231,7 +1231,7 @@ class CupertinoNavigationBarBackButton extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final ModalRoute<dynamic> currentRoute = ModalRoute.of(context);
|
final ModalRoute<dynamic> currentRoute = ModalRoute.of(context);
|
||||||
assert(
|
assert(
|
||||||
currentRoute.canPop,
|
currentRoute?.canPop == true,
|
||||||
'CupertinoNavigationBarBackButton should only be used in routes that can be popped',
|
'CupertinoNavigationBarBackButton should only be used in routes that can be popped',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -883,6 +883,28 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(SystemChrome.latestStyle, SystemUiOverlayStyle.dark);
|
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 {
|
class _ExpectStyles extends StatelessWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user