|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:flutter/cupertino.dart';
|
| 6 | +import 'package:flutter/services.dart'; |
6 | 7 | import 'package:flutter_test/flutter_test.dart';
|
7 | 8 |
|
8 | 9 | void main() {
|
@@ -289,4 +290,37 @@ void main() {
|
289 | 290 | expect(find.text('home'), findsOneWidget);
|
290 | 291 | expect(find.text('second route'), findsNothing);
|
291 | 292 | });
|
| 293 | + |
| 294 | + testWidgets('Handles Android back button', (WidgetTester tester) async { |
| 295 | + final GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>(); |
| 296 | + await tester.pumpWidget( |
| 297 | + CupertinoApp( |
| 298 | + home: CupertinoTabScaffold( |
| 299 | + tabBar: CupertinoTabBar( |
| 300 | + items: const <BottomNavigationBarItem>[ |
| 301 | + BottomNavigationBarItem(label: '', icon: Text('1')), |
| 302 | + BottomNavigationBarItem(label: '', icon: Text('2')) |
| 303 | + ], |
| 304 | + ), |
| 305 | + tabBuilder: (_, int i) => PopScope( |
| 306 | + canPop: false, |
| 307 | + child: CupertinoTabView( |
| 308 | + navigatorKey: key, |
| 309 | + builder: (BuildContext context) => const Text('first route'), |
| 310 | + ), |
| 311 | + ), |
| 312 | + ), |
| 313 | + ), |
| 314 | + ); |
| 315 | + |
| 316 | + expect(find.text('first route'), findsOneWidget); |
| 317 | + |
| 318 | + // Simulate android back button intent. |
| 319 | + final ByteData message = const JSONMethodCodec().encodeMethodCall(const MethodCall('popRoute')); |
| 320 | + await tester.binding.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) {}); |
| 321 | + await tester.pumpAndSettle(); |
| 322 | + |
| 323 | + // Navigator didn't pop, so first route is still visible |
| 324 | + expect(find.text('first route'), findsOneWidget); |
| 325 | + }); |
292 | 326 | }
|
0 commit comments