Repository navigation
[ Widget Preview ] @Preview() applications outside of lib/ cause the previewer to crash #178651
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: widget previewsIssues related to the Widget Previewer toolingIssues related to the Widget Previewer toolingc: crashStack traces logged to the consoleStack traces logged to the consoler: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Description
Found 1 preview.
Oops; flutter has exited unexpectedly: "Null check operator used on a null value".
A crash report has been written to
Command
flutter widget-preview startSteps to Reproduce
- ...
- ...
- ...
Logs
_TypeError: (#0 PreviewCodeGenerator._buildPreviews (package:flutter_tools/src/widget_preview/preview_code_generator.dart:167:58))
#0 PreviewCodeGenerator._buildPreviews (package:flutter_tools/src/widget_preview/preview_code_generator.dart:167:58)
#1 PreviewCodeGenerator._buildGeneratedPreviewMethod (package:flutter_tools/src/widget_preview/preview_code_generator.dart:145:13)
#2 PreviewCodeGenerator.populatePreviewsInGeneratedPreviewScaffold.<anonymous closure>.<anonymous closure> (package:flutter_tools/src/widget_preview/preview_code_generator.dart:109:37)
#3 _$MethodBuilder.update (package:code_builder/src/specs/method.g.dart:332:33)
#4 new _$Method (package:code_builder/src/specs/method.g.dart:38:29)
#5 PreviewCodeGenerator.populatePreviewsInGeneratedPreviewScaffold.<anonymous closure> (package:flutter_tools/src/widget_preview/preview_code_generator.dart:108:14)
#6 _$LibraryBuilder.update (package:code_builder/src/specs/library.g.dart:232:33)
#7 new _$Library (package:code_builder/src/specs/library.g.dart:28:30)
#8 PreviewCodeGenerator.populatePreviewsInGeneratedPreviewScaffold (package:flutter_tools/src/widget_preview/preview_code_generator.dart:104:20)
#9 WidgetPreviewStartCommand.runCommand (package:flutter_tools/src/commands/widget_preview.dart:341:27)
<asynchronous suspension>
#10 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1559:27)
<asynchronous suspension>
#11 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
<asynchronous suspension>
#12 CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#13 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:487:9)
<asynchronous suspension>
#14 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
<asynchronous suspension>
#15 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:422:5)
<asynchronous suspension>
#16 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:101:11)
<asynchronous suspension>�[32m[✓]�[39m Flutter (Channel stable, 3.38.1, on Microsoft Windows [Version 10.0.26200.7171], locale en-US) [278ms]
�[32m•�[39m Flutter version 3.38.1 on channel stable at C:\Users\DenivyBraiamRuck\dependencies\flutter
�[32m•�[39m Upstream repository https://github.com/flutter/flutter.git
�[32m•�[39m Framework revision b45fa18946 (4 days ago), 2025-11-12 22:09:06 -0600
�[32m•�[39m Engine revision b5990e5ccc
�[32m•�[39m Dart version 3.10.0
�[32m•�[39m DevTools version 2.51.1
�[32m•�[39m 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
�[32m[✓]�[39m Windows Version (Windows 11 or higher, 25H2, 2009) [1,131ms]
�[32m[✓]�[39m Android toolchain - develop for Android devices (Android SDK version 36.1.0) [2.8s]
�[32m•�[39m Android SDK at C:\Users\DenivyBraiamRuck\AppData\Local\Android\sdk
�[32m•�[39m Emulator version 36.2.12.0 (build_id 14214601) (CL:N/A)
�[32m•�[39m Platform android-36, build-tools 36.1.0
�[32m•�[39m Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
�[32m•�[39m Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
�[32m•�[39m All Android licenses accepted.
�[32m[✓]�[39m Chrome - develop for the web [9ms]
�[32m•�[39m Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
�[31m[✗]�[39m Visual Studio - develop Windows apps [8ms]
�[31m✗�[39m Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
�[32m[✓]�[39m Connected device (4 available) [652ms]
�[32m•�[39m sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
�[32m•�[39m Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26200.7171]
�[32m•�[39m Chrome (web) • chrome • web-javascript • Google Chrome 142.0.7444.163
�[32m•�[39m Edge (web) • edge • web-javascript • Microsoft Edge 142.0.3595.80
�[32m[✓]�[39m Network resources [819ms]
�[32m•�[39m All expected network resources are available.
�[33m!�[39m Doctor found issues in 1 category.
Flutter Application Metadata
Type: malformed
Version: 0.0.1
Material: true
Android X: false
Module: false
Plugin: false
Android package: null
iOS bundle identifier: null
Creation channel: null
Creation framework version: null
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: widget previewsIssues related to the Widget Previewer toolingIssues related to the Widget Previewer toolingc: crashStack traces logged to the consoleStack traces logged to the consoler: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Activity
darshankawar commentedon Nov 18, 2025
@denivyruck Can you provide replication pattern that leads to this crash ? Are you running
flutter cleanbeforeflutter widget-preview start? If that's not the case, the state of the app when this error occurs would be helpful to debug further./cc @bkonyi
tifcty1 commentedon Nov 24, 2025
when I only use a constructor preview widget, it works well. The bug occurs when I add an official sample code as below
and when I run the
flutter clean, I should runflutter pub getbefore I runflutter widget-preview startbkonyi commentedon Nov 24, 2025
What are the symptoms of the bug? Are you running
flutter cleanwhile you have an active instance offlutter widget-preview start?tifcty1 commentedon Nov 25, 2025
"Null check operator used on a null value", same as the creator's issue.
I didn't run commands concurrently.
The steps are:
flutter widget-preview start
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Detected changes in pubspec.yaml. Regenerating pubspec.yaml for the widget preview scaffold.
Finding previews in xxxxxxx...
Found 2 previews.
Oops; flutter has exited unexpectedly: "Null check operator used on a null value".
the stacktrace is the same as this issue
4. flutter clean
5. flutter pub get
6. flutter widget-preview start, same as step 3....
bkonyi commentedon Nov 25, 2025
Would you mind sharing the output of
flutter widget-preview start --verbose? This will include file paths, so you might want to clean up the output to remove any sensitive information. However, it's important that we get a general sense of the structure of the project you're trying to view previews in, so we'll need the logs to still contain those details.tifcty1 commentedon Nov 26, 2025
log
Thanks for reply, I removed just a little sensitive information lines like
hope it not affect the result.
bkonyi commentedon Dec 2, 2025
Thanks for the logs @tifcty1!
I think I see the issue here. Do you have previews defined in these files?
I don't think the previewer correctly handles previews defined outside of the package's
lib/directory (this is definitely a bug). If you do have previews undertest/, try moving them underlib/and see if that resolves the crash for you for now while we investigate fixing this.[-][tool_crash] _TypeError: (#0 PreviewCodeGenerator._buildPreviews (package:flutter_tools/src/widget_preview/preview_code_generator.dart:167:58))[/-][+][ Widget Preview ] `@Preview()` applications outside of `lib/` cause the previewer to crash[/+]tifcty1 commentedon Dec 3, 2025
Yes it is. Thanks~
[ Widget Preview ] Fix crash when `@Preview` annotations appeared out…
[ Widget Preview ] Fix crash when `@Preview` annotations appeared out…
github-actions commentedon Feb 3, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[ Widget Preview ] Fix crash when `@Preview` annotations appeared out…
[ Widget Preview ] Fix crash when `@Preview` annotations appeared out…