Skip to content

[web] Can't run a Flutter web app when there are async operations before runApp/runZoned #50977

@jorgecoca

Description

@jorgecoca

Steps to Reproduce

This code does not work (leaves a white empty screen on the browser, and there are no errors reported or anything):

Future<void> main() => runMyApp();

Future<void> runMyApp() async {
  final authenticationRepository = await AuthenticationRepository.create();
  await runZoned(
    () async => runApp(
      MaterialApp(home: Text('hey 2')),
    ),
  );
}

However, this code works:

Future<void> main() => runMyApp();

Future<void> runMyApp() async {
  await runZoned(
    () async => runApp(
      MaterialApp(home: Text('hey 2')),
    ),
  );
}

Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v1.14.6, on Mac OS X 10.15.3 19D76, locale en-US)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.42.1)
[✓] Connected device (3 available)

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions