Skip to content

Flutter Widget Preview retrying forever #6017

Closed

Description

@FMorschel

Describe the bug
Flutter Widget Preview is retrying forever when problem occurs.

To Reproduce
Steps to reproduce the behavior:
I'm not sure how to repro in any machine yet, but I' getting:

Dart Code extension: 3.131.20260324
Flutter extension: 3.131.20260303 (activated)

App: Visual Studio Code
App Host: desktop
Version: win 1.113.0


Logging Categories:
    FlutterWidgetPreview

Mon Mar 30 2026 [14:19:45 GMT-0300 (Horário Padrão de Brasília)] Log file started
[14:20:09] <== [{"event":"widget_preview.initializing","params":{"pid":2604}}]
[14:20:09] <== [{"event":"widget_preview.logMessage","params":{"level":"warning","message":"Invalid Widget Preview Scaffold manifest at C:\\TMP\\flutter_tools.6e737b4c\\widget_preview_scaffold4a9cbc58\\preview_manifest.json. Regenerating Widget Preview Scaffold."}}]
[14:20:09] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Creating widget preview scaffolding at: C:\\TMP\\flutter_tools.6e737b4c\\widget_preview_scaffold4a9cbc58"}}]
[14:20:10] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Creating the Widget Preview Scaffold manifest at C:\\TMP\\flutter_tools.6e737b4c\\widget_preview_scaffold4a9cbc58\\preview_manifest.json"}}]
[14:20:12] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Finding previews in C:\\Fontes\\_local\\Flutter\\new_project..."}}]
[14:20:31] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Found 18 previews."}}]
[14:20:31] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Launching the Widget Preview Scaffold on Web Server..."}}]
[14:20:31] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Launching lib\\main.dart on Web Server in debug mode..."}}]
[14:20:34] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Waiting for connection from debug service on Web Server..."}}]
[14:20:34] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Error: SDK root directory not found: /C:/Users/felipe-m/.puro/envs/stable/flutter/bin/cache/flutter_web_sdk/."}}]
[14:20:59] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Failed to compile application."}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Detected change in C:\\Fontes\\_local\\Flutter\\new_project\\test\\widgets\\multi_options_input_widget_test.dart."}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Finding previews in C:\\Fontes\\_local\\Flutter\\new_project\\test\\widgets\\multi_options_input_widget_test.dart..."}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Found 0 previews."}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Updated previews for file:///C:/Fontes/_local/Flutter/new_project/test/widgets/multi_options_input_widget_test.dart: []"}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Triggering reload based on change to preview set: {(path: C:\\Fontes\\_local\\Flutter\\new_project\\lib\\main.dart, uri: package:new_project/main.dart): (<snip>
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Performing hot reload..."}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Waiting for connection from debug service on Web Server..."}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
[14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Error: SDK root directory not found: /C:/Users/felipe-m/.puro/envs/stable/flutter/bin/cache/flutter_web_sdk/."}}]
[14:21:13] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Detected change in C:\\Fontes\\_local\\Flutter\\new_project\\test\\widgets\\multi_options_input_widget_test.dart."}}]
[14:21:13] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Finding previews in C:\\Fontes\\_local\\Flutter\\new_project\\test\\widgets\\multi_options_input_widget_test.dart..."}}]
[14:21:13] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Found 0 previews."}}]

flutterWidgetPreview.log

Expected behavior
For the extension to give up and show the log file.

Screenshots

Image

Please complete the following information:

Workspace Environment
Dart Code extension: 3.131.20260324
Flutter extension: 3.131.20260303 (activated)

App: Visual Studio Code
App Host: desktop
Version: win 1.113.0

Workspace type: Flutter (LSP)
Workspace name: new_project

Dart (3.11.3): C:\Users\felipe-m\.puro\shared\caches\052f31d115eceda8cbff1b3481fcde4330c4ae12\dart-sdk
Flutter (3.41.5): C:\Users\felipe-m\.puro\envs\stable\flutter (No device)

Output from 'dart info'

C:\Users\felipe-m\.puro\shared\caches\052f31d115eceda8cbff1b3481fcde4330c4ae12\dart-sdk\bin\dart.exe info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

General info

  • Dart 3.11.3 (stable) (Tue Mar 17 01:06:16 2026 -0700) on "windows_x64"
  • on windows / "Windows 11 Pro" 10.0 (Build 26200)
  • locale is pt-BR

Project info

  • sdk constraint: '^3.10.8'
  • dependencies: flutter, json_annotation, path, path_provider
  • dev_dependencies: build_runner, flutter_test, json_serializable

Process info

Memory CPU Elapsed time Command line
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dartvm.exe
0 MB -- dartvm.exe
0 MB -- dartvm.exe
0 MB -- dartvm.exe
0 MB -- dartvm.exe
0 MB -- dartvm.exe
Output from 'flutter doctor'

C:\Users\felipe-m\.puro\envs\stable\flutter\bin\flutter.bat doctor -v

[√] Flutter (Channel stable, 3.41.5, on Microsoft Windows [versão 10.0.26200.8037], locale pt-BR) [1.363ms]
    • Flutter version 3.41.5 on channel stable at C:\Users\felipe-m\.puro\envs\stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2c9eb20739 (13 days ago), 2026-03-17 16:14:01 -0700
    • Engine revision 052f31d115
    • Dart version 3.11.3
    • DevTools version 2.54.2
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[√] Windows Version (Windows 11 or higher, 25H2, 2009) [1.522ms]

[√] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [3,4s]
    • Android SDK at C:\AndroidStudioSdk
    • Emulator version 36.4.10.0 (build_id 15004761) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • ANDROID_HOME = C:\AndroidStudioSdk
    • Java binary at: C:\RECH\zulu17.0.18\x64\bin\java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Zulu17.64+17-CA (build 17.0.18+8-LTS)
    • All Android licenses accepted.

[√] Chrome - develop for the web [154ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.4.2) [152ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\18\Community
    • Visual Studio Community 2026 version 18.4.11620.152
    • Windows 10 SDK version 10.0.26100.0

[√] Connected device (4 available) [557ms]
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 16 (API 36) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [versão 10.0.26200.8037]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 146.0.7680.165
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 146.0.3856.84

[√] Network resources [474ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. added this to the v3.134.0 milestone on Apr 14, 2026
  2. DanTup commented on Apr 16, 2026

    @DanTup
    Member

    My plan was to interrupt the spinner if we got an error logMessage from the widget preview, however I see there are lots of errors being reported that I don't think are necessary fatal:

    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.app.webLaunchUrl","params":{"url":"http://localhost:63349","launched":false}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.started","params":{"url":"http://localhost:63349"}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
    [12:43:13 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Null check operator used on a null value"}}]
    [12:43:18 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Debug service listening on ws://127.0.0.1:59738/EiU0bqabt94=/ws"}}]
    [12:43:18 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"A Dart VM Service on Web Server is available at: http://127.0.0.1:59738/EiU0bqabt94="}}]
    [12:43:18 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"The Flutter DevTools debugger and profiler on Web Server is available at: http://127.0.0.1:9101?uri=ws://127.0.0.1:59738/EiU0bqabt94=/ws"}}]
    [12:43:18 PM] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Done loading previews."}}]
    

    Therefore I don't think we can reliably tell the difference between "normal" errors and fatal errors that cause the widget preview to never become available (such as the one in flutter/flutter#184389 (comment)). While we could put some kind of timeout, that doesn't work well if the machien is legitimately running slowly.

    @bkonyi do you think there's a way we can handle fatal errors like this:

    [14:20:34] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Error: SDK root directory not found: /C:/Users/felipe-m/.puro/envs/stable/flutter/bin/cache/flutter_web_sdk/."}}]
    [14:20:59] [FlutterWidgetPreview] [Info] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Failed to compile application."}}]
    

    From other kinds of errors, so that Dart-Code could provide better feedback to the user (instead of an infinite spinner waiting for widget_preview.started)?

  3. bkonyi commented on Apr 16, 2026

    @bkonyi

    Will a fatal error not just result in the widget previewer crashing?

    Also, do we have any more context around when those null assertions are happening? We shouldn't be seeing any of those from the widget previewer.

    We could try to add some additional events before widget_preview.started to indicate where we are in the launch process, and try and add some try-catch blocks to better isolate where exceptions are coming from. That way we'd at least know how much progress had been made during the startup process, even if we can't report a better error for some reason. WDYT?

  4. DanTup commented on Apr 16, 2026

    @DanTup
    Member

    Will a fatal error not just result in the widget previewer crashing?

    The one in the original log above did not:

    [14:20:31] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Found 18 previews."}}]
    [14:20:31] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Launching the Widget Preview Scaffold on Web Server..."}}]
    [14:20:31] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Launching lib\\main.dart on Web Server in debug mode..."}}]
    [14:20:34] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Waiting for connection from debug service on Web Server..."}}]
    [14:20:34] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Error: SDK root directory not found: /C:/Users/felipe-m/.puro/envs/stable/flutter/bin/cache/flutter_web_sdk/."}}]
    [14:20:59] <== [{"event":"widget_preview.logMessage","params":{"level":"error","message":"Failed to compile application."}}]
    [14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Detected change in C:\\Fontes\\_local\\Flutter\\new_project\\test\\widgets\\multi_options_input_widget_test.dart."}}]
    [14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Finding previews in C:\\Fontes\\_local\\Flutter\\new_project\\test\\widgets\\multi_options_input_widget_test.dart..."}}]
    [14:21:08] <== [{"event":"widget_preview.logMessage","params":{"level":"status","message":"Found 0 previews."}}]
    

    It was failing in a way that prevented the widget_preview.started event from occurring, but otherwise still seemed to be alive.

    Also, do we have any more context around when those null assertions are happening?

    No, there's no stack or anything. I had assumed they were coming form my test app, however I do see the same in @FMorschel's original log, so maybe not. Perhaps we're dropping the stack trace somewhere where these errors are routed to the log events?

    We could try to add some additional events before widget_preview.started to indicate where we are in the launch process, and try and add some try-catch blocks to better isolate where exceptions are coming from.

    I did originally think I can just handle any errors that arrive before that event, but from the errors in the logs above, I'm not sure it's guaranteed that an error is fatal, and I don't want to show "Widget Preview failed to start" and then actually we did start up (and I don't want to use a timeout, because it's hard to know what is a good value).

    I think the best outcome would be if we knew a fatal error (that means widget_preview.started is never going to come) occurs, but I don't know how reliably you know that from the widget previewer.

  5. DanTup commented on Apr 17, 2026

    @DanTup
    Member

    @bkonyi I don't know if it's related, but I'm looking through the bot failures in the Pub package roll PR (flutter/flutter#185172) and I see this:

    logs: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8684332614556134609/+/u/run_test.dart_for_tool_tests_shard_and_subshard_general/stdout?format=raw

    00:28 +1754 -1: test/general.shard/resident_runner_test.dart: ResidentRunner will alternative the name of the dill file uploaded for a hot restart [E]
      Null check operator used on a null value
      package:flutter_tools/src/run_hot.dart 701:65       HotRunner._restartFromSources
      ===== asynchronous gap ===========================
      package:flutter_tools/src/run_hot.dart 860:16       HotRunner._fullRestartHelper
      ===== asynchronous gap ===========================
      package:flutter_tools/src/run_hot.dart 800:38       HotRunner.restart
      ===== asynchronous gap ===========================
      test/general.shard/resident_runner_test.dart 951:7  main.<fn>.<fn>
      ===== asynchronous gap ===========================
      test/src/testbed.dart 155:13                        TestBed.run.<fn>.<fn>.<fn>
      ===== asynchronous gap ===========================
      package:flutter_tools/src/base/context.dart 154:19  AppContext.run.<fn>
      ===== asynchronous gap ===========================
      package:flutter_tools/src/base/context.dart 154:19  AppContext.run.<fn>
      ===== asynchronous gap ===========================
      test/src/context.dart 151:32                        testUsingContext.<fn>.<fn>.<fn>.<fn>.<fn>
      ===== asynchronous gap ===========================
      package:flutter_tools/src/base/context.dart 154:19  AppContext.run.<fn>
      ===== asynchronous gap ===========================
      test/src/context.dart 140:28                        testUsingContext.<fn>.<fn>.<fn>.<fn>
    

    I wonder if this is the same issue showing up in the logs here?

    I don't know if it's intermittent though - if it was the cause of this, it wouldn't be caused by the pub roll.

  6. bkonyi commented on Apr 17, 2026

    @bkonyi

    It was failing in a way that prevented the widget_preview.started event from occurring, but otherwise still seemed to be alive.

    That doesn't seem great. If we fail, we should exit.

    Also, do we have any more context around when those null assertions are happening?

    No, there's no stack or anything. I had assumed they were coming form my test app, however I do see the same in @FMorschel's original log, so maybe not. Perhaps we're dropping the stack trace somewhere where these errors are routed to the log events?

    I think this is because most of the places we call logger.printError we don't actually include a stack trace (we probably should).

    I did originally think I can just handle any errors that arrive before that event, but from the errors in the logs above, I'm not sure it's guaranteed that an error is fatal, and I don't want to show "Widget Preview failed to start" and then actually we did start up (and I don't want to use a timeout, because it's hard to know what is a good value).

    I think the best outcome would be if we knew a fatal error (that means widget_preview.started is never going to come) occurs, but I don't know how reliably you know that from the widget previewer.

    We can for sure give some indication that we're possibly stuck if we give some progress indicators, but if we're in a situation where we've encountered a fatal error and we're not crashing already, that's something we probably won't be able to detect. Can you file an issue on flutter/flutter and assign it to me? This seems like a bug that should be investigated further.

  7. DanTup commented on Apr 20, 2026

    @DanTup
    Member

    Can you file an issue on flutter/flutter and assign it to me? This seems like a bug that should be investigated further.

    I've opened flutter/flutter#185273

    I'll see if I can repro the other error again now and get a proper stack trace, and I'll file that.

    (Closing this one in favour of flutter/flutter#185273 because I think that's the real fix for this).

  8. removed this from the v3.134.0 milestone on Apr 20, 2026
  9. added and removed
    in flutterRelates to running Flutter apps
    on Apr 20, 2026
  10. DanTup commented on Apr 20, 2026

    @DanTup
    Member

    I think this is because most of the places we call logger.printError we don't actually include a stack trace (we probably should).

    I changed the implementation of printError to use StackTrace.current when no stack trace was provided, and the stack trace that came up was:

    #0      WidgetPreviewMachineAwareLogger.printError (package:flutter_tools/src/commands/widget_preview.dart:672:31)
    #1      StdoutHandler.handler (package:flutter_tools/src/compile.dart:150:17)
    

    This code looks like it's parsing the message out of stdout, so I don't know how easily a stack trace is available.

    FWIW, when trying to repro, I struggled at first, and think it might be related to whether I have an active file when I switch to the preview. When I did, I didn't see the error, but if I have no open files in VS Code and then trigger the server, it seems like I get this error. It may or may not be coincidence. Let me know if you want an issue for this.

  11. DanTup commented on Jul 7, 2026

    @DanTup
    Member

    @FMorschel FYI, Ben landed a fix in flutter/flutter#188921 so hopefully if you're still been hitting this it'll be gone soon :-)

  12. added this to the v3.140.0 milestone on Jul 7, 2026
  13. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    and removed on Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in dart / flutterrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions