Committed by
GitHub
Merge pull request #2497 from ricardodalarme/refactor/use-new-binding-everywhere
refactor(binding): use the new binding everywhere
Showing
5 changed files
with
25 additions
and
19 deletions
@@ -507,7 +507,7 @@ GetBuilder<Controller>( | @@ -507,7 +507,7 @@ GetBuilder<Controller>( | ||
507 | 507 | ||
508 | * You have already learned how to manage states with Get. | 508 | * You have already learned how to manage states with Get. |
509 | 509 | ||
510 | -* Note: You may want a larger organization, and not use the init property. For that, you can create a class and extends Bindings class, and within it mention the controllers that will be created within that route. Controllers will not be created at that time, on the contrary, this is just a statement, so that the first time you use a Controller, Get will know where to look. Get will remain lazyLoad, and will continue to dispose Controllers when they are no longer needed. See the pub.dev example to see how it works. | 510 | +* Note: You may want a larger organization, and not use the init property. For that, you can create a class and extends Binding class, and within it mention the controllers that will be created within that route. Controllers will not be created at that time, on the contrary, this is just a statement, so that the first time you use a Controller, Get will know where to look. Get will remain lazyLoad, and will continue to dispose Controllers when they are no longer needed. See the pub.dev example to see how it works. |
511 | 511 | ||
512 | If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init): | 512 | If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init): |
513 | 513 |
@@ -507,7 +507,7 @@ GetBuilder<Controller>( | @@ -507,7 +507,7 @@ GetBuilder<Controller>( | ||
507 | 507 | ||
508 | * You have already learned how to manage states with Get. | 508 | * You have already learned how to manage states with Get. |
509 | 509 | ||
510 | -* Note: You may want a larger organization, and not use the init property. For that, you can create a class and extends Bindings class, and within it mention the controllers that will be created within that route. Controllers will not be created at that time, on the contrary, this is just a statement, so that the first time you use a Controller, Get will know where to look. Get will remain lazyLoad, and will continue to dispose Controllers when they are no longer needed. See the pub.dev example to see how it works. | 510 | +* Note: You may want a larger organization, and not use the init property. For that, you can create a class and extends Binding class, and within it mention the controllers that will be created within that route. Controllers will not be created at that time, on the contrary, this is just a statement, so that the first time you use a Controller, Get will know where to look. Get will remain lazyLoad, and will continue to dispose Controllers when they are no longer needed. See the pub.dev example to see how it works. |
511 | 511 | ||
512 | If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init): | 512 | If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init): |
513 | 513 |
@@ -200,12 +200,14 @@ Bindings is the first step towards having a scalable application, you can visual | @@ -200,12 +200,14 @@ Bindings is the first step towards having a scalable application, you can visual | ||
200 | To create a Binding, simply create a class and implement Bindings | 200 | To create a Binding, simply create a class and implement Bindings |
201 | 201 | ||
202 | ```dart | 202 | ```dart |
203 | -class SampleBind extends Bindings { | 203 | +class SampleBind extends Binding { |
204 | @override | 204 | @override |
205 | - void dependencies() { | ||
206 | - Get.lazyPut<Controller>(() => Controller()); | ||
207 | - Get.lazyPut<Controller2>(() => Controller2()); | ||
208 | - Get.lazyPut<Controller3>(() => Controller3()); | 205 | + List<Bind> dependencies() { |
206 | + return [ | ||
207 | + Bind.lazyPut<Controller>(() => Controller()), | ||
208 | + Bind.lazyPut<Controller2>(() => Controller2()), | ||
209 | + Bind.lazyPut<Controller3>(() => Controller3()), | ||
210 | + ]; | ||
209 | } | 211 | } |
210 | } | 212 | } |
211 | ``` | 213 | ``` |
@@ -487,7 +489,7 @@ class Third extends GetView<ControllerX> { | @@ -487,7 +489,7 @@ class Third extends GetView<ControllerX> { | ||
487 | } | 489 | } |
488 | } | 490 | } |
489 | 491 | ||
490 | -class SampleBind extends Bindings { | 492 | +class SampleBind extends Binding { |
491 | @override | 493 | @override |
492 | void dependencies() { | 494 | void dependencies() { |
493 | Get.lazyPut<ControllerX>(() => ControllerX()); | 495 | Get.lazyPut<ControllerX>(() => ControllerX()); |
@@ -578,4 +580,4 @@ class SizeTransitions extends CustomTransition { | @@ -578,4 +580,4 @@ class SizeTransitions extends CustomTransition { | ||
578 | ); | 580 | ); |
579 | } | 581 | } |
580 | } | 582 | } |
581 | -``` | ||
583 | +``` |
@@ -5,11 +5,13 @@ import '../data/home_repository.dart'; | @@ -5,11 +5,13 @@ import '../data/home_repository.dart'; | ||
5 | import '../domain/adapters/repository_adapter.dart'; | 5 | import '../domain/adapters/repository_adapter.dart'; |
6 | import '../presentation/controllers/home_controller.dart'; | 6 | import '../presentation/controllers/home_controller.dart'; |
7 | 7 | ||
8 | -class HomeBinding extends Bindings { | 8 | +class HomeBinding extends Binding { |
9 | @override | 9 | @override |
10 | - void dependencies() { | ||
11 | - Get.lazyPut<IHomeProvider>(() => HomeProvider()); | ||
12 | - Get.lazyPut<IHomeRepository>(() => HomeRepository(provider: Get.find())); | ||
13 | - Get.lazyPut(() => HomeController(homeRepository: Get.find())); | 10 | + List<Bind> dependencies() { |
11 | + return [ | ||
12 | + Bind.lazyPut<IHomeProvider>(() => HomeProvider()), | ||
13 | + Bind.lazyPut<IHomeRepository>(() => HomeRepository(provider: Get.find())), | ||
14 | + Bind.lazyPut(() => HomeController(homeRepository: Get.find())), | ||
15 | + ]; | ||
14 | } | 16 | } |
15 | } | 17 | } |
@@ -2,11 +2,13 @@ import 'package:get/get.dart'; | @@ -2,11 +2,13 @@ import 'package:get/get.dart'; | ||
2 | 2 | ||
3 | import '../controllers/products_controller.dart'; | 3 | import '../controllers/products_controller.dart'; |
4 | 4 | ||
5 | -class ProductsBinding extends Bindings { | 5 | +class ProductsBinding extends Binding { |
6 | @override | 6 | @override |
7 | - void dependencies() { | ||
8 | - Get.lazyPut<ProductsController>( | ||
9 | - () => ProductsController(), | ||
10 | - ); | 7 | + List<Bind> dependencies() { |
8 | + return [ | ||
9 | + Bind.lazyPut<ProductsController>( | ||
10 | + () => ProductsController(), | ||
11 | + ) | ||
12 | + ]; | ||
11 | } | 13 | } |
12 | } | 14 | } |
-
Please register or login to post a comment