pumpWidget method

Future<void> pumpWidget(
  1. Widget widget, {
  2. bool scanZones = false,
  3. bool useHitTesting = true,
  4. bool debugOverlay = false,
  5. DebugOverlayPosition? debugOverlayPosition,
  6. int? width,
  7. int? height,
})

Mounts widget in a WidgetApp wrapped by a Program and performs the initial render.

This is the TUI equivalent of Flutter's tester.pumpWidget(widget). It is async because the Program requires async initialisation.

Implementation

Future<void> pumpWidget(
  Widget widget, {
  bool scanZones = false,
  bool useHitTesting = true,
  bool debugOverlay = false,
  DebugOverlayPosition? debugOverlayPosition,
  int? width,
  int? height,
}) async {
  if (width != null) screenWidth = width;
  if (height != null) screenHeight = height;

  _app = WidgetApp(
    widget,
    scanZones: scanZones,
    useHitTesting: useHitTesting,
    debugOverlay: debugOverlay,
    debugOverlayPosition:
        debugOverlayPosition ?? DebugOverlayPosition.topRight,
  );

  _terminal = _TestTerminal(
    terminalWidth: screenWidth,
    terminalHeight: screenHeight,
  );

  _program = Program<WidgetApp>(
    _app!,
    options: const ProgramOptions(
      altScreen: false,
      hideCursor: false,
      mouse: true,
      disableRenderer: true,
      signalHandlers: false,
      catchPanics: false,
    ),
    terminal: _terminal!,
  );

  // Start the program.  run() is a long-lived future that resolves when
  // the program quits; we keep it around for cleanup.
  _runFuture = _program!.run();

  // Give the async initialisation (_setup + _initialize) a chance to
  // complete.  With the mock terminal this resolves almost immediately.
  await _yieldToEventLoop();

  // Capture the initial view.
  _syncView();
  _pumpCount++;
}