runWatchedWidgetApp function

Future<void> runWatchedWidgetApp(
  1. ReloadWidgetBuilder builder, {
  2. required Iterable<String> watchRoots,
  3. ReloadController? controller,
  4. ReloadMode watchMode = ReloadMode.reload,
  5. Duration watchDebounce = const Duration(milliseconds: 150),
  6. bool watchRecursive = true,
  7. bool watchIgnoreHidden = true,
  8. Iterable<String> watchExtensions = const <String>['.dart'],
  9. ProgramOptions? options,
  10. ProgramHost? host,
  11. ImageAutoMode? imageAutoMode,
})

Runs a reloadable WidgetApp and watches filesystem roots for changes.

This is a convenience wrapper around ReloadController, ReloadHost, and ReloadFileWatcher for local development loops.

Implementation

Future<void> runWatchedWidgetApp(
  ReloadWidgetBuilder builder, {
  required Iterable<String> watchRoots,
  ReloadController? controller,
  ReloadMode watchMode = ReloadMode.reload,
  Duration watchDebounce = const Duration(milliseconds: 150),
  bool watchRecursive = true,
  bool watchIgnoreHidden = true,
  Iterable<String> watchExtensions = const <String>['.dart'],
  runtime.ProgramOptions? options,
  hosts.ProgramHost? host,
  ImageAutoMode? imageAutoMode,
}) async {
  final reloadController = controller ?? ReloadController();
  final ownsController = controller == null;
  final watcher = await ReloadFileWatcher.watch(
    controller: reloadController,
    roots: watchRoots,
    mode: watchMode,
    debounce: watchDebounce,
    recursive: watchRecursive,
    ignoreHidden: watchIgnoreHidden,
    extensions: watchExtensions,
  );

  try {
    await runReloadableWidgetApp(
      builder,
      controller: reloadController,
      options: options,
      host: host,
      imageAutoMode: imageAutoMode,
    );
  } finally {
    await watcher.dispose();
    if (ownsController) {
      await reloadController.dispose();
    }
  }
}