visit method

Future<void> visit(
  1. RouteView route, {
  2. ThemeData? theme,
  3. ThemeData? darkTheme,
  4. ThemeMode themeMode = ThemeMode.light,
})

Pump a route with full Nylo navigation support.

Sets up a MaterialApp with the NyRouter's route generator, navigator key, and route history observer so that navigation via routeTo works correctly in tests.

Example:

await tester.visit(DashboardPage.path);
await tester.tap(find.byType(MyButton));
tester.assertNavigatedTo(ProfilePage.path);

Implementation

Future<void> visit(
  RouteView route, {
  ThemeData? theme,
  ThemeData? darkTheme,
  ThemeMode themeMode = ThemeMode.light,
}) async {
  final effectiveTheme = theme ?? _getDefaultTheme();
  final effectiveDarkTheme = darkTheme ?? _getDefaultDarkTheme();

  await pumpWidget(
    MaterialApp(
      navigatorKey: NyNavigator.instance.router.navigatorKey,
      navigatorObservers: [NyRouteHistoryObserver()],
      initialRoute: route.$1,
      onGenerateRoute: NyNavigator.instance.router.generator(),
      theme: effectiveTheme,
      darkTheme: effectiveDarkTheme,
      themeMode: themeMode,
      debugShowCheckedModeBanner: false,
    ),
  );

  await pump();
  await pump(const Duration(milliseconds: 100));

  try {
    await pumpAndSettle(const Duration(seconds: 5));
  } catch (e) {
    await pump(const Duration(milliseconds: 100));
    await pump(const Duration(milliseconds: 100));
  }
}