Unfortunately, the functionality you are looking for is not provided by GoRouter at this time.
An alternative to using go_router_flow is to implement something simple yourself by passing callbacks as the extra property on GoRouterState.
This dartpad contains a full example, but the gist is that you define your routes similar to:
GoRouter(
initialLocation: "/",
routes: <RouteBase>[
GoRoute(
path: "/second",
builder: (_, state) {
final params = state.extra! as SecondPageParams;
return SecondPage(params: params);
},
),
],
);
And define your SecondPage
similar to:
class SecondPageParams {
final void Function(String data) action;
const SecondPageParams(this.action);
}
class SecondPage extends StatelessWidget {
final SecondPageParams params;
const SecondPage({super.key, required this.params});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: ElevatedButton(
onPressed: () {
context.pop();
params.action("Data from second page");
},
child: const Text("Pop and perform action")
),
),
),
);
}
}
It's not as clean as being able to await
a context.push
, but this is a simple way you can specify the action that you want to take whenever SecondPage
is popped off the stack without having to rely on a different package.