-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpop.dart
105 lines (95 loc) · 2.91 KB
/
pop.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static Map<String, FlutterBoostRouteFactory> routerMap = {
'initialRoute': (settings, uniqueId) {
return PageRouteBuilder<dynamic>(
settings: settings,
pageBuilder: (_, __, ___) {
return Scaffold(
body: Text('initialRoute text'),
);
},
);
},
'mainPage': (settings, uniqueId) {
return PageRouteBuilder<dynamic>(
settings: settings,
pageBuilder: (_, __, ___) {
final Map<String, Object> map = settings.arguments;
final String dataString = map['data'];
return Scaffold(
body: Center(
child: Column(
children: [
Text('mainPage text'),
Text(dataString ?? ''),
],
)),
);
});
},
'secondPage': (settings, uniqueId) {
return PageRouteBuilder<dynamic>(
settings: settings,
pageBuilder: (_, __, ___) {
final Map<String, Object> map = settings.arguments;
final String dataString = map['data'];
return Scaffold(
body: Center(
child: Column(
children: [
Text('secondPage text'),
Text(dataString ?? ''),
],
)),
);
});
},
};
Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
FlutterBoostRouteFactory func = routerMap[settings.name];
if (func == null) {
return null;
}
return func(settings, uniqueId);
}
Widget appBuilder(Widget home) {
return MaterialApp(home: home, debugShowCheckedModeBanner: false);
}
@override
Widget build(BuildContext context) {
return FlutterBoostApp(
routeFactory,
appBuilder: appBuilder,
initialRoute: "initialRoute",
);
}
}
void main() {
/// push and pop with result test
testWidgets('push and pop with result test', (tester) async {
await tester.pumpWidget(
MyApp(),
);
BoostNavigator.instance.push('mainPage');
await tester.pumpAndSettle();
expect(find.text('mainPage text'), findsOneWidget);
BoostNavigator.instance.push('secondPage').then((value) {
///check pop result
Map popResult = value as Map;
expectSync(popResult['data'], 'resultString');
});
await tester.pumpAndSettle();
BoostNavigator.instance.pop({'data': 'resultString'});
await tester.pumpAndSettle();
expect(find.text('mainPage text'), findsOneWidget);
expect(find.text('secondPage text'), findsNothing);
});
}