@@ -15,7 +15,7 @@ Add this to your package's pubspec.yaml file:
```
dependencies:
get: ^1.8.1
get: ^1.9.2
```
And import it:
...
...
@@ -212,6 +212,40 @@ void main() {
));
}
```
#### Middleware
If you want to hear Get events to trigger actions, you can add a GetObserver to your materialApp. This is extremely useful for triggering events whenever a specific Screen is displayed on the screen. Currently on Flutter you would have to put the event on initState and wait for a possible response in a navigator.pop (context); to get that. But with Get, this is extremely simple!
##### add GetObserver();
```dart
voidmain(){
runApp(MaterialApp(
onGenerateRoute:Router.generateRoute,
initialRoute:"/",
navigatorKey:Get.key,
navigatorObservers:[
GetObserver(MiddleWare.observer),// HERE !!!
],
));
}
```
Create a MiddleWare class
```dart
classMiddleWare{
staticobserver(Routingrouting){
/// You can listen in addition to the routes, the snackbars, dialogs and bottomsheets on each screen.
///If you need to enter any of these 3 events directly here,
///you must specify that the event is != Than you are trying to do.
child:Text('No route defined for ${settings.name}')),
body:
Center(child:Text('No route defined for ${settings.name}')),
));
}
}
...
...
@@ -246,7 +284,7 @@ class Router {
And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (BLoC will love it), and when your app is compiled to the web, your routes will appear in the url beautifully <3
```dart
classFirstRouteextendsStatelessWidget{
classFirstextendsStatelessWidget{
@override
Widgetbuild(BuildContextcontext){
returnScaffold(
...
...
@@ -271,12 +309,37 @@ class FirstRoute extends StatelessWidget {