69 lines
2.1 KiB
Markdown
69 lines
2.1 KiB
Markdown
<!--
|
|
* Copyright (C) 2023 WYATT GROUP
|
|
* Please see the AUTHORS file for details.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
-->
|
|
|
|
# Flutter - Wyatt Go Router
|
|
|
|
<p align="left">
|
|
<a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"><img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /></a>
|
|
<img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" />
|
|
</p>
|
|
|
|
GoRouter Enhancements for Flutter
|
|
|
|
This package provides a set of utilities to help you use the [GoRouter](https://pub.dev/packages/go_router) package.
|
|
|
|
## Features
|
|
|
|
* PageProtection extension to add a protection to a page
|
|
* currentRoute method to get the current route anywhere in the app
|
|
* GoRouterRefreshStream to refresh the router when needed
|
|
* RouteBase flattenization to get a list of all the routes in the router
|
|
|
|
## Usage
|
|
|
|
If you want to protect a page, you can use the PageProtection extension:
|
|
|
|
```dart
|
|
GoRoute(
|
|
path: '/sign_in',
|
|
...
|
|
)..setPublic(),
|
|
```
|
|
|
|
If you want to get the current route, you can use the currentRoute method:
|
|
|
|
```dart
|
|
final route = GoRouter.of(context).currentRoute;
|
|
// or
|
|
final route = context.currentRoute;
|
|
```
|
|
|
|
If you want to refresh the router, you can use the GoRouterRefreshStream:
|
|
|
|
```dart
|
|
GoRouterRefreshStream(
|
|
context.read<AuthenticationCubit<Session>>().stream,
|
|
)
|
|
```
|
|
|
|
If you want to get a list of all the routes in the router, you can use the RouteBase flattenization:
|
|
|
|
```dart
|
|
final routes = GoRouter.of(context).flattenedRoutes;
|
|
```
|