toAndExpectData method

Future<T?> toAndExpectData(
  1. String routeName, {
  2. Map<String, dynamic>? args,
})

Navigates to the specified route and expects to receive data back.

routeName is the name of the route to navigate to. args are the optional arguments to pass to the route. Returns a Future that completes with the data received from the route.

Implementation

Future<T?> toAndExpectData(String routeName,
    {Map<String, dynamic>? args}) async {
  try {
    if (context != null) {
      return await Navigator.pushNamed(context!, routeName, arguments: args);
    } else if (navigatorKey != null) {
      return await navigatorKey!.currentState!
          .pushNamed(routeName, arguments: args);
    }
  } catch (e) {
    print('Error in toAndExpectData: $e');
    return null;
  }
  return null;
}