Skip to content

[Widget Preview] Pub Workspace preview fails to resolve a member package when started from the workspace root #190692

Closed

Description

@sugarwyc

Steps to reproduce

  1. 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).
  2. Run flutter pub get at the workspace root.
  3. Put an @Preview declaration under packages/ui_components/lib/.
  4. Open the workspace root in VS Code 1.109.5 with Dart-Code and Flutter extensions 3.140.0.
  5. Open the preview Dart file and select the Flutter Widget Preview sidebar.
  6. 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

Activity

  1. suryaKommana2662 commented on Aug 7, 2026

    @suryaKommana2662
    Contributor

    @sugarwyc Thanks for the report. I was able to reproduce this issue on the latest stable Flutter (3.44.8). Running flutter widget-preview start --web-server from the workspace root failed with:

    Error: Couldn't resolve the package 'ui_components' in 'package:ui_components/example.preview.dart'.

    which resulted in the Widget Preview scaffold failing to compile. This matches the behavior described in the report. Routing to team-tool for further investigation.

    Flutter Doctor Output

    [✓] Flutter (Channel stable, 3.44.8, on macOS 26.4 25E246 darwin-arm64, locale en-IN) [654ms]
        • Flutter version 3.44.8 on channel stable at /Users/suryakommana/develop/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 058e0af2c2 (2 weeks ago), 2026-07-23 10:56:21 -0700
        • Engine revision 0cd610717b
        • Dart version 3.12.2
        • DevTools version 2.57.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets,
          enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,851ms]
        • Android SDK at /Users/suryakommana/Library/Android/sdk
        • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
        • Platform android-37.0, build-tools 36.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/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"`.
        • Java version OpenJDK Runtime Environment (build 25.0.2+-15348964-b329.117)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.6) [1,654ms]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 17F113
        • CocoaPods version 1.17.0
    
    [✓] Chrome - develop for the web [4ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (3 available) [5.7s]
        • iPhone 17 (mobile) • E354ECD5-7984-44E0-9C38-082B39E72C88 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-26-5 (simulator)
        • macOS (desktop)    • macos                                • darwin-arm64   • macOS 26.4 25E246 darwin-arm64
        • Chrome (web)       • chrome                               • web-javascript • Google Chrome 151.0.7922.77
    
    [✓] Network resources [482ms]
        • All expected network resources are available.
    
    • No issues found!
  2. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Aug 7, 2026
  3. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Aug 11, 2026
  4. self-assigned this
    on Aug 20, 2026
  5. github-actions commented on Sep 7, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions