-
-
Notifications
You must be signed in to change notification settings - Fork 504
/
Copy pathnavigation_service.dart
68 lines (59 loc) · 1.81 KB
/
navigation_service.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
import 'package:flutter/material.dart';
class NavigationService {
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
Future<dynamic> pushScreen(String routeName, {dynamic arguments}) {
return navigatorKey.currentState!
.pushNamed(routeName, arguments: arguments);
}
Future<dynamic> popAndPushScreen(String routeName, {dynamic arguments}) {
navigatorKey.currentState!.pop();
return pushScreen(routeName, arguments: arguments);
}
Future<dynamic> pushReplacementScreen(String routeName, {dynamic arguments}) {
return navigatorKey.currentState!
.pushReplacementNamed(routeName, arguments: arguments);
}
void fromInviteLink(List<String> routeNames, List<dynamic> arguments) {
int i = 0;
removeAllAndPush('/${routeNames[i]}', '/', arguments: arguments[i]);
for (i = 1; i < routeNames.length; i++) {
pushScreen('/${routeNames[i]}', arguments: arguments[i]);
}
}
Future<dynamic> removeAllAndPush(
String routeName,
String tillRoute, {
dynamic arguments,
}) {
return navigatorKey.currentState!.pushNamedAndRemoveUntil(
routeName,
ModalRoute.withName(tillRoute),
arguments: arguments,
);
}
void pushDialog(Widget dialog) {
showDialog(
context: navigatorKey.currentContext!,
barrierColor: Colors.transparent,
barrierDismissible: false,
builder: (BuildContext context) {
return dialog;
},
);
}
void showSnackBar(
String message, {
Duration duration = const Duration(seconds: 2),
}) {
ScaffoldMessenger.of(navigatorKey.currentContext!).showSnackBar(
SnackBar(
behavior: SnackBarBehavior.floating,
duration: duration,
content: Text(message),
),
);
}
void pop() {
return navigatorKey.currentState!.pop();
}
}