toAndExpectData<T> method

Future<T?> toAndExpectData<T>()

Navigates to a named route and expects to receive data back.

If a valid routeName is provided, this method navigates to the specified route and waits for data to be returned. If routeName is null, it returns a default string message.

Returns the result obtained from the navigated route or a default message if routeName is null.

Implementation

Future<T?> toAndExpectData<T>() async {
if (routeName == null) {
  throw Exception('Route name is null. Cannot navigate without a valid route.');
}
return await Navigator.pushNamed(context, routeName!, arguments: arguments?.arguments);
}