cleanup
Reverted GetWidget to original implementation ( to use with `@override`), added docs, renamed "name" to "tag" in `Get.create()` to be consistent with the rest of the GetInstance() methods.
Showing
3 changed files
with
15 additions
and
9 deletions
1 | import 'package:get_core/get_core.dart'; | 1 | import 'package:get_core/get_core.dart'; |
2 | + | ||
2 | import 'get_instance.dart'; | 3 | import 'get_instance.dart'; |
3 | 4 | ||
4 | extension Inst on GetInterface { | 5 | extension Inst on GetInterface { |
@@ -47,6 +48,7 @@ extension Inst on GetInterface { | @@ -47,6 +48,7 @@ extension Inst on GetInterface { | ||
47 | /// So, if you call `Get.delete<T>()` the "instance factory" used in this | 48 | /// So, if you call `Get.delete<T>()` the "instance factory" used in this |
48 | /// method ([Get.create<T>()]) will be removed, but NOT the instances | 49 | /// method ([Get.create<T>()]) will be removed, but NOT the instances |
49 | /// already created by it. | 50 | /// already created by it. |
51 | + /// Uses `tag` as the other methods. | ||
50 | /// | 52 | /// |
51 | /// Example: | 53 | /// Example: |
52 | /// | 54 | /// |
@@ -55,8 +57,8 @@ extension Inst on GetInterface { | @@ -55,8 +57,8 @@ extension Inst on GetInterface { | ||
55 | /// Repl b = find(); | 57 | /// Repl b = find(); |
56 | /// print(a==b); (false)``` | 58 | /// print(a==b); (false)``` |
57 | void create<S>(InstanceBuilderCallback<S> builder, | 59 | void create<S>(InstanceBuilderCallback<S> builder, |
58 | - {String name, bool permanent = true}) => | ||
59 | - GetInstance().create<S>(builder, name: name, permanent: permanent); | 60 | + {String tag, bool permanent = true}) => |
61 | + GetInstance().create<S>(builder, tag: tag, permanent: permanent); | ||
60 | 62 | ||
61 | /// Finds a Instance of the required Class <[S]>(or [tag]) | 63 | /// Finds a Instance of the required Class <[S]>(or [tag]) |
62 | /// In the case of using [Get.create()], it will generate an Instance | 64 | /// In the case of using [Get.create()], it will generate an Instance |
@@ -116,11 +116,11 @@ class GetInstance { | @@ -116,11 +116,11 @@ class GetInstance { | ||
116 | /// print(a==b); (false)``` | 116 | /// print(a==b); (false)``` |
117 | void create<S>( | 117 | void create<S>( |
118 | InstanceBuilderCallback<S> builder, { | 118 | InstanceBuilderCallback<S> builder, { |
119 | - String name, | 119 | + String tag, |
120 | bool permanent = true, | 120 | bool permanent = true, |
121 | }) { | 121 | }) { |
122 | _insert( | 122 | _insert( |
123 | - isSingleton: false, name: name, builder: builder, permanent: permanent); | 123 | + isSingleton: false, name: tag, builder: builder, permanent: permanent); |
124 | } | 124 | } |
125 | 125 | ||
126 | /// Injects the Instance [S] builder into the [_singleton] HashMap. | 126 | /// Injects the Instance [S] builder into the [_singleton] HashMap. |
@@ -11,9 +11,13 @@ import 'package:get_instance/get_instance.dart'; | @@ -11,9 +11,13 @@ import 'package:get_instance/get_instance.dart'; | ||
11 | /// } | 11 | /// } |
12 | /// | 12 | /// |
13 | /// class AwesomeView extends GetView<AwesomeController> { | 13 | /// class AwesomeView extends GetView<AwesomeController> { |
14 | -/// /// if you need you can pass the tag for your controller | ||
15 | -/// /// in the super constructor. | ||
16 | -/// AwesomeView({Key key}):super(key:key, tag:"myControllerTag"); | 14 | +/// /// if you need you can pass the tag for |
15 | +/// /// Get.find<AwesomeController>(tag:"myTag"); | ||
16 | +/// @override | ||
17 | +/// final String tag = "myTag"; | ||
18 | +/// | ||
19 | +/// AwesomeView({Key key}):super(key:key); | ||
20 | +/// | ||
17 | /// @override | 21 | /// @override |
18 | /// Widget build(BuildContext context) { | 22 | /// Widget build(BuildContext context) { |
19 | /// return Container( | 23 | /// return Container( |
@@ -24,9 +28,9 @@ import 'package:get_instance/get_instance.dart'; | @@ -24,9 +28,9 @@ import 'package:get_instance/get_instance.dart'; | ||
24 | /// } | 28 | /// } |
25 | ///`` | 29 | ///`` |
26 | abstract class GetView<T> extends StatelessWidget { | 30 | abstract class GetView<T> extends StatelessWidget { |
27 | - const GetView({Key key, this.tag}) : super(key: key); | 31 | + const GetView({Key key}) : super(key: key); |
28 | 32 | ||
29 | - final String tag; | 33 | + final String tag = null; |
30 | 34 | ||
31 | T get controller => GetInstance().find<T>(tag: tag); | 35 | T get controller => GetInstance().find<T>(tag: tag); |
32 | 36 |
-
Please register or login to post a comment