start method

Future<void> start()

Runs the full update flow, showing each dialog in sequence.

Checks for a patch and, if one is available, prompts the user, downloads it, and offers to restart. Does nothing if no navigator is available.

Implementation

Future<void> start() async {
  // Use the navigator's overlay context so `showDialog` always finds a
  // Navigator, regardless of where ShorebirdUpdaterWidget sits in the tree.
  final context = manager.navigatorKey.currentState?.overlay?.context;

  if (context == null || !context.mounted) {
    return;
  }

  _showChecking(context);

  final available = await manager.checkForUpdates();

  if (!context.mounted) return;

  Navigator.of(context, rootNavigator: true).pop();

  if (!available) return;

  final update = await _showUpdateDialog(context);

  if (!update) return;

  _showDownloading(context);

  final downloaded = await manager.downloadUpdate();

  if (!context.mounted) return;

  Navigator.of(context, rootNavigator: true).pop();

  // Only prompt to restart if the patch was actually downloaded and staged.
  if (!downloaded) return;

  _showRestart(context);
}