flutter_go_router_extension 1.0.2
flutter_go_router_extension: ^1.0.2 copied to clipboard
A Flutter package that extends go_router with Android-style navigation behaviors, such as FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK.
Flutter GoRouter Extension #
A Flutter package that extends go_router with Android-style navigation behaviors.
Features #
pushWithSetNewRoutePath: Simulates Android'sFLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASKbehavior- Supports dynamic route parameters (e.g.,
/user/:id) - Supports wildcard routes (e.g.,
/files/*)
Installation #
Add this to your pubspec.yaml:
dependencies:
flutter_go_router_extension: ^1.0.2
Usage #
pushWithSetNewRoutePath #
When navigating to a page that already exists in the stack, it clears all pages above and including that page, then pushes a new instance of the target page.
import 'package:flutter_go_router_extension/flutter_go_router_extension.dart';
// In your widget
ElevatedButton(
onPressed: () {
context.pushWithSetNewRoutePath('/user/123');
},
child: Text('Go to User'),
)
Example #
If the original stack is:
/home -> /user/123 -> /user/123/posts -> /comments
And you call:
context.pushWithSetNewRoutePath('/user/123');
Processing steps:
- Route
/user/:idconverts to RegExp:^/user/[^/]+$ - Check
/comments- No match, remove - Check
/user/123/posts- No match, remove - Check
/user/123- Match found
Resulting stack:
/home -> /user/123 (new instance)
How It Works #
- Path to Regex Conversion: Dynamic parameters (
:param) are converted to[^/]+, wildcards (*) to.* - Stack Traversal: Iterates from the top of the navigation stack
- Match & Clear: When a matching route is found, all routes above it (including itself) are removed
- Push New Instance: A fresh instance of the target page is pushed onto the stack
Requirements #
- Flutter SDK
- go_router: ^14.0.0 or higher
License #
MIT License