Steps to reproduce
- Create a Pub Workspace whose root is a Dart package and whose Flutter package is included with a workspace glob (minimal files are in the Code sample below).
- Run
flutter pub get at the workspace root.
- Put an
@Preview declaration under packages/ui_components/lib/.
- Open the workspace root in VS Code 1.109.5 with Dart-Code and Flutter extensions 3.140.0.
- Open the preview Dart file and select the Flutter Widget Preview sidebar.
- The IDE starts the preview server from the workspace root and reports:
Flutter Widget Preview server process terminated.
The same failure is reproducible without VS Code by running this at the workspace root:
flutter widget-preview start --web-server
Running the command from packages/ui_components succeeds.
This appears related to Pub Workspace support added in Dart-Code#5775, but occurs on versions that already include that fix.
Expected results
The Widget Preview server should resolve and render previews declared in any Flutter package belonging to the Pub Workspace when the workspace root is opened in VS Code.
The Flutter documentation states that the IDE previewer supports previews contained within a single Pub Workspace, and Dart-Code 3.124 release notes state that previews work for all projects within a Pub Workspace.
Actual results
The generated Widget Preview Scaffold is created outside the Pub Workspace and cannot resolve the workspace member package. Its generated file imports the preview using package:ui_components/..., but ui_components is missing from the scaffold's package resolution.
VS Code only reports:
Flutter Widget Preview: Widget Preview server process terminated
Starting from the workspace root fails, while starting from the member package directory succeeds. Adding every preview package as a direct path dependency of the workspace root works around the issue, but requires duplicating Workspace membership in dependencies and should not be necessary.
Code sample
Code sample
Workspace layout:
preview_workspace/
pubspec.yaml
packages/
ui_components/
pubspec.yaml
lib/example.preview.dart
Root pubspec.yaml:
name: preview_workspace
publish_to: none
environment:
sdk: ^3.12.0
workspace:
- packages/*
dev_dependencies:
flutter_lints: ^6.0.0
packages/ui_components/pubspec.yaml:
name: ui_components
publish_to: none
version: 1.0.0
environment:
sdk: ^3.12.0
flutter: ">=3.44.0"
resolution: workspace
dependencies:
flutter:
sdk: flutter
flutter:
uses-material-design: true
packages/ui_components/lib/example.preview.dart:
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';
@Preview(name: 'Example')
Widget examplePreview() => const MaterialApp(
home: Scaffold(body: Center(child: Text('Preview'))),
);
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
$ flutter widget-preview start --web-server
Creating widget preview scaffolding at: /tmp/flutter_tools.../widget_preview_scaffold...
Launching analysis server...
Connecting to DTD
Connected to DTD
Launching the Widget Preview Scaffold on Web Server...
Launching lib/main.dart on Web Server in debug mode...
Error: Couldn't resolve the package 'ui_components' in 'package:ui_components/example.preview.dart'.
.../widget_preview_scaffold.../lib/src/generated_preview.dart:5:8: Error: Not found: 'package:ui_components/example.preview.dart'
import 'package:ui_components/example.preview.dart';
^
.../lib/src/generated_preview.dart: Error: Method not found: 'examplePreview'.
The Dart compiler exited unexpectedly.
Failed to compile application.
The actual project produces the same error with the longer path package:ui_components/src/templates/feature_placeholder_page.preview.dart.
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.44.8, on macOS 26.5.2 25F84 darwin-arm64, locale en-CN)
• Flutter version 3.44.8 on channel stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 058e0af2c2, 2026-07-23
• Engine revision 0cd610717b
• Dart version 3.12.2
• DevTools version 2.57.0
• Feature flags: enable-web, enable-macos-desktop, enable-android, enable-ios,
enable-native-assets, enable-swift-package-manager
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0)
• Java version OpenJDK Runtime Environment Homebrew (build 17.0.20+0)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 26.6)
• Build 17F113
! CocoaPods not globally installed (project uses Bundler; unrelated to this Web preview issue).
[✓] Chrome - develop for the web
• Google Chrome 151.0.7922.76
[✓] Connected device
• macOS (desktop) • darwin-arm64
• Chrome (web) • web-javascript
[✓] Network resources
! Doctor found issues in 1 category.
VS Code: 1.109.5
Dart-Code: 3.140.0
Flutter extension: 3.140.0
Steps to reproduce
flutter pub getat the workspace root.@Previewdeclaration underpackages/ui_components/lib/.Flutter Widget Preview server process terminated.The same failure is reproducible without VS Code by running this at the workspace root:
flutter widget-preview start --web-serverRunning the command from
packages/ui_componentssucceeds.This appears related to Pub Workspace support added in Dart-Code#5775, but occurs on versions that already include that fix.
Expected results
The Widget Preview server should resolve and render previews declared in any Flutter package belonging to the Pub Workspace when the workspace root is opened in VS Code.
The Flutter documentation states that the IDE previewer supports previews contained within a single Pub Workspace, and Dart-Code 3.124 release notes state that previews work for all projects within a Pub Workspace.
Actual results
The generated Widget Preview Scaffold is created outside the Pub Workspace and cannot resolve the workspace member package. Its generated file imports the preview using
package:ui_components/..., butui_componentsis missing from the scaffold's package resolution.VS Code only reports:
Starting from the workspace root fails, while starting from the member package directory succeeds. Adding every preview package as a direct
pathdependency of the workspace root works around the issue, but requires duplicating Workspace membership in dependencies and should not be necessary.Code sample
Code sample
Workspace layout:
Root
pubspec.yaml:packages/ui_components/pubspec.yaml:packages/ui_components/lib/example.preview.dart:Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
The actual project produces the same error with the longer path
package:ui_components/src/templates/feature_placeholder_page.preview.dart.Flutter Doctor output
Doctor output