Nipodemos

docs: more docs for dependency management

@@ -12,7 +12,6 @@ @@ -12,7 +12,6 @@
12 12
13 ![](getx.png) 13 ![](getx.png)
14 14
15 -  
16 - [About Get](#about-get) 15 - [About Get](#about-get)
17 - [Installing](#installing) 16 - [Installing](#installing)
18 - [The Three pillars](#the-three-pillars) 17 - [The Three pillars](#the-three-pillars)
@@ -28,7 +27,7 @@ @@ -28,7 +27,7 @@
28 - [Other Advanced APIs](#other-advanced-apis) 27 - [Other Advanced APIs](#other-advanced-apis)
29 - [Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations) 28 - [Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations)
30 - [Breaking changes from 2.0](#breaking-changes-from-20) 29 - [Breaking changes from 2.0](#breaking-changes-from-20)
31 -- [Why I made this package](#why-i-made-this-package) 30 +- [Why Getx](#why-getx)
32 31
33 # About Get 32 # About Get
34 33
@@ -71,7 +70,8 @@ Add "Get" before your materialApp, turning it into GetMaterialApp @@ -71,7 +70,8 @@ Add "Get" before your materialApp, turning it into GetMaterialApp
71 void main() => runApp(GetMaterialApp(home: Home())); 70 void main() => runApp(GetMaterialApp(home: Home()));
72 ``` 71 ```
73 72
74 -- Note: this does not modify the MaterialApp of the Flutter, GetMaterialApp is not a modified MaterialApp, it is just a pre-configured Widget, which has the default MaterialApp as a child. You can configure this manually, but it is definitely not necessary. GetMaterialApp will create routes, inject them, inject translations, inject everything you need for route navigation. If you use Get only for state management or dependency management, it is not necessary to use GetMaterialApp. GetMaterialApp is necessary for routes, snackbars, internationalization, bottomSheets, dialogs, and high-level apis related to routes and absence of context. 73 +- Note: This step in only necessary if you gonna use route management (`Get.to()`, `Get.back()` and so on). If you not gonna use it then it is not necessary to do step 1
  74 +- Note²: this does not modify the MaterialApp of the Flutter, GetMaterialApp is not a modified MaterialApp, it is just a pre-configured Widget, which has the default MaterialApp as a child. You can configure this manually, but it is definitely not necessary. GetMaterialApp will create routes, inject them, inject translations, inject everything you need for route navigation. If you use Get only for state management or dependency management, it is not necessary to use GetMaterialApp. GetMaterialApp is necessary for routes, snackbars, internationalization, bottomSheets, dialogs, and high-level apis related to routes and absence of context.
75 75
76 - Step 2: 76 - Step 2:
77 Create your business logic class and place all variables, methods and controllers inside it. 77 Create your business logic class and place all variables, methods and controllers inside it.
@@ -3,16 +3,18 @@ @@ -3,16 +3,18 @@
3 3
4 ## Simple Instance Manager 4 ## Simple Instance Manager
5 5
6 -- Note: If you are using Get's State Manager, you don't have to worry about that, just read for information, but pay more attention to the bindings api, which will do all of this automatically for you.  
7 -  
8 -Are you already using Get and want to make your project as lean as possible? Get has a simple and powerful dependency manager that allows you to retrieve the same class as your Bloc or Controller with just 1 lines of code, no Provider context, no inheritedWidget: 6 +Get has a simple and powerful dependency manager that allows you to retrieve the same class as your Bloc or Controller with just 1 lines of code, no Provider context, no inheritedWidget:
9 7
10 ```dart 8 ```dart
11 Controller controller = Get.put(Controller()); // Rather Controller controller = Controller(); 9 Controller controller = Get.put(Controller()); // Rather Controller controller = Controller();
12 ``` 10 ```
13 11
  12 +- Note: If you are using Get's State Manager, pay more attention to the bindings api, which will make easier to connect your view to your controller.
  13 +
14 Instead of instantiating your class within the class you are using, you are instantiating it within the Get instance, which will make it available throughout your App. 14 Instead of instantiating your class within the class you are using, you are instantiating it within the Get instance, which will make it available throughout your App.
15 -So you can use your controller (or class Bloc) normally 15 +So you can use your controller (or Bloc class) normally
  16 +
  17 +**Tip:** Get dependency management is decloupled from other parts of the package, so if for example your app is already using a state manager (any one, it doesn't matter), you don't need to rewrite it all, you can use this dependency injection with no problems at all
16 18
17 ```dart 19 ```dart
18 controller.fetchApi(); 20 controller.fetchApi();
@@ -61,6 +63,77 @@ To remove a instance of Get: @@ -61,6 +63,77 @@ To remove a instance of Get:
61 Get.delete<Controller>(); 63 Get.delete<Controller>();
62 ``` 64 ```
63 65
  66 +## Options
  67 +
  68 +When you use Get.put, lazyPut and putAsync you will have some options that you can change if you want
  69 +
  70 +- On Get.put():
  71 +
  72 +```dart
  73 +Get.put<S>(
  74 + // mandatory: the class that you want to get to save, like a controller or anything
  75 + // note: that "S" means that it can be anything
  76 + S dependency
  77 +
  78 + // optional: this is for when you want multiple classess that are of the same type
  79 + // since you normally get a class by using Get.find<Controller>(),
  80 + // you need to use tag to tell which instance you need
  81 + // must be unique string
  82 + String tag,
  83 +
  84 + // optional: by default, get will dispose instances after they are not used anymore (example,
  85 + // the controller of a view that is closed), but you might need that the instance
  86 + // to be kept there throughout the entire app, like an instance of sharedPreferences or something
  87 + // so you use this
  88 + // defaults to false
  89 + bool permanent = false,
  90 +
  91 + // optional: TODO: make docs about this
  92 + // defaults to false
  93 + bool overrideAbstract = false,
  94 +
  95 + // optional: TODO: make docs about this
  96 + FcBuilderFunc<S> builder,
  97 +)
  98 +```
  99 +
  100 +- On Get.lazyPut:
  101 +
  102 +```dart
  103 +Get.lazyPut<S>(
  104 + // mandatory: a method that will be executed when your class is called for the first time
  105 + // Example: Get.lazyPut<Controller>( () => Controller() )
  106 + FcBuilderFunc builder,
  107 +
  108 + // optional: same as Get.put(), it is used for when you want multiple different instance of a same class
  109 + // must be unique
  110 + String tag,
  111 +
  112 + // optional: TODO: make docs about this
  113 + // defaults to false
  114 + bool fenix = false
  115 +
  116 +)
  117 +```
  118 +
  119 +- On Get.putAsync:
  120 +
  121 +```dart
  122 +Get.putAsync<S>(
  123 +
  124 + // mandatory: an async method that will be executed to instantiate your class
  125 + // Example: Get.putAsync<YourAsyncClass>( () async => await YourAsyncClass() )
  126 + FcBuilderFuncAsync<S> builder,
  127 +
  128 + // optional: same as Get.put(), it is used for when you want multiple different instance of a same class
  129 + // must be unique
  130 + String tag,
  131 +
  132 + // optional: same as in Get.put(), used when you need to maintain that instance alive in the entire app
  133 + // defaults to false
  134 + bool permanent = false
  135 +```
  136 +
64 ## Bindings 137 ## Bindings
65 138
66 One of the great differentials of this package, perhaps, is the possibility of full integration of the routes, state manager and dependency manager. 139 One of the great differentials of this package, perhaps, is the possibility of full integration of the routes, state manager and dependency manager.
@@ -76,7 +149,9 @@ In addition, the Binding class will allow you to have SmartManager configuration @@ -76,7 +149,9 @@ In addition, the Binding class will allow you to have SmartManager configuration
76 - Create a class and implements Binding 149 - Create a class and implements Binding
77 150
78 ```dart 151 ```dart
79 -class HomeBinding implements Bindings{ 152 +class HomeBinding implements Bindings {
  153 +
  154 +}
80 ``` 155 ```
81 156
82 Your IDE will automatically ask you to override the "dependencies" method, and you just need to click on the lamp, override the method, and insert all the classes you are going to use on that route: 157 Your IDE will automatically ask you to override the "dependencies" method, and you just need to click on the lamp, override the method, and insert all the classes you are going to use on that route: