pushRouteNameToFramework function
Pushes the routeName
into Flutter's navigation system via a platform
message.
The platform is notified using SystemNavigator.routeInformationUpdated. On older versions of Flutter, this means it will not work unless the application uses a Router (e.g. using MaterialApp.router).
Returns the raw data returned by the framework.
Implementation
// TODO(ianh): Remove the first argument.
Future<ByteData> pushRouteNameToFramework(Object? _, String routeName) {
final Completer<ByteData> completer = Completer<ByteData>();
// TODO(chunhtai): remove this ignore and migrate the code
// https://github.com/flutter/flutter/issues/124045.
// ignore: deprecated_member_use
SystemNavigator.routeInformationUpdated(location: routeName);
final _SendMessage sendMessage = _ambiguate(WidgetsBinding.instance)
?.platformDispatcher
.onPlatformMessage ??
ui.channelBuffers.push;
sendMessage(
'flutter/navigation',
_codec.encodeMethodCall(
MethodCall('pushRouteInformation', <dynamic, dynamic>{
'location': routeName,
'state': null,
}),
),
completer.complete,
);
return completer.future;
}