Jonny Borges
Committed by GitHub

Update routes.dart

@@ -5,45 +5,89 @@ class Get { @@ -5,45 +5,89 @@ class Get {
5 static Get _get; 5 static Get _get;
6 static GlobalKey<NavigatorState> key = new GlobalKey<NavigatorState>(); 6 static GlobalKey<NavigatorState> key = new GlobalKey<NavigatorState>();
7 7
  8 + ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement,
  9 + ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named"
  10 + ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed.
  11 + ///To return to the previous screen, use Get.back().
  12 + ///No need to pass any context to Get, just put the name of the route inside
  13 + ///the parentheses and the magic will occur.
8 factory Get() { 14 factory Get() {
9 if (_get == null) _get = Get._(); 15 if (_get == null) _get = Get._();
10 return _get; 16 return _get;
11 } 17 }
12 18
  19 + ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement,
  20 + ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named"
  21 + ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed.
  22 + ///To return to the previous screen, use Get.back().
  23 + ///No need to pass any context to Get, just put the name of the route inside
  24 + ///the parentheses and the magic will occur.
13 Get._(); 25 Get._();
14 26
  27 + /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push
  28 + /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
  29 + /// of rebuilding every app after a route, use rebuildRoutes = true as the parameter.
15 static to(Widget page, {bool rebuildRoutes = false}) { 30 static to(Widget page, {bool rebuildRoutes = false}) {
16 return key.currentState 31 return key.currentState
17 .push(GetRoute(opaque: rebuildRoutes, builder: (_) => page)); 32 .push(GetRoute(opaque: rebuildRoutes, builder: (_) => page));
18 } 33 }
19 34
  35 + /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed
  36 + /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
  37 + /// of rebuilding every app after a route, use rebuildRoutes = true as the parameter.
20 static toNamed(String page, {arguments}) { 38 static toNamed(String page, {arguments}) {
21 return key.currentState.pushNamed(page, arguments: arguments); 39 return key.currentState.pushNamed(page, arguments: arguments);
22 } 40 }
23 41
  42 + /// It replaces Navigator.pushReplacementNamed, but needs no context.
24 static offNamed(String page, {arguments}) { 43 static offNamed(String page, {arguments}) {
25 - return key.currentState  
26 - .pushReplacementNamed(page, arguments: arguments); 44 + return key.currentState.pushReplacementNamed(page, arguments: arguments);
  45 + }
  46 +
  47 + /// It replaces Navigator.popUntil, but needs no context.
  48 + static until(String page, predicate) {
  49 + return key.currentState.popUntil(predicate);
  50 + }
  51 +
  52 + /// It replaces Navigator.pushAndRemoveUntil, but needs no context.
  53 + static offUntil(page, predicate) {
  54 + return key.currentState.pushAndRemoveUntil(page, predicate);
  55 + }
  56 +
  57 + /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context.
  58 + static offNamedUntil(page, predicate) {
  59 + return key.currentState.pushNamedAndRemoveUntil(page, predicate);
  60 + }
  61 +
  62 + /// It replaces Navigator.removeRoute, but needs no context.
  63 + static removeRoute(route) {
  64 + return key.currentState.removeRoute(route);
27 } 65 }
28 66
  67 + /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context.
29 static offAllNamed( 68 static offAllNamed(
30 String newRouteName, 69 String newRouteName,
31 RoutePredicate predicate, { 70 RoutePredicate predicate, {
32 - Object arguments, 71 + arguments,
33 }) { 72 }) {
34 return key.currentState 73 return key.currentState
35 .pushNamedAndRemoveUntil(newRouteName, predicate, arguments: arguments); 74 .pushNamedAndRemoveUntil(newRouteName, predicate, arguments: arguments);
36 } 75 }
37 76
38 - static back() {  
39 - return key.currentState.pop(); 77 + /// It replaces Navigator.pop, but needs no context.
  78 + static back({result}) {
  79 + return key.currentState.pop(result);
40 } 80 }
41 81
  82 + /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement
  83 + /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
  84 + /// of rebuilding every app after a route, use rebuildRoutes = true as the parameter.
42 static off(Widget page, {bool rebuildRoutes = false}) { 85 static off(Widget page, {bool rebuildRoutes = false}) {
43 return key.currentState 86 return key.currentState
44 .pushReplacement(GetRoute(opaque: rebuildRoutes, builder: (_) => page)); 87 .pushReplacement(GetRoute(opaque: rebuildRoutes, builder: (_) => page));
45 } 88 }
46 89
  90 + /// It replaces Navigator.pushAndRemoveUntil, but needs no context
47 static offAll(Widget page, RoutePredicate predicate, 91 static offAll(Widget page, RoutePredicate predicate,
48 {bool rebuildRoutes = false}) { 92 {bool rebuildRoutes = false}) {
49 return key.currentState.pushAndRemoveUntil( 93 return key.currentState.pushAndRemoveUntil(