@@ -192,12 +192,13 @@ class App with ConnectivityListener {
192192 static ui.SingletonFlutterWindow ? _window;
193193
194194 /// Return the navigator key used by the App's View.
195- static GlobalKey <NavigatorState >? get navigatorKey => _appState? .navigatorKey;
196- static set navigatorKey (GlobalKey <NavigatorState >? v) {
197- if (v != null ) {
198- _appState? .navigatorKey = v;
199- }
200- }
195+ static final navigatorKey = GlobalKey <NavigatorState >();
196+
197+ /// Use this to navigate throughout the your app
198+ static NavigatorState get navigator => router;
199+
200+ /// Merely another name for it.
201+ static NavigatorState get router => navigatorKey.currentState! ;
201202
202203 /// Return the navigator key used by the App's View.
203204 static GlobalKey <ScaffoldMessengerState >? get scaffoldMessengerKey =>
@@ -977,6 +978,202 @@ class App with ConnectivityListener {
977978 }
978979 return connectionStatus;
979980 }
981+
982+ /// Whether the navigator can be popped.
983+ static bool canPop () => _appState! .canPop ();
984+
985+ /// Complete the lifecycle for a route that has been popped off the navigator.
986+ static void finalizeRoute (Route <dynamic > route) =>
987+ _appState! .finalizeRoute (route);
988+
989+ /// Consults the current route's [Route.willPop] method, and acts accordingly,
990+ /// potentially popping the route as a result; returns whether the pop request
991+ /// should be considered handled.
992+ @optionalTypeArgs
993+ static Future <bool > maybePop <T extends Object ?>([T ? result]) =>
994+ _appState! .maybePop <T >(result);
995+
996+ /// Pop the top-most route off the navigator.
997+ @optionalTypeArgs
998+ static void pop <T extends Object ?>([T ? result]) => _appState! .pop <T >(result);
999+
1000+ /// Pop the current route off the navigator and push a named route in its
1001+ /// place.
1002+ @optionalTypeArgs
1003+ static Future <T ?> popAndPushNamed <T extends Object ?, TO extends Object ?>(
1004+ String routeName,
1005+ {TO ? result,
1006+ Object ? arguments}) =>
1007+ _appState! .popAndPushNamed <T , TO >(routeName,
1008+ result: result, arguments: arguments);
1009+
1010+ /// Calls [pop] repeatedly until the predicate returns true.
1011+ static void popUntil (RoutePredicate predicate) =>
1012+ _appState! .popUntil (predicate);
1013+
1014+ /// Push the given route onto the navigator.
1015+ @optionalTypeArgs
1016+ static Future <T ?> push <T extends Object ?>(Route <T > route) =>
1017+ _appState! .push <T >(route);
1018+
1019+ /// Push the given route onto the navigator, and then remove all the previous
1020+ /// routes until the `predicate` returns true.
1021+ @optionalTypeArgs
1022+ static Future <T ?> pushAndRemoveUntil <T extends Object ?>(
1023+ Route <T > newRoute, RoutePredicate predicate) =>
1024+ _appState! .pushAndRemoveUntil <T >(newRoute, predicate);
1025+
1026+ /// Push a named route onto the navigator.
1027+ @optionalTypeArgs
1028+ static Future <T ?> pushNamed <T extends Object ?>(
1029+ String routeName, {
1030+ Object ? arguments,
1031+ }) =>
1032+ _appState! .pushNamed (routeName, arguments: arguments);
1033+
1034+ /// Push the route with the given name onto the navigator, and then remove all
1035+ /// the previous routes until the `predicate` returns true.
1036+ @optionalTypeArgs
1037+ static Future <T ?> pushNamedAndRemoveUntil <T extends Object ?>(
1038+ String newRouteName, RoutePredicate predicate, {Object ? arguments}) =>
1039+ _appState! .pushNamedAndRemoveUntil <T >(newRouteName, predicate,
1040+ arguments: arguments);
1041+
1042+ /// Replace the current route of the navigator by pushing the given route and
1043+ /// then disposing the previous route once the new route has finished
1044+ /// animating in.
1045+ @optionalTypeArgs
1046+ static Future <T ?> pushReplacement <T extends Object ?, TO extends Object ?>(
1047+ Route <T > newRoute,
1048+ {TO ? result}) =>
1049+ _appState! .pushReplacement <T , TO >(newRoute, result: result);
1050+
1051+ /// Replace the current route of the navigator by pushing the route named
1052+ /// [routeName] and then disposing the previous route once the new route has
1053+ /// finished animating in.
1054+ @optionalTypeArgs
1055+ static Future <T ?> pushReplacementNamed <T extends Object ?, TO extends Object ?>(
1056+ String routeName,
1057+ {TO ? result,
1058+ Object ? arguments}) =>
1059+ _appState! .pushReplacementNamed <T , TO >(routeName,
1060+ result: result, arguments: arguments);
1061+
1062+ /// Immediately remove `route` from the navigator, and [Route.dispose] it.
1063+ static void removeRoute (Route <dynamic > route) =>
1064+ _appState! .removeRoute (route);
1065+
1066+ /// Immediately remove a route from the navigator, and [Route.dispose] it. The
1067+ /// route to be removed is the one below the given `anchorRoute` .
1068+ static void removeRouteBelow (Route <dynamic > anchorRoute) =>
1069+ _appState! .removeRouteBelow (anchorRoute);
1070+
1071+ /// Replaces a route on the navigator that most tightly encloses the given
1072+ /// context with a new route.
1073+ @optionalTypeArgs
1074+ static void replace <T extends Object ?>(
1075+ {required Route <dynamic > oldRoute, required Route <T > newRoute}) =>
1076+ _appState! .replace <T >(oldRoute: oldRoute, newRoute: newRoute);
1077+
1078+ /// Replaces a route on the navigator with a new route. The route to be
1079+ /// replaced is the one below the given `anchorRoute` .
1080+ @optionalTypeArgs
1081+ static void replaceRouteBelow <T extends Object ?>(
1082+ {required Route <dynamic > anchorRoute, required Route <T > newRoute}) =>
1083+ App .router
1084+ .replaceRouteBelow <T >(anchorRoute: anchorRoute, newRoute: newRoute);
1085+
1086+ /// Pop the current route off the navigator and push a named route in its
1087+ /// place.
1088+ @optionalTypeArgs
1089+ static String
1090+ restorablePopAndPushNamed <T extends Object ?, TO extends Object ?>(
1091+ String routeName,
1092+ {TO ? result,
1093+ Object ? arguments}) =>
1094+ _appState! .restorablePopAndPushNamed <T , TO >(routeName,
1095+ result: result, arguments: arguments);
1096+
1097+ /// Push a new route onto the navigator.
1098+ @optionalTypeArgs
1099+ static String restorablePush <T extends Object ?>(
1100+ RestorableRouteBuilder <T > routeBuilder,
1101+ {Object ? arguments}) =>
1102+ _appState! .restorablePush <T >(routeBuilder, arguments: arguments);
1103+
1104+ /// Push a new route onto the navigator, and then remove all the previous
1105+ /// routes until the `predicate` returns true.
1106+ @optionalTypeArgs
1107+ static String restorablePushAndRemoveUntil <T extends Object ?>(
1108+ RestorableRouteBuilder <T > newRouteBuilder, RoutePredicate predicate,
1109+ {Object ? arguments}) =>
1110+ _appState! .restorablePushAndRemoveUntil <T >(newRouteBuilder, predicate,
1111+ arguments: arguments);
1112+
1113+ /// Push a named route onto the navigator.
1114+ @optionalTypeArgs
1115+ static String restorablePushNamed <T extends Object ?>(
1116+ String routeName, {
1117+ Object ? arguments,
1118+ }) =>
1119+ _appState! .restorablePushNamed (routeName, arguments: arguments);
1120+
1121+ /// Push the route with the given name onto the navigator that most tightly
1122+ /// encloses the given context, and then remove all the previous routes until
1123+ /// the `predicate` returns true.
1124+ @optionalTypeArgs
1125+ static String restorablePushNamedAndRemoveUntil <T extends Object ?>(
1126+ String newRouteName, RoutePredicate predicate, {Object ? arguments}) =>
1127+ _appState! .restorablePushNamedAndRemoveUntil <T >(newRouteName, predicate,
1128+ arguments: arguments);
1129+
1130+ /// Replace the current route of the navigator by pushing a new route and
1131+ /// then disposing the previous route once the new route has finished
1132+ /// animating in.
1133+ @optionalTypeArgs
1134+ static String
1135+ restorablePushReplacement <T extends Object ?, TO extends Object ?>(
1136+ RestorableRouteBuilder <T > routeBuilder,
1137+ {TO ? result,
1138+ Object ? arguments}) =>
1139+ _appState! .restorablePushReplacement <T , TO >(routeBuilder,
1140+ result: result, arguments: arguments);
1141+
1142+ /// Replace the current route of the navigator that most tightly encloses the
1143+ /// given context by pushing the route named [routeName] and then disposing
1144+ /// the previous route once the new route has finished animating in.
1145+ @optionalTypeArgs
1146+ static String
1147+ restorablePushReplacementNamed <T extends Object ?, TO extends Object ?>(
1148+ String routeName,
1149+ {TO ? result,
1150+ Object ? arguments}) =>
1151+ _appState! .restorablePushReplacementNamed <T , TO >(routeName,
1152+ result: result, arguments: arguments);
1153+
1154+ /// Replaces a route on the navigator that most tightly encloses the given
1155+ /// context with a new route.
1156+ @optionalTypeArgs
1157+ static String restorableReplace <T extends Object ?>(
1158+ {required Route <dynamic > oldRoute,
1159+ required RestorableRouteBuilder <T > newRouteBuilder,
1160+ Object ? arguments}) =>
1161+ _appState! .restorableReplace <T >(
1162+ oldRoute: oldRoute,
1163+ newRouteBuilder: newRouteBuilder,
1164+ arguments: arguments);
1165+
1166+ /// Replaces a route on the navigator with a new route. The route to be
1167+ /// replaced is the one below the given `anchorRoute` .
1168+ @optionalTypeArgs
1169+ static String restorableReplaceRouteBelow <T extends Object ?>(
1170+ {required Route <dynamic > anchorRoute,
1171+ required RestorableRouteBuilder <T > newRouteBuilder,
1172+ Object ? arguments}) =>
1173+ _appState! .restorableReplaceRouteBelow <T >(
1174+ anchorRoute: anchorRoute,
1175+ newRouteBuilder: newRouteBuilder,
1176+ arguments: arguments);
9801177}
9811178
9821179/// A Listener for the device's own connectivity status at any point in time.
@@ -985,24 +1182,6 @@ mixin ConnectivityListener {
9851182 void onConnectivityChanged (ConnectivityResult result);
9861183}
9871184
988- // /// Supply an MVC State object that hooks into the App class.
989- // abstract class StateC<T extends StatefulWidget> extends s.StateC<T>
990- // with HandleError {
991- // /// Optionally supply a State Controller to be linked to this 'State' object.
992- // StateC([StateController? controller]) : super(controller);
993- //
994- // @override
995- // void refresh() {
996- // // Critical to have the App 'refresh' first.
997- // // It uses a built-in InheritedWidget.
998- // App.refresh();
999- // if (mounted) {
1000- // // Next refresh the current State object itself.
1001- // super.refresh();
1002- // }
1003- // }
1004- // }
1005-
10061185/// A standard Drawer object for your Flutter app.
10071186class AppDrawer extends StatelessWidget {
10081187 /// Supply the properties to a Material Design [Drawer] Widget.
0 commit comments