@bdayadev/flutter-ultra-mcp 1.11.7 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dart/ultra_flutter/pubspec.yaml +1 -1
- package/dart/ultra_flutter_devtools/pubspec.yaml +1 -1
- package/package.json +1 -1
- package/skills/UPSTREAM-LICENSES +75 -0
- package/skills/add-integration-test/SKILL.md +179 -0
- package/skills/add-unit-test/SKILL.md +141 -0
- package/skills/add-widget-preview/SKILL.md +166 -0
- package/skills/add-widget-test/SKILL.md +171 -0
- package/skills/apply-architecture-best-practices/SKILL.md +182 -0
- package/skills/build-cli-app/SKILL.md +200 -0
- package/skills/build-responsive-layout/SKILL.md +160 -0
- package/skills/collect-coverage/SKILL.md +168 -0
- package/skills/fix-layout-issues/SKILL.md +152 -0
- package/skills/fix-runtime-errors/SKILL.md +197 -0
- package/skills/generate-test-mocks/SKILL.md +177 -0
- package/skills/implement-json-serialization/SKILL.md +168 -0
- package/skills/migrate-to-checks-package/SKILL.md +156 -0
- package/skills/resolve-package-conflicts/SKILL.md +140 -0
- package/skills/run-static-analysis/SKILL.md +120 -0
- package/skills/setup-declarative-routing/SKILL.md +293 -0
- package/skills/setup-localization/SKILL.md +247 -0
- package/skills/use-http-package/SKILL.md +189 -0
- package/skills/use-pattern-matching/SKILL.md +169 -0
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
{
|
|
11
11
|
"name": "flutter",
|
|
12
12
|
"description": "Durable cross-platform Flutter automation via 8 specialized MCP servers, in-app mixin binding, and an optional DevTools panel. Replaces marionette_mcp and the official dart mcp-server for Claude Code.",
|
|
13
|
-
"version": "1.
|
|
13
|
+
"version": "1.13.0",
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "Bdaya-Dev",
|
|
16
16
|
"url": "https://github.com/Bdaya-Dev"
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"tags": ["flutter", "dart", "mcp", "testing", "automation", "patrol", "cross-platform"]
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
|
-
"version": "1.
|
|
26
|
+
"version": "1.13.0"
|
|
27
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
3
|
"name": "flutter",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.0",
|
|
5
5
|
"description": "Durable cross-platform Flutter automation via 8 specialized MCP servers, in-app mixin binding, and an optional DevTools panel. Replaces marionette_mcp and the official dart mcp-server for Claude Code.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bdaya-Dev",
|
|
@@ -4,7 +4,7 @@ description: >-
|
|
|
4
4
|
extensions (gesture, screenshot, inspector, screencast, log collection)
|
|
5
5
|
for the flutter-ultra-mcp Claude Code plugin. Composable with Sentry and
|
|
6
6
|
other WidgetsFlutterBinding subclasses via the mixin form.
|
|
7
|
-
version: 1.
|
|
7
|
+
version: 1.13.0
|
|
8
8
|
homepage: https://github.com/Bdaya-Dev/flutter-ultra-mcp
|
|
9
9
|
repository: https://github.com/Bdaya-Dev/flutter-ultra-mcp
|
|
10
10
|
issue_tracker: https://github.com/Bdaya-Dev/flutter-ultra-mcp/issues
|
|
@@ -2,7 +2,7 @@ name: ultra_flutter_devtools
|
|
|
2
2
|
description: >-
|
|
3
3
|
Flutter DevTools extension showing live MCP activity for the flutter-ultra-mcp
|
|
4
4
|
Claude Code plugin (sessions, recent tool calls, errors, screenshot grid).
|
|
5
|
-
version: 1.
|
|
5
|
+
version: 1.13.0
|
|
6
6
|
homepage: https://github.com/Bdaya-Dev/flutter-ultra-mcp
|
|
7
7
|
repository: https://github.com/Bdaya-Dev/flutter-ultra-mcp
|
|
8
8
|
issue_tracker: https://github.com/Bdaya-Dev/flutter-ultra-mcp/issues
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bdayadev/flutter-ultra-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Flutter Ultra MCP plugin monorepo — 8 MCP servers + ultra_flutter Dart packages + skills for Claude Code.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/Bdaya-Dev/flutter-ultra-mcp",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
The following vendored skills are sourced from upstream repositories under
|
|
2
|
+
the BSD 3-Clause License. The flutter-ultra plugin itself is Apache-2.0.
|
|
3
|
+
|
|
4
|
+
================================================================================
|
|
5
|
+
flutter/skills — https://github.com/flutter/skills
|
|
6
|
+
================================================================================
|
|
7
|
+
|
|
8
|
+
Copyright 2026 The Flutter Authors. All rights reserved.
|
|
9
|
+
|
|
10
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
11
|
+
are permitted provided that the following conditions are met:
|
|
12
|
+
|
|
13
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
14
|
+
list of conditions and the following disclaimer.
|
|
15
|
+
|
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
|
18
|
+
and/or other materials provided with the distribution.
|
|
19
|
+
|
|
20
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
21
|
+
may be used to endorse or promote products derived from this software without
|
|
22
|
+
specific prior written permission.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
25
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
26
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
28
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
29
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
30
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
31
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
32
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
33
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
|
+
|
|
35
|
+
Skills vendored:
|
|
36
|
+
add-integration-test, add-widget-preview, add-widget-test,
|
|
37
|
+
apply-architecture-best-practices, build-responsive-layout,
|
|
38
|
+
fix-layout-issues, implement-json-serialization,
|
|
39
|
+
setup-declarative-routing, setup-localization, use-http-package
|
|
40
|
+
|
|
41
|
+
================================================================================
|
|
42
|
+
dart-lang/skills — https://github.com/dart-lang/skills
|
|
43
|
+
================================================================================
|
|
44
|
+
|
|
45
|
+
Copyright 2012, the Dart project authors.
|
|
46
|
+
|
|
47
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
48
|
+
are permitted provided that the following conditions are met:
|
|
49
|
+
|
|
50
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
51
|
+
list of conditions and the following disclaimer.
|
|
52
|
+
|
|
53
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
54
|
+
this list of conditions and the following disclaimer in the documentation
|
|
55
|
+
and/or other materials provided with the distribution.
|
|
56
|
+
|
|
57
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
58
|
+
may be used to endorse or promote products derived from this software without
|
|
59
|
+
specific prior written permission.
|
|
60
|
+
|
|
61
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
62
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
63
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
64
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
65
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
66
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
67
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
68
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
69
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
70
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
71
|
+
|
|
72
|
+
Skills vendored:
|
|
73
|
+
add-unit-test, build-cli-app, collect-coverage, fix-runtime-errors,
|
|
74
|
+
generate-test-mocks, migrate-to-checks-package, resolve-package-conflicts,
|
|
75
|
+
run-static-analysis, use-pattern-matching
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: add-integration-test
|
|
3
|
+
description: Configures Flutter Driver for app interaction and converts MCP actions into permanent integration tests. Use when adding integration testing to a project, exploring UI components via MCP, or automating user flows with the integration_test package.
|
|
4
|
+
last_modified: Tue, 21 Apr 2026 18:29:20 GMT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Implementing Flutter Integration Tests
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- [Project Setup and Dependencies](#project-setup-and-dependencies)
|
|
12
|
+
- [Interactive Exploration via MCP](#interactive-exploration-via-mcp)
|
|
13
|
+
- [Test Authoring Guidelines](#test-authoring-guidelines)
|
|
14
|
+
- [Execution and Profiling](#execution-and-profiling)
|
|
15
|
+
- [Workflow: End-to-End Integration Testing](#workflow-end-to-end-integration-testing)
|
|
16
|
+
- [Examples](#examples)
|
|
17
|
+
|
|
18
|
+
## Project Setup and Dependencies
|
|
19
|
+
|
|
20
|
+
Configure the project to support integration testing and Flutter Driver extensions.
|
|
21
|
+
|
|
22
|
+
1. Add required development dependencies to `pubspec.yaml`:
|
|
23
|
+
```bash
|
|
24
|
+
flutter pub add 'dev:integration_test:{"sdk":"flutter"}'
|
|
25
|
+
flutter pub add 'dev:flutter_test:{"sdk":"flutter"}'
|
|
26
|
+
```
|
|
27
|
+
2. Enable the Flutter Driver extension in your application entry point (typically `lib/main.dart` or a dedicated `lib/main_test.dart`):
|
|
28
|
+
- Import `package:flutter_driver/driver_extension.dart`.
|
|
29
|
+
- Call `enableFlutterDriverExtension();` before `runApp()`.
|
|
30
|
+
3. Add `Key` parameters (e.g., `ValueKey('login_button')`) to critical widgets in the application code to ensure reliable targeting during tests.
|
|
31
|
+
|
|
32
|
+
## Interactive Exploration via MCP
|
|
33
|
+
|
|
34
|
+
Use the Dart/Flutter MCP server tools to interactively explore and manipulate the application state before writing static tests.
|
|
35
|
+
|
|
36
|
+
- **Launch**: Execute `launch_app` with `target: "lib/main_test.dart"` to start the application and acquire the DTD URI.
|
|
37
|
+
- **Inspect**: Execute `get_widget_tree` to discover available `Key`s, `Text` nodes, and widget `Type`s.
|
|
38
|
+
- **Interact**: Execute `tap`, `enter_text`, and `scroll` to simulate user flows.
|
|
39
|
+
- **Wait**: Always execute `waitFor` or verify state with `get_health` when navigating or triggering animations.
|
|
40
|
+
- **Troubleshoot Unmounted Widgets**: If a widget is not found in the tree, it may be lazily loaded in a `SliverList` or `ListView`. Execute `scroll` or `scrollIntoView` to force the widget to mount before interacting with it.
|
|
41
|
+
|
|
42
|
+
## Test Authoring Guidelines
|
|
43
|
+
|
|
44
|
+
Structure integration tests using the `flutter_test` API paradigm.
|
|
45
|
+
|
|
46
|
+
- Create a dedicated `integration_test/` directory at the project root.
|
|
47
|
+
- Name all test files using the `<name>_test.dart` convention.
|
|
48
|
+
- Initialize the binding by calling `IntegrationTestWidgetsFlutterBinding.ensureInitialized();` at the start of `main()`.
|
|
49
|
+
- Load the application UI using `await tester.pumpWidget(MyApp());`.
|
|
50
|
+
- Trigger frames and wait for animations to complete using `await tester.pumpAndSettle();` after interactions like `tester.tap()`.
|
|
51
|
+
- Assert widget visibility using `expect(find.byKey(ValueKey('foo')), findsOneWidget);` or `findsNothing`.
|
|
52
|
+
- Scroll to specific off-screen widgets using `await tester.scrollUntilVisible(itemFinder, 500.0, scrollable: listFinder);`.
|
|
53
|
+
|
|
54
|
+
**Conditional Logic for Legacy `flutter_driver`:**
|
|
55
|
+
|
|
56
|
+
- If maintaining or migrating legacy `flutter_driver` tests, use `driver.waitFor()`, `driver.waitForAbsent()`, `driver.tap()`, and `driver.scroll()` instead of the `WidgetTester` APIs.
|
|
57
|
+
|
|
58
|
+
## Execution and Profiling
|
|
59
|
+
|
|
60
|
+
Execute tests using the `flutter drive` command. Require a host driver script located in `test_driver/integration_test.dart` that calls `integrationDriver()`.
|
|
61
|
+
|
|
62
|
+
**Conditional Execution Targets:**
|
|
63
|
+
|
|
64
|
+
- **If testing on Chrome:** Launch `chromedriver --port=4444` in a separate terminal, then run:
|
|
65
|
+
`flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart -d chrome`
|
|
66
|
+
- **If testing headless web:** Run with `-d web-server`.
|
|
67
|
+
- **If testing on Android (Local):** Run `flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart`.
|
|
68
|
+
- **If testing on Firebase Test Lab (Android):**
|
|
69
|
+
1. Build debug APK: `flutter build apk --debug`
|
|
70
|
+
2. Build test APK: `./gradlew app:assembleAndroidTest`
|
|
71
|
+
3. Upload both APKs to the Firebase Test Lab console.
|
|
72
|
+
|
|
73
|
+
## Workflow: End-to-End Integration Testing
|
|
74
|
+
|
|
75
|
+
Copy and follow this checklist to implement and verify integration tests.
|
|
76
|
+
|
|
77
|
+
- [ ] **Task Progress: Setup**
|
|
78
|
+
- [ ] Add `integration_test` and `flutter_test` to `pubspec.yaml`.
|
|
79
|
+
- [ ] Inject `enableFlutterDriverExtension()` into the app entry point.
|
|
80
|
+
- [ ] Assign `ValueKey`s to target widgets.
|
|
81
|
+
- [ ] **Task Progress: Exploration**
|
|
82
|
+
- [ ] Run `launch_app` via MCP.
|
|
83
|
+
- [ ] Map the widget tree using `get_widget_tree`.
|
|
84
|
+
- [ ] Validate interaction paths using MCP tools (`tap`, `enter_text`).
|
|
85
|
+
- [ ] **Task Progress: Authoring**
|
|
86
|
+
- [ ] Create `integration_test/app_test.dart`.
|
|
87
|
+
- [ ] Write test cases using `WidgetTester` APIs.
|
|
88
|
+
- [ ] Create `test_driver/integration_test.dart` with `integrationDriver()`.
|
|
89
|
+
- [ ] **Task Progress: Execution & Feedback Loop**
|
|
90
|
+
- [ ] Run `flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart`.
|
|
91
|
+
- [ ] **Feedback Loop**: Review test output -> If `PumpAndSettleTimedOutException` occurs, check for infinite animations -> If widget not found, add `scrollUntilVisible` -> Re-run test until passing.
|
|
92
|
+
|
|
93
|
+
## Examples
|
|
94
|
+
|
|
95
|
+
### Standard Integration Test (`integration_test/app_test.dart`)
|
|
96
|
+
|
|
97
|
+
```dart
|
|
98
|
+
import 'package:flutter/material.dart';
|
|
99
|
+
import 'package:flutter_test/flutter_test.dart';
|
|
100
|
+
import 'package:integration_test/integration_test.dart';
|
|
101
|
+
import 'package:my_app/main.dart';
|
|
102
|
+
|
|
103
|
+
void main() {
|
|
104
|
+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
105
|
+
|
|
106
|
+
group('End-to-end test', () {
|
|
107
|
+
testWidgets('tap on the floating action button, verify counter', (tester) async {
|
|
108
|
+
// Load app widget.
|
|
109
|
+
await tester.pumpWidget(const MyApp());
|
|
110
|
+
|
|
111
|
+
// Verify the counter starts at 0.
|
|
112
|
+
expect(find.text('0'), findsOneWidget);
|
|
113
|
+
|
|
114
|
+
// Find the floating action button to tap on.
|
|
115
|
+
final fab = find.byKey(const ValueKey('increment'));
|
|
116
|
+
|
|
117
|
+
// Emulate a tap on the floating action button.
|
|
118
|
+
await tester.tap(fab);
|
|
119
|
+
|
|
120
|
+
// Trigger a frame and wait for animations.
|
|
121
|
+
await tester.pumpAndSettle();
|
|
122
|
+
|
|
123
|
+
// Verify the counter increments by 1.
|
|
124
|
+
expect(find.text('1'), findsOneWidget);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Host Driver Script (`test_driver/integration_test.dart`)
|
|
131
|
+
|
|
132
|
+
```dart
|
|
133
|
+
import 'package:integration_test/integration_test_driver.dart';
|
|
134
|
+
|
|
135
|
+
Future<void> main() => integrationDriver();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Performance Profiling Driver Script (`test_driver/perf_driver.dart`)
|
|
139
|
+
|
|
140
|
+
Use this driver script if you wrap your test actions in `binding.traceAction()` to capture performance metrics.
|
|
141
|
+
|
|
142
|
+
```dart
|
|
143
|
+
import 'package:flutter_driver/flutter_driver.dart' as driver;
|
|
144
|
+
import 'package:integration_test/integration_test_driver.dart';
|
|
145
|
+
|
|
146
|
+
Future<void> main() {
|
|
147
|
+
return integrationDriver(
|
|
148
|
+
responseDataCallback: (data) async {
|
|
149
|
+
if (data != null) {
|
|
150
|
+
final timeline = driver.Timeline.fromJson(
|
|
151
|
+
data['scrolling_timeline'] as Map<String, dynamic>,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
final summary = driver.TimelineSummary.summarize(timeline);
|
|
155
|
+
|
|
156
|
+
await summary.writeTimelineToFile(
|
|
157
|
+
'scrolling_timeline',
|
|
158
|
+
pretty: true,
|
|
159
|
+
includeSummary: true,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Flutter Ultra Integration
|
|
168
|
+
|
|
169
|
+
After writing the integration test, use these tools to launch the app and verify it:
|
|
170
|
+
|
|
171
|
+
- `mcp__plugin_flutter_flutter-ultra-runtime__launch_app` — Launch the app with the integration test target
|
|
172
|
+
- `mcp__plugin_flutter_flutter-ultra-runtime__attach` — Attach to the running app's VM Service
|
|
173
|
+
- `mcp__plugin_flutter_flutter-ultra-runtime__screenshot` — Capture screenshots during test verification
|
|
174
|
+
- `mcp__plugin_flutter_flutter-ultra-runtime__get_widget_tree` — Inspect the widget tree to verify test assertions
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
> **Attribution:** This skill is vendored from [flutter/skills](https://github.com/flutter/skills) (BSD-3-Clause).
|
|
179
|
+
> Synced by `scripts/sync-upstream-skills.mjs`. Do not edit manually — changes will be overwritten on next sync.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: add-unit-test
|
|
3
|
+
description: Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains correct and regression-free.
|
|
4
|
+
last_modified: Fri, 24 Apr 2026 15:07:58 GMT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Testing Dart and Flutter Applications
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- [Structuring Test Files](#structuring-test-files)
|
|
12
|
+
- [Writing Tests](#writing-tests)
|
|
13
|
+
- [Executing Tests](#executing-tests)
|
|
14
|
+
- [Test Implementation Workflow](#test-implementation-workflow)
|
|
15
|
+
- [Examples](#examples)
|
|
16
|
+
|
|
17
|
+
## Structuring Test Files
|
|
18
|
+
|
|
19
|
+
Organize test files to mirror the `lib` directory structure to maintain predictability.
|
|
20
|
+
|
|
21
|
+
- Place all test code within the `test` directory at the root of the package.
|
|
22
|
+
- Append `_test.dart` to the end of all test file names (e.g., `lib/src/utils.dart` should be tested in `test/src/utils_test.dart`).
|
|
23
|
+
- If writing integration tests, place them in an `integration_test` directory at the root of the package.
|
|
24
|
+
|
|
25
|
+
## Writing Tests
|
|
26
|
+
|
|
27
|
+
Utilize `package:test` as the standard testing library for Dart applications.
|
|
28
|
+
|
|
29
|
+
- Import `package:test/test.dart` (or `package:flutter_test/flutter_test.dart` for Flutter).
|
|
30
|
+
- Group related tests using the `group()` function to provide shared context.
|
|
31
|
+
- Define individual test cases using the `test()` function.
|
|
32
|
+
- Validate outcomes using the `expect()` function alongside matchers (e.g., `equals()`, `isTrue`, `throwsA()`).
|
|
33
|
+
- Write asynchronous tests using standard `async`/`await` syntax. The test runner automatically waits for the `Future` to complete.
|
|
34
|
+
- Manage test setup and teardown using `setUp()` and `tearDown()` callbacks.
|
|
35
|
+
- If testing code that relies on dependency injection, use `package:mockito` alongside `package:test` to generate mock objects, configure fixed scenarios, and verify interactions.
|
|
36
|
+
|
|
37
|
+
## Executing Tests
|
|
38
|
+
|
|
39
|
+
Select the appropriate test runner based on the project type and test location.
|
|
40
|
+
|
|
41
|
+
- If working on a pure Dart project, execute tests using the `dart test` command.
|
|
42
|
+
- If working on a Flutter project, execute tests using the `flutter test` command.
|
|
43
|
+
- If running integration tests, explicitly specify the directory path, as the default runner ignores it: `dart test integration_test` or `flutter test integration_test`.
|
|
44
|
+
|
|
45
|
+
## Test Implementation Workflow
|
|
46
|
+
|
|
47
|
+
Follow this sequential workflow when implementing new test suites. Copy the checklist to track your progress.
|
|
48
|
+
|
|
49
|
+
### Task Progress
|
|
50
|
+
|
|
51
|
+
- [ ] 1. Create the test file in the `test/` directory, ensuring the `_test.dart` suffix.
|
|
52
|
+
- [ ] 2. Import `package:test/test.dart` and the target library.
|
|
53
|
+
- [ ] 3. Define a `main()` function.
|
|
54
|
+
- [ ] 4. Initialize shared resources or mocks using `setUp()`.
|
|
55
|
+
- [ ] 5. Write `test()` cases grouped by functionality using `group()`.
|
|
56
|
+
- [ ] 6. Execute the test suite using the appropriate CLI command.
|
|
57
|
+
- [ ] 7. **Feedback Loop**: Run test -> Review stack trace for failures -> Fix implementation or assertions -> Re-run until passing.
|
|
58
|
+
|
|
59
|
+
## Examples
|
|
60
|
+
|
|
61
|
+
### Standard Unit Test Suite
|
|
62
|
+
|
|
63
|
+
Demonstrates grouping, setup, synchronous, and asynchronous testing.
|
|
64
|
+
|
|
65
|
+
```dart
|
|
66
|
+
import 'package:test/test.dart';
|
|
67
|
+
import 'package:my_package/calculator.dart';
|
|
68
|
+
|
|
69
|
+
void main() {
|
|
70
|
+
group('Calculator', () {
|
|
71
|
+
late Calculator calc;
|
|
72
|
+
|
|
73
|
+
setUp(() {
|
|
74
|
+
calc = Calculator();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('adds two numbers correctly', () {
|
|
78
|
+
expect(calc.add(2, 3), equals(5));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('handles asynchronous operations', () async {
|
|
82
|
+
final result = await calc.fetchRemoteValue();
|
|
83
|
+
expect(result, isNotNull);
|
|
84
|
+
expect(result, greaterThan(0));
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Mocking with Mockito
|
|
91
|
+
|
|
92
|
+
Demonstrates configuring a mock object for dependency injection testing.
|
|
93
|
+
|
|
94
|
+
```dart
|
|
95
|
+
import 'package:test/test.dart';
|
|
96
|
+
import 'package:mockito/mockito.dart';
|
|
97
|
+
import 'package:mockito/annotations.dart';
|
|
98
|
+
import 'package:my_package/api_client.dart';
|
|
99
|
+
import 'package:my_package/data_service.dart';
|
|
100
|
+
|
|
101
|
+
// Generate the mock using build_runner: dart run build_runner build
|
|
102
|
+
@GenerateNiceMocks([MockSpec<ApiClient>()])
|
|
103
|
+
import 'data_service_test.mocks.dart';
|
|
104
|
+
|
|
105
|
+
void main() {
|
|
106
|
+
group('DataService', () {
|
|
107
|
+
late MockApiClient mockApiClient;
|
|
108
|
+
late DataService dataService;
|
|
109
|
+
|
|
110
|
+
setUp(() {
|
|
111
|
+
mockApiClient = MockApiClient();
|
|
112
|
+
dataService = DataService(apiClient: mockApiClient);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('returns parsed data on successful API call', () async {
|
|
116
|
+
// Configure the mock
|
|
117
|
+
when(mockApiClient.get('/data')).thenAnswer((_) async => '{"id": 1}');
|
|
118
|
+
|
|
119
|
+
// Execute the system under test
|
|
120
|
+
final result = await dataService.fetchData();
|
|
121
|
+
|
|
122
|
+
// Verify outcomes and interactions
|
|
123
|
+
expect(result.id, equals(1));
|
|
124
|
+
verify(mockApiClient.get('/data')).called(1);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Flutter Ultra Integration
|
|
131
|
+
|
|
132
|
+
After writing the unit test, run and validate it:
|
|
133
|
+
|
|
134
|
+
- `mcp__plugin_flutter_flutter-ultra-build__start_run_unit_tests` — Execute unit tests (supports `testNamePattern` and `coverage`)
|
|
135
|
+
- `mcp__plugin_flutter_flutter-ultra-build__poll_run_unit_tests` — Monitor test progress until completion
|
|
136
|
+
- `mcp__plugin_flutter_flutter-ultra-build__get_run_unit_tests_result` — Get detailed results with per-failure info
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
> **Attribution:** This skill is vendored from [dart-lang/skills](https://github.com/dart-lang/skills) (BSD-3-Clause).
|
|
141
|
+
> Synced by `scripts/sync-upstream-skills.mjs`. Do not edit manually — changes will be overwritten on next sync.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: add-widget-preview
|
|
3
|
+
description: Adds interactive widget previews to the project using the previews.dart system. Use when creating new UI components or updating existing screens to ensure consistent design and interactive testing.
|
|
4
|
+
last_modified: Tue, 21 Apr 2026 20:05:23 GMT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Previewing Flutter Widgets
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- [Preview Guidelines](#preview-guidelines)
|
|
12
|
+
- [Handling Limitations](#handling-limitations)
|
|
13
|
+
- [Workflows](#workflows)
|
|
14
|
+
- [Examples](#examples)
|
|
15
|
+
|
|
16
|
+
## Preview Guidelines
|
|
17
|
+
|
|
18
|
+
Use the Flutter Widget Previewer to render widgets in real-time, isolated from the full application context.
|
|
19
|
+
|
|
20
|
+
- **Target Elements:** Apply the `@Preview` annotation to top-level functions, static methods within a class, or public widget constructors/factories that have no required arguments and return a `Widget` or `WidgetBuilder`.
|
|
21
|
+
- **Imports:** Always import `package:flutter/widget_previews.dart` to access the preview annotations.
|
|
22
|
+
- **Custom Annotations:** Extend the `Preview` class to create custom annotations that inject common properties (e.g., themes, wrappers) across multiple widgets.
|
|
23
|
+
- **Multiple Configurations:** Apply multiple `@Preview` annotations to a single target to generate multiple preview instances. Alternatively, extend `MultiPreview` to encapsulate common multi-preview configurations.
|
|
24
|
+
- **Runtime Transformations:** Override the `transform()` method in custom `Preview` or `MultiPreview` classes to modify preview configurations dynamically at runtime (e.g., generating names based on dynamic values, which is impossible in a `const` context).
|
|
25
|
+
|
|
26
|
+
## Handling Limitations
|
|
27
|
+
|
|
28
|
+
Adhere to the following constraints when authoring previewable widgets, as the Widget Previewer runs in a web environment:
|
|
29
|
+
|
|
30
|
+
- **No Native APIs:** Do not use native plugins or APIs from `dart:io` or `dart:ffi`. Widgets with transitive dependencies on `dart:io` or `dart:ffi` will throw exceptions upon invocation. Use conditional imports to mock or bypass these in preview mode.
|
|
31
|
+
- **Asset Paths:** Use package-based paths for assets loaded via `dart:ui` `fromAsset` APIs (e.g., `packages/my_package_name/assets/my_image.png` instead of `assets/my_image.png`).
|
|
32
|
+
- **Public Callbacks:** Ensure all callback arguments provided to preview annotations are public and constant to satisfy code generation requirements.
|
|
33
|
+
- **Constraints:** Apply explicit constraints using the `size` parameter in the `@Preview` annotation if your widget is unconstrained, as the previewer defaults to constraining them to approximately half the viewport.
|
|
34
|
+
|
|
35
|
+
## Workflows
|
|
36
|
+
|
|
37
|
+
### Creating a Widget Preview
|
|
38
|
+
|
|
39
|
+
Copy and track this checklist when implementing a new widget preview:
|
|
40
|
+
|
|
41
|
+
- [ ] Import `package:flutter/widget_previews.dart`.
|
|
42
|
+
- [ ] Identify a valid target (top-level function, static method, or parameter-less public constructor).
|
|
43
|
+
- [ ] Apply the `@Preview` annotation to the target.
|
|
44
|
+
- [ ] Configure preview parameters (`name`, `group`, `size`, `theme`, `brightness`, etc.) as needed.
|
|
45
|
+
- [ ] If applying the same configuration to multiple widgets, extract the configuration into a custom class extending `Preview`.
|
|
46
|
+
|
|
47
|
+
### Interacting with Previews
|
|
48
|
+
|
|
49
|
+
Follow the appropriate conditional workflow to launch and interact with the Widget Previewer:
|
|
50
|
+
|
|
51
|
+
**If using a supported IDE (Android Studio, IntelliJ, VS Code with Flutter 3.38+):**
|
|
52
|
+
|
|
53
|
+
1. Launch the IDE. The Widget Previewer starts automatically.
|
|
54
|
+
2. Open the "Flutter Widget Preview" tab in the sidebar.
|
|
55
|
+
3. Toggle "Filter previews by selected file" at the bottom left if you want to view previews outside the currently active file.
|
|
56
|
+
|
|
57
|
+
**If using the Command Line:**
|
|
58
|
+
|
|
59
|
+
1. Navigate to the Flutter project's root directory.
|
|
60
|
+
2. Run `flutter widget-preview start`.
|
|
61
|
+
3. View the automatically opened Chrome environment.
|
|
62
|
+
|
|
63
|
+
**Feedback Loop: Preview Iteration**
|
|
64
|
+
|
|
65
|
+
1. Modify the widget code or preview configuration.
|
|
66
|
+
2. Observe the automatic update in the Widget Previewer.
|
|
67
|
+
3. If global state (e.g., static initializers) was modified: Click the global hot restart button at the bottom right.
|
|
68
|
+
4. If only the local widget state needs resetting: Click the individual hot restart button on the specific preview card.
|
|
69
|
+
5. Review errors in the IDE/CLI console -> fix -> repeat.
|
|
70
|
+
|
|
71
|
+
## Examples
|
|
72
|
+
|
|
73
|
+
### Basic Preview
|
|
74
|
+
|
|
75
|
+
```dart
|
|
76
|
+
import 'package:flutter/widget_previews.dart';
|
|
77
|
+
import 'package:flutter/material.dart';
|
|
78
|
+
|
|
79
|
+
@Preview(name: 'My Sample Text', group: 'Typography')
|
|
80
|
+
Widget mySampleText() {
|
|
81
|
+
return const Text('Hello, World!');
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Custom Preview with Runtime Transformation
|
|
86
|
+
|
|
87
|
+
```dart
|
|
88
|
+
import 'package:flutter/widget_previews.dart';
|
|
89
|
+
import 'package:flutter/material.dart';
|
|
90
|
+
|
|
91
|
+
final class TransformativePreview extends Preview {
|
|
92
|
+
const TransformativePreview({
|
|
93
|
+
super.name,
|
|
94
|
+
super.group,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
PreviewThemeData _themeBuilder() {
|
|
98
|
+
return PreviewThemeData(
|
|
99
|
+
materialLight: ThemeData.light(),
|
|
100
|
+
materialDark: ThemeData.dark(),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@override
|
|
105
|
+
Preview transform() {
|
|
106
|
+
final originalPreview = super.transform();
|
|
107
|
+
final builder = originalPreview.toBuilder();
|
|
108
|
+
|
|
109
|
+
builder
|
|
110
|
+
..name = 'Transformed - ${originalPreview.name}'
|
|
111
|
+
..theme = _themeBuilder;
|
|
112
|
+
|
|
113
|
+
return builder.toPreview();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@TransformativePreview(name: 'Custom Themed Button')
|
|
118
|
+
Widget myButton() => const ElevatedButton(onPressed: null, child: Text('Click'));
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### MultiPreview Implementation
|
|
122
|
+
|
|
123
|
+
```dart
|
|
124
|
+
import 'package:flutter/widget_previews.dart';
|
|
125
|
+
import 'package:flutter/material.dart';
|
|
126
|
+
|
|
127
|
+
/// Creates light and dark mode previews automatically.
|
|
128
|
+
final class MultiBrightnessPreview extends MultiPreview {
|
|
129
|
+
const MultiBrightnessPreview({required this.name});
|
|
130
|
+
|
|
131
|
+
final String name;
|
|
132
|
+
|
|
133
|
+
@override
|
|
134
|
+
List<Preview> get previews => const [
|
|
135
|
+
Preview(brightness: Brightness.light),
|
|
136
|
+
Preview(brightness: Brightness.dark),
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
@override
|
|
140
|
+
List<Preview> transform() {
|
|
141
|
+
final previews = super.transform();
|
|
142
|
+
return previews.map((preview) {
|
|
143
|
+
final builder = preview.toBuilder()
|
|
144
|
+
..group = 'Brightness'
|
|
145
|
+
..name = '$name - ${preview.brightness!.name}';
|
|
146
|
+
return builder.toPreview();
|
|
147
|
+
}).toList();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@MultiBrightnessPreview(name: 'Primary Card')
|
|
152
|
+
Widget cardPreview() => const Card(child: Padding(padding: EdgeInsets.all(8.0), child: Text('Content')));
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Flutter Ultra Integration
|
|
156
|
+
|
|
157
|
+
After adding `@Preview` annotations, use these tools to view and capture previews:
|
|
158
|
+
|
|
159
|
+
- `mcp__plugin_flutter_flutter-ultra-runtime__launch_app` — Launch the app to render previews
|
|
160
|
+
- `mcp__plugin_flutter_flutter-ultra-runtime__screenshot` — Capture preview screenshots for documentation
|
|
161
|
+
- `mcp__plugin_flutter_flutter-ultra-build__analyze` — Verify preview annotations are syntactically correct
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
> **Attribution:** This skill is vendored from [flutter/skills](https://github.com/flutter/skills) (BSD-3-Clause).
|
|
166
|
+
> Synced by `scripts/sync-upstream-skills.mjs`. Do not edit manually — changes will be overwritten on next sync.
|