https://github.com/fmotalleb/go_router_infused
https://github.com/fmotalleb/go_router_infused
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fmotalleb/go_router_infused
- Owner: FMotalleb
- License: bsd-3-clause
- Created: 2022-09-12T07:17:13.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-20T07:00:24.000Z (over 2 years ago)
- Last Synced: 2025-02-13T04:42:34.756Z (4 months ago)
- Language: C++
- Size: 299 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## background
this package was built as an extension on [go_router](https://pub.dev/packages/go_router)
currently in this version(0.0.1+) it only implements middleware
since middlewares are not supported by default in this case an extended version of `GoRoute`
is built (`GoRouteInfused`) that accepts middlewaresmiddlewares use [provider](https://pub.dev/packages/provider) to attach middleware's result to the context.
its simple to migrate to `GoRouteInfused`, since it uses all parameters of `GoRoute`
if you don't have any middleware for a route **DO NOT** use `GoRouteInfused`
## usecases
* parsing models from route parameters
* checking user authentication before changing route## example
model:
```dart
class MyModel{
final String text;
const MyModel(this.text);
factory MyModel.fromParams(Map params)=>MyModel(params['text']);
}
```middleware definition:
```dart
/// [GoMiddlewareParamsParser] is a built-in middleware that parses parameters
final myMiddleware = GoMiddlewareParamsParser(
parser:MyModel.fromParams,
canBeIgnored=true,
);
```route definition:
```dart
GoRouteInfused(
// currently you must provide parameters in path manually
path: "/path/to/route/:text",
builder:(context,state){
// there is a extension on `BuildContext` that checks existence of a provider
// its not efficient thu, you may need to create a method manually for this purpose.
if(context.hasProviderFor()){
final myInstance=context.read();
print(myInstance.text);
}
throw UnimplementedError();
},
middlewares = [
myMiddleware,
],
)
```in this example if you go to route `/path/to/route/test_text`
the result will be `test_text`.