Skip to content

FutureBuilder hangs the whole UI even when using an Isolate #30987

@devnoname120

Description

@devnoname120

Steps to Reproduce

  1. Create a complex and nested Widget that takes a significant time to build (~100 widgets, with ~10 nesting levels).
  2. Use an Isolate through the compute function in order to build it:
FutureBuilder(
            future: compute<int, Widget>(
                buildComments, this.storyId),
            builder: (BuildContext context, AsyncSnapshot snapshot) {
              switch (snapshot.connectionState) {
                case ConnectionState.none:
                case ConnectionState.active:
                case ConnectionState.waiting:
                  return LinearProgressIndicator();
                case ConnectionState.done:
                  if (snapshot.hasError) {
                    final ArgumentError myError = snapshot.error;
                    return Text('Error: ${myError.message}');
                  } else {
                    final Widget comments = snapshot.data;

                    return comments;
                  }
              }
            },
          )

Note that the prototype of the function is Future<Widget> buildComments(int storyId) async, so the future should be executed inside the isolate.

  1. The linear progress indicator will hang for a visible amount of time.

More information here: https://stackoverflow.com/q/55632971/3634271

loading_bar_hang
(Sorry for the quality of this GIF but I think that it helps to understand the issue.)

Logs

hacker_news_core.log

C:\Users\noname120\AndroidStudioProjects\hacker_news_core>flutter analyze
Analyzing hacker_news_core...
No issues found! (ran in 3.7s)
Output of `flutter doctor -v`

C:\Users\noname120\AndroidStudioProjects\hacker_news_core>flutter doctor -v
[√] Flutter (Channel master, v1.4.11-pre.34, on Microsoft Windows [Version 10.0.17134.590], locale en-US)
    • Flutter version 1.4.11-pre.34 at C:\flutter
    • Framework revision 0b8403b61c (5 days ago), 2019-04-07 21:29:32 -0700
    • Engine revision ff1bcdc009
    • Dart version 2.2.1 (build 2.2.1-dev.3.0 None)


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\noname120\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 34.0.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] IntelliJ IDEA Ultimate Edition (version 2019.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.1
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[!] VS Code, 64-bit edition (version 1.30.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
    • ZTE A2017G • 16246042 • android-arm64 • Android 7.1.1 (API 25)

! Doctor found issues in 2 categories.

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