- This update attaches two nice features developed by (@SchabanBo): *GetPage Children* And *GetMiddleware*
In previous versions, to create child pages, you should do something like:
```dart
GetPage(
name:'/home',
page:()=>HomeView(),
binding:HomeBinding(),
),
GetPage(
name:'/home/products',
page:()=>ProductsView(),
binding:ProductsBinding(),
),
GetPage(
name:'/home/products/electronics',
page:()=>ElectronicsView(),
binding:ElectronicsBinding(),
),
```
Although the feature works well, it could be improved in several ways:
1- If you had many pages, the page file could become huge and difficult to read. Besides, it was difficult to know which page was the daughter of which module.
2- It was not possible to delegate the function of naming routes to a subroutine file.
With this update, it is possible to create a declarative structure, very similar to the Flutter widget tree for your route, which might look like this:
```dart
GetPage(
name:'/home',
page:()=>HomeView(),
binding:HomeBinding(),
children:[
GetPage(
name:'/products',
page:()=>ProductsView(),
binding:ProductsBinding(),
children:[
GetPage(
name:'/electronics',
page:()=>ElectronicsView(),
binding:ElectronicsBinding(),
),
],
),
],
);
```
Thus, when accessing the url: '/home/products/electronics'
Or use Get.toNamed('/home/products/electronics') it will go directly to the page [ElectronicsView], because the child pages, automatically inherit the name of the ancestral page, so _with any small change on any father in the tree all children will be updated._ If you change [/products] to [/accessories], you don't nesse update on all child links.
However, the most powerful feature of this version is *GetMiddlewares*.
The GetPage has now new property that takes a list of GetMiddleWare than can perform actions and run them in the specific order.
### Priority
The Order of the Middlewares to run can pe set by the priority in the GetMiddleware.
```dart
finalmiddlewares=[
GetMiddleware(priority:2),
GetMiddleware(priority:5),
GetMiddleware(priority:4),
GetMiddleware(priority:-8),
];
```
those middlewares will be run in this order **-8 => 2 => 4 => 5**
### Redirect
This function will be called when the page of the called route is being searched for. It takes RouteSettings as a result to redirect to. Or give it null and there will be no redirecting.
This function will be called right after the GetPage.page function is called and will give you the result of the function. and take the widget that will be showed.
### OnPageDispose
This function will be called right after disposing all the related objects (Controllers, views, ...) of the page.
## [3.20.1]
* Fix wrong reference with unnamed routes and added more tests
-[Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations)
-[Local State Widgets](#local-state-widgets)
...
...
@@ -416,8 +424,6 @@ GetConnect is highly customizable You can define base Url, as answer modifiers,
classHomeProviderextendsGetConnect{
@override
voidonInit(){
@override
voidonInit(){
// All request will pass to jsonEncode so CasesModel.fromJson()
httpClient.defaultDecoder=CasesModel.fromJson;
httpClient.baseUrl='https://api.covid19api.com';
...
...
@@ -459,6 +465,83 @@ class HomeProvider extends GetConnect {
}
```
## GetPage Middleware
The GetPage has now new property that takes a list of GetMiddleWare and run them in the specific order.
**Note**: When GetPage has a Middlewares, all the children of this page will have the same middlewares automatically.
### Priority
The Order of the Middlewares to run can pe set by the priority in the GetMiddleware.
```dart
finalmiddlewares=[
GetMiddleware(priority:2),
GetMiddleware(priority:5),
GetMiddleware(priority:4),
GetMiddleware(priority:-8),
];
```
those middlewares will be run in this order **-8 => 2 => 4 => 5**
### Redirect
This function will be called when the page of the called route is being searched for. It takes RouteSettings as a result to redirect to. Or give it null and there will be no redirecting.
This function will be called right after the GetPage.page function is called and will give you the result of the function. and take the widget that will be showed.
### OnPageDispose
This function will be called right after disposing all the related objects (Controllers, views, ...) of the page.