navigateTo<T extends Object?> method

Future<T?>? navigateTo<T extends Object?>({
  1. required BuildContext context,
  2. required String routeName,
  3. dynamic options,
})

Navigates to the specified routeName with the given options as arguments.

This method pushes a new route to the navigation stack and returns a Future that completes when the pushed route is popped.

The BuildContext context and the target routeName are required. The options parameter is optional and can be used to pass additional arguments to the target route.

Implementation

Future<T?>? navigateTo<T extends Object?>({
  required BuildContext context,
  required String routeName,
  dynamic options,
}) {
  if (routes[routeName] != null) {
    try {
      return Navigator.push(
        context,
        MaterialPageRoute(
          builder: routes[routeName]!,
          settings: RouteSettings(arguments: {
            'options': options,
          }),
        ),
      );
    } catch (e) {
      TencentCloudChat.instance.logInstance.console(
        componentName: 'Navigator',
        logs: '`$routeName` failed: ${e.toString()}',
        logLevel: TencentCloudChatLogLevel.error,
      );
    }
  } else {
    TencentCloudChat.instance.logInstance.console(
      componentName: 'Navigator',
      logs: '`$routeName` not registered',
      logLevel: TencentCloudChatLogLevel.error,
    );
  }
  return null;
}