Merge branch 'master' of https://github.com/jonataslaw/getx
Showing
1 changed file
with
15 additions
and
5 deletions
| @@ -205,21 +205,31 @@ Get.delete<Controller>(); //usually you don't need to do this because GetX alrea | @@ -205,21 +205,31 @@ Get.delete<Controller>(); //usually you don't need to do this because GetX alrea | ||
| 205 | 205 | ||
| 206 | ## Specifying an alternate instance | 206 | ## Specifying an alternate instance | 
| 207 | 207 | ||
| 208 | -A currently inserted instance can be replaced with a similar or extended class instance by using the `replace` method. This can then be retrieved by using the original class. | 208 | +A currently inserted instance can be replaced with a similar or extended class instance by using the `replace` or `lazyReplace` method. This can then be retrieved by using the original class. | 
| 209 | 209 | ||
| 210 | ```dart | 210 | ```dart | 
| 211 | -class ParentClass {} | 211 | +abstract class BaseClass {} | 
| 212 | +class ParentClass extends BaseClass {} | ||
| 212 | 213 | ||
| 213 | class ChildClass extends ParentClass { | 214 | class ChildClass extends ParentClass { | 
| 214 | bool isChild = true; | 215 | bool isChild = true; | 
| 215 | } | 216 | } | 
| 216 | 217 | ||
| 217 | -Get.put(ParentClass()); | ||
| 218 | 218 | ||
| 219 | -Get.replace<ParentClass, ChildClass>(ChildClass()); | 219 | +Get.put<BaseClass>(ParentClass()); | 
| 220 | 220 | ||
| 221 | -final instance = Get.find<ParentClass>(); | 221 | +Get.replace<BaseClass>(ChildClass()); | 
| 222 | + | ||
| 223 | +final instance = Get.find<BaseClass>(); | ||
| 222 | print(instance is ChildClass); //true | 224 | print(instance is ChildClass); //true | 
| 225 | + | ||
| 226 | + | ||
| 227 | +class OtherClass extends BaseClass {} | ||
| 228 | +Get.lazyReplace<BaseClass>(() => OtherClass()); | ||
| 229 | + | ||
| 230 | +final instance = Get.find<BaseClass>(); | ||
| 231 | +print(instance is ChildClass); // false | ||
| 232 | +print(instance is OtherClass); //true | ||
| 223 | ``` | 233 | ``` | 
| 224 | 234 | ||
| 225 | ## Differences between methods | 235 | ## Differences between methods | 
- 
Please register or login to post a comment