Showing
1 changed file
with
50 additions
and
21 deletions
| 1 | # Get | 1 | # Get |
| 2 | 2 | ||
| 3 | -A consistent navigation library that lets you navigate between screens, open dialogs, and display snackbars from anywhere in your code without context. | 3 | +A consistent navigation library that lets you navigate between screens, open dialogs/bottomSheets, and display snackbars from anywhere in your code without context. |
| 4 | ## Getting Started | 4 | ## Getting Started |
| 5 | 5 | ||
| 6 | Flutter's conventional navigation has a lot of unnecessary boilerplate, requires context to navigate between screens, open dialogs, and snacking is really painful. | 6 | Flutter's conventional navigation has a lot of unnecessary boilerplate, requires context to navigate between screens, open dialogs, and snacking is really painful. |
| @@ -15,7 +15,7 @@ Add this to your package's pubspec.yaml file: | @@ -15,7 +15,7 @@ Add this to your package's pubspec.yaml file: | ||
| 15 | 15 | ||
| 16 | ``` | 16 | ``` |
| 17 | dependencies: | 17 | dependencies: |
| 18 | - get: ^1.7.1 | 18 | + get: ^1.7.3 |
| 19 | ``` | 19 | ``` |
| 20 | 20 | ||
| 21 | And import it: | 21 | And import it: |
| @@ -29,6 +29,7 @@ MaterialApp( | @@ -29,6 +29,7 @@ MaterialApp( | ||
| 29 | home: MyHome(), | 29 | home: MyHome(), |
| 30 | ) | 30 | ) |
| 31 | ``` | 31 | ``` |
| 32 | +### Navigating without named routes | ||
| 32 | To navigate to a new screen: | 33 | To navigate to a new screen: |
| 33 | 34 | ||
| 34 | ```dart | 35 | ```dart |
| @@ -50,7 +51,7 @@ Get.off(NextScreen()); | @@ -50,7 +51,7 @@ Get.off(NextScreen()); | ||
| 50 | To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests) | 51 | To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests) |
| 51 | 52 | ||
| 52 | ```dart | 53 | ```dart |
| 53 | -Get.offAll(NextScreen(), (route) => false)); | 54 | +Get.offAll(NextScreen(), (route) => false); |
| 54 | ``` | 55 | ``` |
| 55 | 56 | ||
| 56 | To navigate to the next route, and receive or update data as soon as you return from it: | 57 | To navigate to the next route, and receive or update data as soon as you return from it: |
| @@ -68,16 +69,34 @@ ex: | @@ -68,16 +69,34 @@ ex: | ||
| 68 | ```dart | 69 | ```dart |
| 69 | if(data == 'sucess') madeAnything(); | 70 | if(data == 'sucess') madeAnything(); |
| 70 | ``` | 71 | ``` |
| 71 | -Others methods: | 72 | +### Others methods (docs will be added soon): |
| 72 | Get.removeRoute // remove one route. | 73 | Get.removeRoute // remove one route. |
| 73 | Get.until // back repeatedly until the predicate returns true. | 74 | Get.until // back repeatedly until the predicate returns true. |
| 74 | Get.offUntil // go to next route and remove all the previous routes until the predicate returns true. | 75 | Get.offUntil // go to next route and remove all the previous routes until the predicate returns true. |
| 75 | Get.offNamedUntil // go to next named route and remove all the previous routes until the predicate returns true. | 76 | Get.offNamedUntil // go to next named route and remove all the previous routes until the predicate returns true. |
| 76 | 77 | ||
| 77 | - | 78 | +### SnackBars |
| 78 | To show a modern snackbar: | 79 | To show a modern snackbar: |
| 79 | ```dart | 80 | ```dart |
| 80 | Get.snackbar('Hi', 'i am a modern snackbar'); | 81 | Get.snackbar('Hi', 'i am a modern snackbar'); |
| 82 | +``` | ||
| 83 | +To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold, | ||
| 84 | +but with Get, all you have to do is call your Get.snackbar from anywhere in your code or customize it however you want with GetBar! | ||
| 85 | + | ||
| 86 | +```dart | ||
| 87 | + GetBar( | ||
| 88 | + title: "Hey i'm a Get SnackBar!", | ||
| 89 | + message: | ||
| 90 | + "It's unbelievable! I'm using SnackBar without context, without boilerplate, without Scaffold, it is something truly amazing!", | ||
| 91 | + icon: Icon(Icons.alarm), | ||
| 92 | + shouldIconPulse: true, | ||
| 93 | + onTap:(){}, | ||
| 94 | + barBlur: 20, | ||
| 95 | + isDismissible: true, | ||
| 96 | + duration: Duration(seconds: 3), | ||
| 97 | + )..show(); | ||
| 98 | +``` | ||
| 99 | +### Dialogs | ||
| 81 | 100 | ||
| 82 | To open dialog: | 101 | To open dialog: |
| 83 | 102 | ||
| @@ -101,21 +120,30 @@ To open default dialog: | @@ -101,21 +120,30 @@ To open default dialog: | ||
| 101 | )); | 120 | )); |
| 102 | ``` | 121 | ``` |
| 103 | 122 | ||
| 104 | -To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold, | ||
| 105 | -but with Get, all you have to do is call your SnackBar from anywhere in your code and and customize it however you want! | 123 | +### BottomSheets |
| 124 | +Get.bottomSheet is like showModalBottomSheet, but don't need of context. | ||
| 106 | 125 | ||
| 107 | ```dart | 126 | ```dart |
| 108 | - GetBar( | ||
| 109 | - title: "Hey i'm a Get SnackBar!", | ||
| 110 | - message: | ||
| 111 | - "It's unbelievable! I'm using SnackBar without context, without boilerplate, without Scaffold, it is something truly amazing!", | ||
| 112 | - icon: Icon(Icons.alarm), | ||
| 113 | - shouldIconPulse: true, | ||
| 114 | - onTap:(){}, | ||
| 115 | - barBlur: 20, | ||
| 116 | - isDismissible: true, | ||
| 117 | - duration: Duration(seconds: 3), | ||
| 118 | - )..show(); | 127 | +Get.bottomSheet( |
| 128 | + builder: (_){ | ||
| 129 | + return Container( | ||
| 130 | + child: Wrap( | ||
| 131 | + children: <Widget>[ | ||
| 132 | + ListTile( | ||
| 133 | + leading: Icon(Icons.music_note), | ||
| 134 | + title: Text('Music'), | ||
| 135 | + onTap: () => {} | ||
| 136 | + ), | ||
| 137 | + ListTile( | ||
| 138 | + leading: Icon(Icons.videocam), | ||
| 139 | + title: Text('Video'), | ||
| 140 | + onTap: () => {}, | ||
| 141 | + ), | ||
| 142 | + ], | ||
| 143 | + ), | ||
| 144 | + ); | ||
| 145 | + } | ||
| 146 | + ); | ||
| 119 | ``` | 147 | ``` |
| 120 | 148 | ||
| 121 | 149 | ||
| @@ -137,7 +165,7 @@ Get.offNamed("/NextScreen"); | @@ -137,7 +165,7 @@ Get.offNamed("/NextScreen"); | ||
| 137 | ``` | 165 | ``` |
| 138 | To navigate and remove all previous screens from the tree. | 166 | To navigate and remove all previous screens from the tree. |
| 139 | ```dart | 167 | ```dart |
| 140 | -Get.offAllNamed("/NextScreen", (route) => false)); | 168 | +Get.offAllNamed("/NextScreen", (route) => false); |
| 141 | ``` | 169 | ``` |
| 142 | 170 | ||
| 143 | ## Using with Named Routes and And offering full flutter_web support (REQUIRED FOR NAMED ROUTES): | 171 | ## Using with Named Routes and And offering full flutter_web support (REQUIRED FOR NAMED ROUTES): |
| @@ -175,12 +203,13 @@ class Router { | @@ -175,12 +203,13 @@ class Router { | ||
| 175 | settings: settings, | 203 | settings: settings, |
| 176 | ); | 204 | ); |
| 177 | case '/Home': | 205 | case '/Home': |
| 178 | - return GetRoute(settings: settings, builder: (_) => Home()); | 206 | + return GetRoute(settings: settings, builder: (_) => Home(), transition: Transition.fade); |
| 179 | case '/Chat': | 207 | case '/Chat': |
| 180 | - return GetRoute(settings: settings, builder: (_) => Chat()); | 208 | + return GetRoute(settings: settings, builder: (_) => Chat(),transition: Transition.rightToLeft); |
| 181 | default: | 209 | default: |
| 182 | return GetRoute( | 210 | return GetRoute( |
| 183 | settings: settings, | 211 | settings: settings, |
| 212 | + transition: Transition.rotate | ||
| 184 | builder: (_) => Scaffold( | 213 | builder: (_) => Scaffold( |
| 185 | body: Center( | 214 | body: Center( |
| 186 | child: Text('No route defined for ${settings.name}')), | 215 | child: Text('No route defined for ${settings.name}')), |
-
Please register or login to post a comment