Skip to content

[Widget Previews] Widget inspector hides widgets from user's local project in implementation widgets #8807

Closed

Description

@elliette

Steps to repro:

  1. git clone https://github.com/bkonyi/widget_preview_study
  2. cd widget_preview_study/widget_preview
  3. flutter pub get
  4. cd ../veggieseasons
  5. flutter pub get
  6. open widget_preview_study/veggieseasons in your IDE
  7. add code below to veggie_card.dart
  8. run dart run ../widget_preview/bin/find_previews.dart in IDE terminal
  9. look for VM service URI and copy it
  10. launch devtools from IDE, then paste in VM service URI
  11. open the inspector

Expected: Widgets defined in veggie_card.dart should be considered part of the local project, and shown in the inspector tree when the implementation widgets are hidden
Actual: Widgets defined in veggie_card.dart are considered implementation widgets, and hidden in the inspector tree

Note: This is because we detect the pub root directory to be the preview scaffold, therefore anything outside of the preview scaffold is ignored:

Image

@bkonyi for widget previews, will the preview scaffold always match the path /flutter/app/directory/.dart_tool/preview_scaffold? If so, we could check if the pub root ends with .dart_tool/preview_scaffold and instead set it to be the parent directory of .dart_tool.

import 'package:veggieseasons/data/local_veggie_provider.dart';
import 'package:widget_preview/widget_preview.dart';

@Preview()
List<WidgetPreview> veggieCardPreview() {
  return [
    WidgetPreview(
      name: 'Veggie Card',
      child: VeggieCard(LocalVeggieProvider.veggies.first, false, true),
    ),
  ];
}

Activity

  1. elliette commented on Jan 24, 2025

    @elliette
    MemberAuthor

    From @bkonyi: "The generated project's name isn't stable yet, but I'm using widget_preview_scaffold for now and it'll live under .dart_tool/"

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

    P2important to work on, but not at the top of the work list.devtools-inspector-screen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions