pushReplacement<T extends Object?, TO extends Object?> method
Push a replacement page with the given widget directly.
If non-null, result will be used as the result of the route that is removed; the future that had been returned from pushing that old route will complete with result. Routes such as dialogs or popup menus typically use this mechanism to return the value selected by the user to the widget that created their route. The type of result, if provided, must match the type argument of the class of the old route (TO).
// some logic..
await context.pushReplacement(MyPage(), result: await getObjectRequired());
Implementation
Future<T?> pushReplacement<T extends Object?, TO extends Object?>(
Widget page, {
Object? result,
}) => Navigator.of(this).pushReplacement(
MaterialPageRoute(builder: (context) => page),
result: result,
);