default_route.dart
4.03 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import 'package:flutter/cupertino.dart';
import '../../../get.dart';
import '../router_report.dart';
@optionalTypeArgs
mixin RouteReportMixin<T extends StatefulWidget> on State<T> {
@override
void initState() {
super.initState();
RouterReportManager.instance.reportCurrentRoute(this);
}
@override
void dispose() {
super.dispose();
RouterReportManager.instance.reportRouteDispose(this);
}
}
mixin PageRouteReportMixin<T> on Route<T> {
@override
void install() {
super.install();
RouterReportManager.instance.reportCurrentRoute(this);
}
@override
void dispose() {
super.dispose();
RouterReportManager.instance.reportRouteDispose(this);
}
}
class GetPageRoute<T> extends PageRoute<T>
with GetPageRouteTransitionMixin<T>, PageRouteReportMixin {
/// Creates a page route for use in an iOS designed app.
///
/// The [builder], [maintainState], and [fullscreenDialog] arguments must not
/// be null.
GetPageRoute({
RouteSettings? settings,
this.transitionDuration = const Duration(milliseconds: 300),
this.reverseTransitionDuration = const Duration(milliseconds: 300),
this.opaque = true,
this.parameter,
this.gestureWidth,
this.curve,
this.alignment,
this.transition,
this.popGesture,
this.customTransition,
this.barrierDismissible = false,
this.barrierColor,
BindingsInterface? binding,
List<BindingsInterface> bindings = const [],
this.binds,
this.routeName,
this.page,
this.title,
this.showCupertinoParallax = true,
this.barrierLabel,
this.maintainState = true,
bool fullscreenDialog = false,
this.middlewares,
}) : bindings = (binding == null) ? bindings : [...bindings, binding],
super(
settings: settings,
fullscreenDialog: fullscreenDialog,
);
@override
final Duration transitionDuration;
@override
final Duration reverseTransitionDuration;
final GetPageBuilder? page;
final String? routeName;
//final String reference;
final CustomTransition? customTransition;
final List<BindingsInterface> bindings;
final Map<String, String>? parameter;
final List<Bind>? binds;
@override
final bool showCupertinoParallax;
@override
final bool opaque;
final bool? popGesture;
@override
final bool barrierDismissible;
final Transition? transition;
final Curve? curve;
final Alignment? alignment;
final List<GetMiddleware>? middlewares;
@override
final Color? barrierColor;
@override
final String? barrierLabel;
@override
final bool maintainState;
@override
void dispose() {
super.dispose();
final middlewareRunner = MiddlewareRunner(middlewares);
middlewareRunner.runOnPageDispose();
_child = null;
}
Widget? _child;
Widget _getChild() {
if (_child != null) return _child!;
final middlewareRunner = MiddlewareRunner(middlewares);
final localBinds = [if (binds != null) ...binds!];
final bindingsToBind = middlewareRunner
.runOnBindingsStart(bindings.isNotEmpty ? bindings : localBinds);
final pageToBuild = middlewareRunner.runOnPageBuildStart(page)!;
if (bindingsToBind != null && bindingsToBind.isNotEmpty) {
if (bindingsToBind is List<BindingsInterface>) {
for (final item in bindingsToBind) {
final dep = item.dependencies();
if (dep is List<Bind>) {
_child = Binds(
binds: dep,
child: middlewareRunner.runOnPageBuilt(pageToBuild()),
);
}
}
} else if (bindingsToBind is List<Bind>) {
_child = Binds(
binds: bindingsToBind,
child: middlewareRunner.runOnPageBuilt(pageToBuild()),
);
}
}
return _child ??= middlewareRunner.runOnPageBuilt(pageToBuild());
}
@override
Widget buildContent(BuildContext context) {
return _getChild();
}
@override
final String? title;
@override
String get debugLabel => '${super.debugLabel}(${settings.name})';
@override
final double Function(BuildContext context)? gestureWidth;
}