pumpNyWidget method

Future<void> pumpNyWidget(
  1. Widget widget, {
  2. ThemeData? theme,
  3. ThemeData? darkTheme,
  4. ThemeMode themeMode = ThemeMode.light,
  5. Duration? settleTimeout,
  6. bool useSimpleTheme = false,
})

Pump a Nylo widget with proper MaterialApp wrapper and theme support.

This method automatically:

  • Wraps the widget in a MaterialApp
  • Sets up the navigator key for Nylo text extensions
  • Handles Google Fonts gracefully
  • Waits for the widget to settle

Example:

await tester.pumpNyWidget(HomePage());
expect(find.text('Welcome'), findsOneWidget);

Implementation

Future<void> pumpNyWidget(
  Widget widget, {
  ThemeData? theme,
  ThemeData? darkTheme,
  ThemeMode themeMode = ThemeMode.light,
  Duration? settleTimeout,
  bool useSimpleTheme = false,
}) async {
  // Ensure Google Fonts is configured
  NyWidgetTest.configure();

  final effectiveTheme = useSimpleTheme
      ? NyWidgetTest.simpleTestTheme
      : (theme ?? _getDefaultTheme());

  final effectiveDarkTheme = useSimpleTheme
      ? NyWidgetTest.simpleDarkTestTheme
      : (darkTheme ?? _getDefaultDarkTheme());

  await pumpWidget(
    _NyTestWrapper(
      theme: effectiveTheme,
      darkTheme: effectiveDarkTheme,
      themeMode: themeMode,
      child: widget,
    ),
  );

  // Pump frames to allow widget to build
  await pump();
  await pump(const Duration(milliseconds: 100));

  // Try to settle, but don't fail on timeout (fonts may cause issues)
  try {
    await pumpAndSettle(settleTimeout ?? const Duration(seconds: 5));
  } catch (e) {
    // If pumpAndSettle fails (e.g., due to font loading), just pump more frames
    await pump(const Duration(milliseconds: 100));
    await pump(const Duration(milliseconds: 100));
  }
}