Repository navigation
Flutter Widget Preview retrying forever #6017
Copy link
Copy link
Closed
Labels
fixed in dart / flutterrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become availableSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
Milestone
Description
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."}}]
Expected behavior
For the extension to give up and show the log file.
Screenshots
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!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
fixed in dart / flutterrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become availableSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
Activity
DanTup commentedon Apr 16, 2026
My plan was to interrupt the spinner if we got an
errorlogMessagefrom the widget preview, however I see there are lots of errors being reported that I don't think are necessary fatal: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:
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)?bkonyi commentedon Apr 16, 2026
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.startedto 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?DanTup commentedon Apr 16, 2026
The one in the original log above did not:
It was failing in a way that prevented the
widget_preview.startedevent from occurring, but otherwise still seemed to be alive.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 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
erroris 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.startedis never going to come) occurs, but I don't know how reliably you know that from the widget previewer.DanTup commentedon Apr 17, 2026
@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
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.
bkonyi commentedon Apr 17, 2026
That doesn't seem great. If we fail, we should exit.
I think this is because most of the places we call
logger.printErrorwe don't actually include a stack trace (we probably should).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.
DanTup commentedon Apr 20, 2026
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).
DanTup commentedon Apr 20, 2026
I changed the implementation of
printErrorto useStackTrace.currentwhen no stack trace was provided, and the stack trace that came up was: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.
DanTup commentedon Jul 7, 2026
@FMorschel FYI, Ben landed a fix in flutter/flutter#188921 so hopefully if you're still been hitting this it'll be gone soon :-)