Showing
8 changed files
with
52 additions
and
36 deletions
@@ -695,7 +695,7 @@ Instead of instantiating your class within the class you are using, you are inst | @@ -695,7 +695,7 @@ Instead of instantiating your class within the class you are using, you are inst | ||
695 | So you can use your controller (or class Bloc) normally | 695 | So you can use your controller (or class Bloc) normally |
696 | 696 | ||
697 | ```dart | 697 | ```dart |
698 | -controller.fetchApi();// Rather Controller controller = Controller(); | 698 | +controller.fetchApi(); |
699 | ``` | 699 | ``` |
700 | 700 | ||
701 | Imagine that you have navigated through numerous routes, and you need a data that was left behind in your controller, you would need a state manager combined with the Provider or Get_it, correct? Not with Get. You just need to ask Get to "find" for your controller, you don't need any additional dependencies: | 701 | Imagine that you have navigated through numerous routes, and you need a data that was left behind in your controller, you would need a state manager combined with the Provider or Get_it, correct? Not with Get. You just need to ask Get to "find" for your controller, you don't need any additional dependencies: |
@@ -716,6 +716,23 @@ Get.lazyPut<Service>(()=> ApiMock()); | @@ -716,6 +716,23 @@ Get.lazyPut<Service>(()=> ApiMock()); | ||
716 | /// ApiMock will only be called when someone uses Get.find<Service> for the first time | 716 | /// ApiMock will only be called when someone uses Get.find<Service> for the first time |
717 | ``` | 717 | ``` |
718 | 718 | ||
719 | +If you want to register an asynchronous instance, you can use Get.putAsync. | ||
720 | +```dart | ||
721 | +Get.putAsync<SharedPreferences>(() async { | ||
722 | + final prefs = await SharedPreferences.getInstance(); | ||
723 | + await prefs.setInt('counter', 12345); | ||
724 | + return prefs; | ||
725 | +}); | ||
726 | +``` | ||
727 | +usage: | ||
728 | + | ||
729 | +```dart | ||
730 | + int count = Get.find<SharedPreferences>().getInt('counter'); | ||
731 | + print(count); | ||
732 | + // out: 12345 | ||
733 | +} | ||
734 | +``` | ||
735 | + | ||
719 | To remove a instance of Get: | 736 | To remove a instance of Get: |
720 | ```dart | 737 | ```dart |
721 | Get.delete<Controller>(); | 738 | Get.delete<Controller>(); |
@@ -73,14 +73,14 @@ class Get { | @@ -73,14 +73,14 @@ class Get { | ||
73 | /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed | 73 | /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed |
74 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 74 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
75 | /// of rebuilding every app after a route, use opaque = true as the parameter. | 75 | /// of rebuilding every app after a route, use opaque = true as the parameter. |
76 | - static Future<T> toNamed<T>(String page, {arguments, int id}) { | 76 | + static Future<T> toNamed<T>(String page, {Object arguments, int id}) { |
77 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 77 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
78 | // when widget don't mounted | 78 | // when widget don't mounted |
79 | return _get.global(id).currentState.pushNamed(page, arguments: arguments); | 79 | return _get.global(id).currentState.pushNamed(page, arguments: arguments); |
80 | } | 80 | } |
81 | 81 | ||
82 | /// It replaces Navigator.pushReplacementNamed, but needs no context. | 82 | /// It replaces Navigator.pushReplacementNamed, but needs no context. |
83 | - static Future<T> offNamed<T>(String page, {arguments, int id}) { | 83 | + static Future<T> offNamed<T>(String page, {Object arguments, int id}) { |
84 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 84 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
85 | // when widget don't mounted | 85 | // when widget don't mounted |
86 | return _get | 86 | return _get |
@@ -90,29 +90,32 @@ class Get { | @@ -90,29 +90,32 @@ class Get { | ||
90 | } | 90 | } |
91 | 91 | ||
92 | /// It replaces Navigator.popUntil, but needs no context. | 92 | /// It replaces Navigator.popUntil, but needs no context. |
93 | - static void until(predicate, {int id}) { | 93 | + static void until(RoutePredicate predicate, {int id}) { |
94 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 94 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
95 | // when widget don't mounted | 95 | // when widget don't mounted |
96 | return _get.global(id).currentState.popUntil(predicate); | 96 | return _get.global(id).currentState.popUntil(predicate); |
97 | } | 97 | } |
98 | 98 | ||
99 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | 99 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context. |
100 | - static Future<T> offUntil<T>(page, predicate, {int id}) { | 100 | + static Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, |
101 | + {int id}) { | ||
101 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 102 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
102 | // when widget don't mounted | 103 | // when widget don't mounted |
103 | return _get.global(id).currentState.pushAndRemoveUntil(page, predicate); | 104 | return _get.global(id).currentState.pushAndRemoveUntil(page, predicate); |
104 | } | 105 | } |
105 | 106 | ||
106 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 107 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. |
107 | - static Future<T> offNamedUntil<T>(page, predicate, {int id}) { | 108 | + static Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, |
109 | + {int id, Object arguments}) { | ||
108 | return _get | 110 | return _get |
109 | .global(id) | 111 | .global(id) |
110 | .currentState | 112 | .currentState |
111 | - .pushNamedAndRemoveUntil(page, predicate); | 113 | + .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); |
112 | } | 114 | } |
113 | 115 | ||
114 | /// It replaces Navigator.popAndPushNamed, but needs no context. | 116 | /// It replaces Navigator.popAndPushNamed, but needs no context. |
115 | - static Future<T> offAndToNamed<T>(String page, {arguments, int id, result}) { | 117 | + static Future<T> offAndToNamed<T>(String page, |
118 | + {Object arguments, int id, dynamic result}) { | ||
116 | return _get | 119 | return _get |
117 | .global(id) | 120 | .global(id) |
118 | .currentState | 121 | .currentState |
@@ -120,13 +123,13 @@ class Get { | @@ -120,13 +123,13 @@ class Get { | ||
120 | } | 123 | } |
121 | 124 | ||
122 | /// It replaces Navigator.removeRoute, but needs no context. | 125 | /// It replaces Navigator.removeRoute, but needs no context. |
123 | - static void removeRoute(route, {int id}) { | 126 | + static void removeRoute(Route<dynamic> route, {int id}) { |
124 | return _get.global(id).currentState.removeRoute(route); | 127 | return _get.global(id).currentState.removeRoute(route); |
125 | } | 128 | } |
126 | 129 | ||
127 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 130 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. |
128 | static Future<T> offAllNamed<T>(String newRouteName, | 131 | static Future<T> offAllNamed<T>(String newRouteName, |
129 | - {RoutePredicate predicate, arguments, int id}) { | 132 | + {RoutePredicate predicate, Object arguments, int id}) { |
130 | var route = (Route<dynamic> rota) => false; | 133 | var route = (Route<dynamic> rota) => false; |
131 | 134 | ||
132 | return _get.global(id).currentState.pushNamedAndRemoveUntil( | 135 | return _get.global(id).currentState.pushNamedAndRemoveUntil( |
@@ -651,6 +654,7 @@ class Get { | @@ -651,6 +654,7 @@ class Get { | ||
651 | 654 | ||
652 | static Future<S> putAsync<S>(_FcBuilderFuncAsync<S> builder, | 655 | static Future<S> putAsync<S>(_FcBuilderFuncAsync<S> builder, |
653 | {String tag}) async { | 656 | {String tag}) async { |
657 | + WidgetsFlutterBinding.ensureInitialized(); | ||
654 | return Get.put<S>(await builder(), tag: tag); | 658 | return Get.put<S>(await builder(), tag: tag); |
655 | } | 659 | } |
656 | 660 | ||
@@ -707,7 +711,8 @@ class Get { | @@ -707,7 +711,8 @@ class Get { | ||
707 | void removeDependencyByRoute(String routeName) async { | 711 | void removeDependencyByRoute(String routeName) async { |
708 | List<String> keysToRemove = []; | 712 | List<String> keysToRemove = []; |
709 | Get().routesKey.forEach((key, value) { | 713 | Get().routesKey.forEach((key, value) { |
710 | - if (value == routeName && value != null) { | 714 | + // if (value == routeName && value != null) { |
715 | + if (value == routeName) { | ||
711 | keysToRemove.add(key); | 716 | keysToRemove.add(key); |
712 | } | 717 | } |
713 | }); | 718 | }); |
@@ -793,7 +798,6 @@ class Get { | @@ -793,7 +798,6 @@ class Get { | ||
793 | if (callInit) { | 798 | if (callInit) { |
794 | Get().initController<S>(tag: tag); | 799 | Get().initController<S>(tag: tag); |
795 | } | 800 | } |
796 | - | ||
797 | return _value; | 801 | return _value; |
798 | } | 802 | } |
799 | } | 803 | } |
@@ -998,8 +1002,6 @@ class _FcBuilder<S> { | @@ -998,8 +1002,6 @@ class _FcBuilder<S> { | ||
998 | } | 1002 | } |
999 | } | 1003 | } |
1000 | 1004 | ||
1001 | - | ||
1002 | - | ||
1003 | typedef _FcBuilderFunc<S> = S Function(); | 1005 | typedef _FcBuilderFunc<S> = S Function(); |
1004 | 1006 | ||
1005 | typedef _FcBuilderFuncAsync<S> = Future<S> Function(); | 1007 | typedef _FcBuilderFuncAsync<S> = Future<S> Function(); |
@@ -32,6 +32,7 @@ class GetRouteBase<T> extends PageRoute<T> { | @@ -32,6 +32,7 @@ class GetRouteBase<T> extends PageRoute<T> { | ||
32 | this.parameter, | 32 | this.parameter, |
33 | this.binding, | 33 | this.binding, |
34 | this.bindings, | 34 | this.bindings, |
35 | + this.customBuildPageTransitions, | ||
35 | this.opaque = true, | 36 | this.opaque = true, |
36 | this.transitionDuration = const Duration(milliseconds: 400), | 37 | this.transitionDuration = const Duration(milliseconds: 400), |
37 | this.popGesture, | 38 | this.popGesture, |
@@ -55,6 +56,8 @@ class GetRouteBase<T> extends PageRoute<T> { | @@ -55,6 +56,8 @@ class GetRouteBase<T> extends PageRoute<T> { | ||
55 | /// Builds the primary contents of the route. | 56 | /// Builds the primary contents of the route. |
56 | final Widget page; | 57 | final Widget page; |
57 | 58 | ||
59 | + final Widget customBuildPageTransitions; | ||
60 | + | ||
58 | final bool popGesture; | 61 | final bool popGesture; |
59 | 62 | ||
60 | final Bindings binding; | 63 | final Bindings binding; |
@@ -239,7 +242,7 @@ class GetRouteBase<T> extends PageRoute<T> { | @@ -239,7 +242,7 @@ class GetRouteBase<T> extends PageRoute<T> { | ||
239 | /// | 242 | /// |
240 | /// * [CupertinoPageTransitionsBuilder], which uses this method to define a | 243 | /// * [CupertinoPageTransitionsBuilder], which uses this method to define a |
241 | /// [PageTransitionsBuilder] for the [PageTransitionsTheme]. | 244 | /// [PageTransitionsBuilder] for the [PageTransitionsTheme]. |
242 | - static Widget buildPageTransitions<T>( | 245 | + Widget buildPageTransitions<T>( |
243 | PageRoute<T> route, | 246 | PageRoute<T> route, |
244 | BuildContext context, | 247 | BuildContext context, |
245 | bool popGesture, | 248 | bool popGesture, |
@@ -479,6 +482,9 @@ class GetRouteBase<T> extends PageRoute<T> { | @@ -479,6 +482,9 @@ class GetRouteBase<T> extends PageRoute<T> { | ||
479 | @override | 482 | @override |
480 | Widget buildTransitions(BuildContext context, Animation<double> animation, | 483 | Widget buildTransitions(BuildContext context, Animation<double> animation, |
481 | Animation<double> secondaryAnimation, Widget child) { | 484 | Animation<double> secondaryAnimation, Widget child) { |
485 | + if (customBuildPageTransitions != null) { | ||
486 | + return customBuildPageTransitions; | ||
487 | + } else { | ||
482 | return buildPageTransitions<T>( | 488 | return buildPageTransitions<T>( |
483 | this, | 489 | this, |
484 | context, | 490 | context, |
@@ -490,6 +496,7 @@ class GetRouteBase<T> extends PageRoute<T> { | @@ -490,6 +496,7 @@ class GetRouteBase<T> extends PageRoute<T> { | ||
490 | curve, | 496 | curve, |
491 | alignment); | 497 | alignment); |
492 | } | 498 | } |
499 | + } | ||
493 | 500 | ||
494 | @override | 501 | @override |
495 | String get debugLabel => '${super.debugLabel}(${settings.name})'; | 502 | String get debugLabel => '${super.debugLabel}(${settings.name})'; |
@@ -5,50 +5,35 @@ class Change<T> { | @@ -5,50 +5,35 @@ class Change<T> { | ||
5 | /// Value after change | 5 | /// Value after change |
6 | final $new; | 6 | final $new; |
7 | 7 | ||
8 | - | ||
9 | - | ||
10 | final ListChangeOp op; | 8 | final ListChangeOp op; |
11 | 9 | ||
12 | final int pos; | 10 | final int pos; |
13 | 11 | ||
14 | final DateTime time; | 12 | final DateTime time; |
15 | final int batch; | 13 | final int batch; |
16 | - Change( | ||
17 | - {this.$new, | ||
18 | - this.$old, | ||
19 | - this.batch, | ||
20 | - | ||
21 | - this.op, | ||
22 | - this.pos, | ||
23 | - DateTime time}) | 14 | + Change({this.$new, this.$old, this.batch, this.op, this.pos, DateTime time}) |
24 | : time = time ?? DateTime.now(); | 15 | : time = time ?? DateTime.now(); |
25 | String toString() => 'Change(new: ${$new}, old: ${$old})'; | 16 | String toString() => 'Change(new: ${$new}, old: ${$old})'; |
26 | 17 | ||
27 | - Change.insert( | ||
28 | - {this.$new, this.$old, this.batch, this.pos, DateTime time}) | 18 | + Change.insert({this.$new, this.$old, this.batch, this.pos, DateTime time}) |
29 | : op = ListChangeOp.add, | 19 | : op = ListChangeOp.add, |
30 | time = time ?? new DateTime.now(); | 20 | time = time ?? new DateTime.now(); |
31 | 21 | ||
32 | - Change.set( | ||
33 | - {this.$new, this.$old, this.batch, this.pos, DateTime time}) | 22 | + Change.set({this.$new, this.$old, this.batch, this.pos, DateTime time}) |
34 | : op = ListChangeOp.set, | 23 | : op = ListChangeOp.set, |
35 | time = time ?? new DateTime.now(); | 24 | time = time ?? new DateTime.now(); |
36 | 25 | ||
37 | - Change.remove( | ||
38 | - {this.$new, this.$old, this.batch, this.pos, DateTime time}) | 26 | + Change.remove({this.$new, this.$old, this.batch, this.pos, DateTime time}) |
39 | : op = ListChangeOp.remove, | 27 | : op = ListChangeOp.remove, |
40 | time = time ?? new DateTime.now(); | 28 | time = time ?? new DateTime.now(); |
41 | 29 | ||
42 | Change.clear({this.$new, this.$old, this.batch, DateTime time}) | 30 | Change.clear({this.$new, this.$old, this.batch, DateTime time}) |
43 | : op = ListChangeOp.clear, | 31 | : op = ListChangeOp.clear, |
44 | pos = null, | 32 | pos = null, |
45 | - | ||
46 | time = time ?? new DateTime.now(); | 33 | time = time ?? new DateTime.now(); |
47 | } | 34 | } |
48 | 35 | ||
49 | typedef bool Condition(); | 36 | typedef bool Condition(); |
50 | 37 | ||
51 | -typedef E ChildrenListComposer<S, E>(S value); | ||
52 | - | ||
53 | /// Change operation | 38 | /// Change operation |
54 | enum ListChangeOp { add, remove, clear, set } | 39 | enum ListChangeOp { add, remove, clear, set } |
@@ -134,6 +134,8 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | @@ -134,6 +134,8 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
134 | } | 134 | } |
135 | } | 135 | } |
136 | 136 | ||
137 | +typedef ShouldRebuild<T> = bool Function(T previous, T next); | ||
138 | + | ||
137 | class RealState { | 139 | class RealState { |
138 | final StateSetter updater; | 140 | final StateSetter updater; |
139 | final String id; | 141 | final String id; |
1 | name: get | 1 | name: get |
2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. | 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. |
3 | -version: 2.11.2 | 3 | +version: 2.11.3 |
4 | homepage: https://github.com/jonataslaw/get | 4 | homepage: https://github.com/jonataslaw/get |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment