Nipodemos

adress suggested changes

Showing 1 changed file with 219 additions and 215 deletions
@@ -57,18 +57,16 @@ This is a simple project but it already makes clear how powerful Get is. As your @@ -57,18 +57,16 @@ This is a simple project but it already makes clear how powerful Get is. As your
57 57
58 - [Route Management](#route-management) 58 - [Route Management](#route-management)
59 - [How to use?](#how-to-use) 59 - [How to use?](#how-to-use)
60 - - [Navigating between routes](#navigating-between-routes)  
61 - - [SnackBars](#snackbars)  
62 - - [Dialogs](#dialogs)  
63 - - [BottomSheets](#bottomsheets)  
64 - - [Navigate with named routes:](#navigate-with-named-routes) 60 + - [Navigation without named routes](#navigation-without-named-routes)
  61 + - [Navigation with named routes](#navigation-with-named-routes)
65 - [Send data to named Routes:](#send-data-to-named-routes) 62 - [Send data to named Routes:](#send-data-to-named-routes)
66 - [Dynamic urls links](#dynamic-urls-links) 63 - [Dynamic urls links](#dynamic-urls-links)
67 - [Middleware](#middleware) 64 - [Middleware](#middleware)
  65 + - [Navigation without context](#navigation-without-context)
  66 + - [SnackBars](#snackbars)
  67 + - [Dialogs](#dialogs)
  68 + - [BottomSheets](#bottomsheets)
68 - [Nested Navigation](#nested-navigation) 69 - [Nested Navigation](#nested-navigation)
69 -- [Syntax sugar for context-required methods](#syntax-sugar-for-context-required-methods)  
70 - - [Change Theme](#change-theme)  
71 - - [Other Advanced APIs and Manual configurations](#other-advanced-apis-and-manual-configurations)  
72 - [State Management](#state-management) 70 - [State Management](#state-management)
73 - [Simple State Manager](#simple-state-manager) 71 - [Simple State Manager](#simple-state-manager)
74 - [Advantages](#advantages) 72 - [Advantages](#advantages)
@@ -93,9 +91,12 @@ This is a simple project but it already makes clear how powerful Get is. As your @@ -93,9 +91,12 @@ This is a simple project but it already makes clear how powerful Get is. As your
93 - [Bindings](#bindings) 91 - [Bindings](#bindings)
94 - [How to use](#how-to-use-1) 92 - [How to use](#how-to-use-1)
95 - [SmartManagement](#smartmanagement) 93 - [SmartManagement](#smartmanagement)
  94 +- [Utils](#utils)
  95 + - [Change Theme](#change-theme)
  96 + - [Other Advanced APIs and Manual configurations](#other-advanced-apis-and-manual-configurations)
96 - [Optional Global Settings](#optional-global-settings) 97 - [Optional Global Settings](#optional-global-settings)
97 98
98 -#### Want to contribute to the project? We will be proud to highlight you as one of our collaborators. Here are some points where you can contribute and make Get (and Flutter) even better. 99 +*Want to contribute to the project? We will be proud to highlight you as one of our collaborators. Here are some points where you can contribute and make Get (and Flutter) even better.*
99 100
100 - Helping to translate the readme into other languages. 101 - Helping to translate the readme into other languages.
101 - Adding documentation to the readme (not even half of Get's functions have been documented yet). 102 - Adding documentation to the readme (not even half of Get's functions have been documented yet).
@@ -104,6 +105,7 @@ This is a simple project but it already makes clear how powerful Get is. As your @@ -104,6 +105,7 @@ This is a simple project but it already makes clear how powerful Get is. As your
104 - Including new functions. 105 - Including new functions.
105 106
106 # Route Management 107 # Route Management
  108 +
107 Any contribution is welcome! 109 Any contribution is welcome!
108 110
109 ## How to use? 111 ## How to use?
@@ -122,7 +124,7 @@ GetMaterialApp( // Before: MaterialApp( @@ -122,7 +124,7 @@ GetMaterialApp( // Before: MaterialApp(
122 ) 124 )
123 ``` 125 ```
124 126
125 -## Navigating between routes 127 +## Navigation without named routes
126 To navigate to a new screen: 128 To navigate to a new screen:
127 129
128 ```dart 130 ```dart
@@ -194,129 +196,7 @@ Get.to(HomePage()); @@ -194,129 +196,7 @@ Get.to(HomePage());
194 196
195 ``` 197 ```
196 198
197 -### SnackBars  
198 -  
199 -To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold,  
200 -```dart  
201 -final snackBar = SnackBar(  
202 - content: Text('Hi!'),  
203 - action: SnackBarAction(  
204 - label: 'I am a old and ugly snackbar :(',  
205 - onPressed: (){}  
206 - ),  
207 -);  
208 -// Find the Scaffold in the widget tree and use  
209 -// it to show a SnackBar.  
210 -Scaffold.of(context).showSnackBar(snackBar);  
211 -```  
212 -  
213 -With Get:  
214 -  
215 -```dart  
216 -Get.snackbar('Hi', 'i am a modern snackbar');  
217 -```  
218 -  
219 -With Get, all you have to do is call your Get.snackbar from anywhere in your code or customize it however you want!  
220 -  
221 -```dart  
222 -Get.snackbar(  
223 - "Hey i'm a Get SnackBar!", // title  
224 - "It's unbelievable! I'm using SnackBar without context, without boilerplate, without Scaffold, it is something truly amazing!", // message  
225 - icon: Icon(Icons.alarm),  
226 - shouldIconPulse: true,  
227 - onTap:(){},  
228 - barBlur: 20,  
229 - isDismissible: true,  
230 - duration: Duration(seconds: 3),  
231 -);  
232 -  
233 -  
234 - ////////// ALL FEATURES //////////  
235 - // Color colorText,  
236 - // Duration duration,  
237 - // SnackPosition snackPosition,  
238 - // Widget titleText,  
239 - // Widget messageText,  
240 - // bool instantInit,  
241 - // Widget icon,  
242 - // bool shouldIconPulse,  
243 - // double maxWidth,  
244 - // EdgeInsets margin,  
245 - // EdgeInsets padding,  
246 - // double borderRadius,  
247 - // Color borderColor,  
248 - // double borderWidth,  
249 - // Color backgroundColor,  
250 - // Color leftBarIndicatorColor,  
251 - // List<BoxShadow> boxShadows,  
252 - // Gradient backgroundGradient,  
253 - // FlatButton mainButton,  
254 - // OnTap onTap,  
255 - // bool isDismissible,  
256 - // bool showProgressIndicator,  
257 - // AnimationController progressIndicatorController,  
258 - // Color progressIndicatorBackgroundColor,  
259 - // Animation<Color> progressIndicatorValueColor,  
260 - // SnackStyle snackStyle,  
261 - // Curve forwardAnimationCurve,  
262 - // Curve reverseAnimationCurve,  
263 - // Duration animationDuration,  
264 - // double barBlur,  
265 - // double overlayBlur,  
266 - // Color overlayColor,  
267 - // Form userInputForm  
268 - ///////////////////////////////////  
269 -```  
270 -If you prefer the traditional snackbar, or want to customize it from scratch, including adding just one line (Get.snackbar makes use of a mandatory title and message), you can use  
271 -`Get.rawSnackbar();` which provides the RAW API on which Get.snackbar was built.  
272 -  
273 -### Dialogs  
274 -  
275 -To open dialog:  
276 -  
277 -```dart  
278 -Get.dialog(YourDialogWidget());  
279 -```  
280 -  
281 -To open default dialog:  
282 -  
283 -```dart  
284 -Get.defaultDialog(  
285 - onConfirm: () => print("Ok"),  
286 - middleText: "Dialog made in 3 lines of code"  
287 -);  
288 -```  
289 -You can also use Get.generalDialog instead of showGeneralDialog.  
290 -  
291 -For all other Flutter dialog widgets, including cupertinos, you can use Get.overlayContext instead of context, and open it anywhere in your code.  
292 -For widgets that don't use Overlay, you can use Get.context.  
293 -These two contexts will work in 99% of cases to replace the context of your UI, except for cases where inheritedWidget is used without a navigation context.  
294 -  
295 -### BottomSheets  
296 -Get.bottomSheet is like showModalBottomSheet, but don't need of context.  
297 -  
298 -```dart  
299 -Get.bottomSheet(  
300 - Container(  
301 - child: Wrap(  
302 - children: <Widget>[  
303 - ListTile(  
304 - leading: Icon(Icons.music_note),  
305 - title: Text('Music'),  
306 - onTap: () => {}  
307 - ),  
308 - ListTile(  
309 - leading: Icon(Icons.videocam),  
310 - title: Text('Video'),  
311 - onTap: () => {},  
312 - ),  
313 - ],  
314 - ),  
315 - );  
316 -);  
317 -```  
318 -  
319 -## Navigate with named routes: 199 +## Navigation with named routes
320 - If you prefer to navigate by namedRoutes, Get also supports this. 200 - If you prefer to navigate by namedRoutes, Get also supports this.
321 201
322 To navigate to nextScreen 202 To navigate to nextScreen
@@ -528,6 +408,129 @@ class Third extends StatelessWidget { @@ -528,6 +408,129 @@ class Third extends StatelessWidget {
528 } 408 }
529 } 409 }
530 ``` 410 ```
  411 +## Navigation without context
  412 +
  413 +### SnackBars
  414 +
  415 +To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold,
  416 +```dart
  417 +final snackBar = SnackBar(
  418 + content: Text('Hi!'),
  419 + action: SnackBarAction(
  420 + label: 'I am a old and ugly snackbar :(',
  421 + onPressed: (){}
  422 + ),
  423 +);
  424 +// Find the Scaffold in the widget tree and use
  425 +// it to show a SnackBar.
  426 +Scaffold.of(context).showSnackBar(snackBar);
  427 +```
  428 +
  429 +With Get:
  430 +
  431 +```dart
  432 +Get.snackbar('Hi', 'i am a modern snackbar');
  433 +```
  434 +
  435 +With Get, all you have to do is call your Get.snackbar from anywhere in your code or customize it however you want!
  436 +
  437 +```dart
  438 +Get.snackbar(
  439 + "Hey i'm a Get SnackBar!", // title
  440 + "It's unbelievable! I'm using SnackBar without context, without boilerplate, without Scaffold, it is something truly amazing!", // message
  441 + icon: Icon(Icons.alarm),
  442 + shouldIconPulse: true,
  443 + onTap:(){},
  444 + barBlur: 20,
  445 + isDismissible: true,
  446 + duration: Duration(seconds: 3),
  447 +);
  448 +
  449 +
  450 + ////////// ALL FEATURES //////////
  451 + // Color colorText,
  452 + // Duration duration,
  453 + // SnackPosition snackPosition,
  454 + // Widget titleText,
  455 + // Widget messageText,
  456 + // bool instantInit,
  457 + // Widget icon,
  458 + // bool shouldIconPulse,
  459 + // double maxWidth,
  460 + // EdgeInsets margin,
  461 + // EdgeInsets padding,
  462 + // double borderRadius,
  463 + // Color borderColor,
  464 + // double borderWidth,
  465 + // Color backgroundColor,
  466 + // Color leftBarIndicatorColor,
  467 + // List<BoxShadow> boxShadows,
  468 + // Gradient backgroundGradient,
  469 + // FlatButton mainButton,
  470 + // OnTap onTap,
  471 + // bool isDismissible,
  472 + // bool showProgressIndicator,
  473 + // AnimationController progressIndicatorController,
  474 + // Color progressIndicatorBackgroundColor,
  475 + // Animation<Color> progressIndicatorValueColor,
  476 + // SnackStyle snackStyle,
  477 + // Curve forwardAnimationCurve,
  478 + // Curve reverseAnimationCurve,
  479 + // Duration animationDuration,
  480 + // double barBlur,
  481 + // double overlayBlur,
  482 + // Color overlayColor,
  483 + // Form userInputForm
  484 + ///////////////////////////////////
  485 +```
  486 +If you prefer the traditional snackbar, or want to customize it from scratch, including adding just one line (Get.snackbar makes use of a mandatory title and message), you can use
  487 +`Get.rawSnackbar();` which provides the RAW API on which Get.snackbar was built.
  488 +
  489 +### Dialogs
  490 +
  491 +To open dialog:
  492 +
  493 +```dart
  494 +Get.dialog(YourDialogWidget());
  495 +```
  496 +
  497 +To open default dialog:
  498 +
  499 +```dart
  500 +Get.defaultDialog(
  501 + onConfirm: () => print("Ok"),
  502 + middleText: "Dialog made in 3 lines of code"
  503 +);
  504 +```
  505 +You can also use Get.generalDialog instead of showGeneralDialog.
  506 +
  507 +For all other Flutter dialog widgets, including cupertinos, you can use Get.overlayContext instead of context, and open it anywhere in your code.
  508 +For widgets that don't use Overlay, you can use Get.context.
  509 +These two contexts will work in 99% of cases to replace the context of your UI, except for cases where inheritedWidget is used without a navigation context.
  510 +
  511 +### BottomSheets
  512 +Get.bottomSheet is like showModalBottomSheet, but don't need of context.
  513 +
  514 +```dart
  515 +Get.bottomSheet(
  516 + Container(
  517 + child: Wrap(
  518 + children: <Widget>[
  519 + ListTile(
  520 + leading: Icon(Icons.music_note),
  521 + title: Text('Music'),
  522 + onTap: () => {}
  523 + ),
  524 + ListTile(
  525 + leading: Icon(Icons.videocam),
  526 + title: Text('Video'),
  527 + onTap: () => {},
  528 + ),
  529 + ],
  530 + ),
  531 + );
  532 +);
  533 +```
531 534
532 535
533 ## Nested Navigation 536 ## Nested Navigation
@@ -579,89 +582,9 @@ Navigator( @@ -579,89 +582,9 @@ Navigator(
579 ``` 582 ```
580 583
581 584
582 -# Syntax sugar for context-required methods  
583 -  
584 -## Change Theme  
585 -Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get.  
586 -  
587 -You can create your custom theme and simply add it within Get.changeTheme without any boilerplate for that:  
588 -  
589 -  
590 -```dart  
591 -Get.changeTheme(ThemeData.light());  
592 -```  
593 -  
594 -If you want to create something like a button that changes the theme with onTap, you can combine two Get APIs for that, the api that checks if the dark theme is being used, and the theme change API, you can just put this within an onPressed:  
595 -  
596 -```dart  
597 -Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark());  
598 -```  
599 -  
600 -When darkmode is activated, it will switch to the light theme, and when the light theme is activated, it will change to dark.  
601 -  
602 -  
603 -If you want to know in depth how to change the theme, you can follow this tutorial on Medium that even teaches the persistence of the theme using Get:  
604 -  
605 -- [Dynamic Themes in 3 lines using Get](https://medium.com/swlh/flutter-dynamic-themes-in-3-lines-c3b375f292e3) - Tutorial by [Rod Brown](https://github.com/RodBr).  
606 -  
607 -  
608 -  
609 -## Other Advanced APIs and Manual configurations  
610 -GetMaterialApp configures everything for you, but if you want to configure Get Manually using advanced APIs.  
611 -  
612 -```dart  
613 -MaterialApp(  
614 - navigatorKey: Get.key,  
615 - navigatorObservers: [GetObserver()],  
616 -);  
617 -```  
618 -  
619 -You will also be able to use your own Middleware within GetObserver, this will not influence anything.  
620 -  
621 -```dart  
622 -MaterialApp(  
623 - navigatorKey: Get.key,  
624 - navigatorObservers: [GetObserver(MiddleWare.observer)], // Here  
625 -);  
626 -```  
627 -  
628 -```dart  
629 -Get.arguments // give the current args from currentScreen  
630 -  
631 -Get.previousArguments // give arguments of previous route  
632 -  
633 -Get.previousRoute // give name of previous route  
634 -  
635 -Get.rawRoute // give the raw route to access for example, rawRoute.isFirst()  
636 -  
637 -Get.routing // give access to Rounting API from GetObserver  
638 -  
639 -Get.isSnackbarOpen // check if snackbar is open  
640 -  
641 -Get.isDialogOpen // check if dialog is open  
642 -  
643 -Get.isBottomSheetOpen // check if bottomsheet is open  
644 -  
645 -Get.removeRoute() // remove one route.  
646 -  
647 -Get.until() // back repeatedly until the predicate returns true.  
648 -  
649 -Get.offUntil() // go to next route and remove all the previous routes until the predicate returns true.  
650 -  
651 -Get.offNamedUntil() // go to next named route and remove all the previous routes until the predicate returns true.  
652 -  
653 -GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid")  
654 -  
655 -Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height, but they are immutable. If you need a changeable height/width (like browser windows that can be scaled) you will need to use context.height and context.width  
656 -  
657 -Get.context // Gives the context of the screen in the foreground anywhere in your code.  
658 -  
659 -Get.contextOverlay // Gives the context of the snackbar/dialog/bottomsheet in the foreground anywhere in your code.  
660 -  
661 -```  
662 -  
663 # State Management 585 # State Management
664 -There are currently several state managers for Flutter. However, most of them involve using ChangeNotifier to update widgets and this is a bad and very bad approach to performance of medium or large applications. You can check in the official Flutter documentation that ChangeNotifier should be used with 1 or a maximum of 2 listeners (https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html), making it practically unusable for any application medium or large. 586 +
  587 +There are currently several state managers for Flutter. However, most of them involve using ChangeNotifier to update widgets and this is a bad and very bad approach to performance of medium or large applications. You can check in the official Flutter documentation that [ChangeNotifier should be used with 1 or a maximum of 2 listeners](https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html), making it practically unusable for any application medium or large.
665 588
666 Other state managers are good, but have their nuances: 589 Other state managers are good, but have their nuances:
667 - BLoC is very safe and efficient, but it is very complex for beginners, which has kept people from developing with Flutter. 590 - BLoC is very safe and efficient, but it is very complex for beginners, which has kept people from developing with Flutter.
@@ -1234,6 +1157,87 @@ Bindings creates transitory factories, which are created the moment you click to @@ -1234,6 +1157,87 @@ Bindings creates transitory factories, which are created the moment you click to
1234 However, if you work with Services or any other abstraction, I recommend using Bindings for a larger organization. 1157 However, if you work with Services or any other abstraction, I recommend using Bindings for a larger organization.
1235 1158
1236 1159
  1160 +# Utils
  1161 +
  1162 +## Change Theme
  1163 +Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get.
  1164 +
  1165 +You can create your custom theme and simply add it within Get.changeTheme without any boilerplate for that:
  1166 +
  1167 +
  1168 +```dart
  1169 +Get.changeTheme(ThemeData.light());
  1170 +```
  1171 +
  1172 +If you want to create something like a button that changes the theme with onTap, you can combine two Get APIs for that, the api that checks if the dark theme is being used, and the theme change API, you can just put this within an onPressed:
  1173 +
  1174 +```dart
  1175 +Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark());
  1176 +```
  1177 +
  1178 +When darkmode is activated, it will switch to the light theme, and when the light theme is activated, it will change to dark.
  1179 +
  1180 +
  1181 +If you want to know in depth how to change the theme, you can follow this tutorial on Medium that even teaches the persistence of the theme using Get:
  1182 +
  1183 +- [Dynamic Themes in 3 lines using Get](https://medium.com/swlh/flutter-dynamic-themes-in-3-lines-c3b375f292e3) - Tutorial by [Rod Brown](https://github.com/RodBr).
  1184 +
  1185 +
  1186 +
  1187 +## Other Advanced APIs and Manual configurations
  1188 +GetMaterialApp configures everything for you, but if you want to configure Get Manually using advanced APIs.
  1189 +
  1190 +```dart
  1191 +MaterialApp(
  1192 + navigatorKey: Get.key,
  1193 + navigatorObservers: [GetObserver()],
  1194 +);
  1195 +```
  1196 +
  1197 +You will also be able to use your own Middleware within GetObserver, this will not influence anything.
  1198 +
  1199 +```dart
  1200 +MaterialApp(
  1201 + navigatorKey: Get.key,
  1202 + navigatorObservers: [GetObserver(MiddleWare.observer)], // Here
  1203 +);
  1204 +```
  1205 +
  1206 +```dart
  1207 +Get.arguments // give the current args from currentScreen
  1208 +
  1209 +Get.previousArguments // give arguments of previous route
  1210 +
  1211 +Get.previousRoute // give name of previous route
  1212 +
  1213 +Get.rawRoute // give the raw route to access for example, rawRoute.isFirst()
  1214 +
  1215 +Get.routing // give access to Rounting API from GetObserver
  1216 +
  1217 +Get.isSnackbarOpen // check if snackbar is open
  1218 +
  1219 +Get.isDialogOpen // check if dialog is open
  1220 +
  1221 +Get.isBottomSheetOpen // check if bottomsheet is open
  1222 +
  1223 +Get.removeRoute() // remove one route.
  1224 +
  1225 +Get.until() // back repeatedly until the predicate returns true.
  1226 +
  1227 +Get.offUntil() // go to next route and remove all the previous routes until the predicate returns true.
  1228 +
  1229 +Get.offNamedUntil() // go to next named route and remove all the previous routes until the predicate returns true.
  1230 +
  1231 +GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid")
  1232 +
  1233 +Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height, but they are immutable. If you need a changeable height/width (like browser windows that can be scaled) you will need to use context.height and context.width
  1234 +
  1235 +Get.context // Gives the context of the screen in the foreground anywhere in your code.
  1236 +
  1237 +Get.contextOverlay // Gives the context of the snackbar/dialog/bottomsheet in the foreground anywhere in your code.
  1238 +
  1239 +```
  1240 +
1237 1241
1238 ### Optional Global Settings 1242 ### Optional Global Settings
1239 You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp 1243 You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp