In case of error, I want to redirect my users to the same flow again (in order to reset the flow state).
I'm using the auto_route package for navigation, and I can see that router.replace and router.replaceAll do not replace (remove and insert from the stack) the same routes again (it just updates them).
From the official documentation:
// removes last entry in stack and pushs provided route
// if last entry == provided route page will just be updated
router.replace(const BooksListRoute())
// This's like providing a completely new stack as it rebuilds the stack
// with the list of passed routes
// entires might just update if already exist
router.replaceAll([
LoginRoute()
]);
How can I "hard reset" replace a route, or stack of routes, using auto_route package?
In order to "hard reset" the same page using auto_route package, Use pushAndPopUntil function, with a predicate set to always false.
That way, all pages will be removed, and the provided stack will be inserted instead (in other words, a full replacement, even for the same page).
Then your page will reinitiate, and all state values will be reset (same as redirecting to a new page).
await _router.pushAndPopUntil(
const LoginRoute(),
predicate: (_) => false,
)
Add this package :
dependencies:
flutter_phoenix: ^1.1.0
Example:
void main() {
runApp(
Phoenix(
child: App(),
),
);
}
Phoenix.rebirth(context);
Phoenix restarts your application at the application level, rebuilding your application widget tree from scratch, losing any previous state.
Phoenix does not fully restart your application process at the OS level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With