Commit Graph

12 Commits

Author SHA1 Message Date
Sigurd Meldgaard
b23840d044
Only bundle assets and plugins from transitive closure of dependencies (#160443)
Fixes https://github.com/dart-lang/pub/issues/4486
Fixes https://github.com/dart-lang/pub/issues/4473
Fixes https://github.com/flutter/flutter/issues/79261
Fixes https://github.com/flutter/flutter/issues/160142
Fixes https://github.com/flutter/flutter/issues/155242

Use the new `.dart_tool/package_graph.json` file to compute the
dependency graph. Determining

* which are transitive dependencies of the main app's direct and
dev-dependencies, (not other packages from the workspace)
* which of these are only in the transitive set of the direct
dependencies

Bundles assets from dev_dependencies when running `flutter test`, but
not otherwise.
2025-05-19 15:30:58 +00:00
Ben Konyi
4baf4b4d1c
[ Widget Preview ] Refactor @Preview() detection and code generation (#168307)
This change makes the detection of `@Preview(...)` annotations more
robust by converting the analyzer AST directly to generated code rather
than simply copying and pasting the original source. This allows for
proper handling of the following cases WRT import prefixing:

  - The use of `const`
  - String interpolation
  - Other uses of constant variables in non-trivial contexts
  - Etc.
2025-05-16 19:59:25 +00:00
Ben Konyi
3d0c18b550
[ Widget Preview ] Add typedefs, replace height and width with size (#168063)
Addresses some comments from
[flutter.dev/go/widget-previews-architecture](flutter.dev/go/widget-previews-architecture).
2025-05-05 15:51:14 +00:00
Ben Konyi
3595e7dad0
[ Widget Preview ] Add support for theme and brightness properties on Preview (#167001)
The `theme` parameter of `Preview(...)` allows for developers to provide
a callback that returns a `PreviewThemeData` instance which can contain
theming data for Material and Cupertino widgets in both light and dark
modes. The provided theme data will be injected into the widget tree and
applied to the previewed widget.

The `brightness` parameter allows for developers to specify an initial
brightness setting (e.g., light vs dark mode) for the previewed widget.
If not provided, the current system default is used.

A new button has also been added to each widget preview card that allows
for toggling between light and dark mode for individual previews.

**Demo:**


https://github.com/user-attachments/assets/f0a4a3bc-25d2-49b0-a5f6-9149eccfc1d4

Fixes https://github.com/flutter/flutter/issues/166436
Fixes https://github.com/flutter/flutter/issues/166275
Fixes https://github.com/flutter/flutter/issues/166279
Fixes https://github.com/flutter/flutter/issues/166437
2025-04-15 17:51:40 +00:00
Ben Konyi
ac6ab205b5
Reland "[ Widget Preview ] Add initial support for communications over the Dart Tooling Daemon (DTD) (#166698)" (#166877)
This reverts commit 059326d49d and updates
the `widget-preview` command to always spawn the previewer using a local
canvaskit binary.

Fixes https://github.com/flutter/flutter/issues/166865
2025-04-11 14:55:29 +00:00
auto-submit[bot]
059326d49d
Reverts "[ Widget Preview ] Add initial support for communications over the Dart Tooling Daemon (DTD) (#166698)" (#166866)
<!-- start_original_pr_link -->
Reverts: flutter/flutter#166698
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: jonahwilliams
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: tests are timing out in presubmit
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: bkonyi
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {jyameo}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
This will eventually be used as the main communication channel between
the widget preview scaffold, the Flutter tool, and other developer
tooling (e.g., IDEs).

Fixes #166417
<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
2025-04-09 18:11:18 +00:00
Ben Konyi
30e53b0d9c
[ Widget Preview ] Add initial support for communications over the Dart Tooling Daemon (DTD) (#166698)
This will eventually be used as the main communication channel between
the widget preview scaffold, the Flutter tool, and other developer
tooling (e.g., IDEs).

Fixes #166417
2025-04-08 18:10:50 +00:00
Ben Konyi
3efb8cc359
[ Widget Preview ] Display an error widget when an exception is thrown while defining the widget tree (#166005)
Example exception thrown trying to invoke `Directory.current` in a
widget constructor:


![image](https://github.com/user-attachments/assets/f9038fa0-9e6e-4037-bc33-a304861c6a22)
2025-03-27 18:47:51 +00:00
Ben Konyi
41c427c6de
[ Widget Preview ] Remove WidgetPreview in favor of using annotation properties (#165500)
This change reworks how users define previews in their code, expands the
number of valid 'functions' that can be used to create previews, and
allows for specifying a 'wrapper' function to wrap the previewed widget
with

The `WidgetPreview` class has been removed from the framework, with its
properties being added to the `Preview` annotation class instead to
remove some boilerplate from the preview declaration workflow.

Before:

```dart
@Preview()
List<WidgetPreview> previews() => <WidgetPreview>[
      WidgetPreview(
        name: 'Top-level preview',
        child: Text('Foo'),
      ),
  ];
```

After:

```dart
@Preview(name: 'Top-level preview')
Widget previews() => Text('Foo');
```

Previews can now be defined using top-level functions, constructors and
factories which take no arguments, and static methods within classes:

Examples:

```dart
@Preview(name: 'Top-level preview')
Widget previews() => Text('Foo');

class MyWidget extends StatelessWidget {
  @Preview(name: 'Constructor preview')
  MyWidget.preview();

  @Preview(name: 'Factory preview')
  factory MyWidget.factoryPreview() => MyWidget.preview();

  @Preview(name: 'Static preview')
  static Widget previewStatic() => Text('Static');

  @override
  Widget build(BuildContext context) {
    return Text('MyWidget');
  }
}
```

Users can also provide a `wrapper` function with the signature `Widget
Function(Widget)` to easily wrap previewed widget with shared
bootstrapping logic.

Example:

```dart
Widget testWrapper(Widget child) {
  return Provider<int>.value(
    value: 42,
    child: child,
  );
}

@Preview(name: 'Preview with wrapper', wrapper: testWrapper)
Widget preview() {
  return Text('Attributes');
}
```

Which is effectively the same as:

```dart
@Preview(name: 'Preview with wrapper')
Widget preview() {
  return Provider<int>.value(
    value: 42,
    child: Text('Attributes'),
  );
}
```

Finally, for situations where a `BuildContext` is needed, users can
return a `WidgetBuilder` from their preview function:

```dart
@Preview('Builder preview')
WidgetBuilder builderPreview() {
  return (BuildContext context) {
    // TODO: retrieve state from context.
    return Text('Foo');
  };
}
```
2025-03-22 01:35:36 +00:00
Sigurd Meldgaard
45b21ec3bb
Refactor writing of package config in tests (#163734)
Seems like each test had its own way of doing this.

Extracted from https://github.com/flutter/flutter/pull/160443
2025-02-28 08:51:59 +00:00
Brandon DeRosier
911aa7547e
Remove legacy scenec stuff from flutter_tool (#163569)
o7

Removes the legacy scenec logic from flutter_tool. We removed scenec
from the engine/shipped artifacts long ago. Originally added in
https://github.com/flutter/flutter/pull/118157. This has since been
replaced by
[flutter_scene_importer](https://pub.dev/packages/flutter_scene_importer/versions)!
2025-02-21 17:41:02 +00:00
Ben Konyi
9c7e2c2563
[ Widget Preview ] Move preview_detector_test.dart from general.shard to commands.shard (#163619)
Tests under the `general.shard` have a 2000ms timeout and these tests
write to the real file system and watch directories for changes. This
can be slow on heavily loaded machines and cause flaky failures.
2025-02-19 22:53:35 +00:00