flutter-add-widget-test
Skill4 starsChanged 4 months agoMITView on GitHub
Implement a component-level test using `WidgetTester` to verify UI rendering and user interactions (tapping, scrolling, entering text). Use when validating that a specific widget displays correct data and responds to events as expected.
6 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- SamuelAlev/control-centerword for word, first seen Nov 8, 2026
- zhouycheng/skillsword for word, first seen Oct 13, 2026
- enrique-lozano/Monekinword for word, first seen Oct 9, 2026
- flutter/skillsword for word, first seen Oct 8, 2026
- deretame/Breezeedited, first seen Oct 8, 2026
- zyyziyunying/skillstheir own version, first seen Sep 11, 2026
Other versions6 projects use a version of this.
Word for word · 4
- flutter/skills★ 3.2k100% same
- enrique-lozano/Monekin★ 268100% same
- SamuelAlev/control-center★ 8100% same
- zhouycheng/skills★ 1100% same
Edited · 1
- deretame/Breeze★ 3k100% same
Wrote their own version · 1
- zyyziyunying/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository70 other files it gives its agents.
- AGENTS.mdAGENTS.md
- engine/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- engine/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- brandkitSkill
- code-reviewSkill
- dart-add-unit-testSkill
- dart-build-cli-appSkill
- dart-collect-coverageSkill
- dart-fix-runtime-errorsSkill
- dart-generate-test-mocksSkill
- dart-migrate-to-checks-packageSkill
- dart-resolve-package-conflictsSkill
- dart-run-static-analysisSkill
- dart-setup-ffi-assetsSkill
- dart-use-ffigenSkill
- dart-use-pattern-matchingSkill
- dart-use-primary-constructorsSkill
- design-taste-frontendSkill
- flutter-add-integration-testSkill
- flutter-add-widget-previewSkill
- flutter-apply-architecture-best-practicesSkill
- flutter-build-responsive-layoutSkill
- flutter-fix-layout-issuesSkill
- flutter-implement-json-serializationSkill
- flutter-setup-declarative-routingSkill
- flutter-setup-localizationSkill
- flutter-use-http-packageSkill
- frontend-code-reviewSkill
- full-output-enforcementSkill
- github-releaseSkill
- grill-with-docsSkill
- high-end-visual-designSkill
- imagegen-frontend-webSkill
- image-to-codeSkill
- improve-codebase-architectureSkill
- industrial-brutalist-uiSkill
- minimalist-uiSkill
- redesign-existing-projectsSkill
- source-command-frontend-code-review-skillSkill
- source-command-impeccable-skillSkill
- stitch-design-tasteSkill
- tddSkill
- to-prdSkill
- frontend-code-reviewSkill
- impeccableSkill
- dart-add-unit-testSkill
- dart-build-cli-appSkill
- dart-collect-coverageSkill
- dart-fix-runtime-errorsSkill
- dart-generate-test-mocksSkill
- dart-migrate-to-checks-packageSkill
- dart-resolve-package-conflictsSkill
- dart-run-static-analysisSkill
- dart-setup-ffi-assetsSkill
- dart-use-ffigenSkill
- dart-use-pattern-matchingSkill
- dart-use-primary-constructorsSkill
- flutter-add-integration-testSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Ensure the testing environment is properly configured before authoring widget tests.
- Very specific: line 21
Add the flutter_test dependency to the dev_dependencies section of pubspec.yaml.
- Very specific: line 22
Place all test files in the test/ directory at the root of the project.
- Very specific: line 52
If testing static rendering: Call await tester.pumpWidget() once, then immediately run expect() assertions.
- Very specific: line 55
Call await tester.pump() to trigger a single frame rebuild.
- Very specific: line 58
Call await tester.pumpAndSettle() to repeatedly pump frames until no more frames are scheduled (animation completes).
- Very specific: line 59
If testing text input: Call await tester.enterText(textFieldFinder, 'Input string').
- Very specific: line 60
If testing items in a dynamic or long list: Call await tester.scrollUntilVisible(itemFinder, 500.0, scrollable: listFinder) to ensure the …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing Flutter Widget Tests
Contents
- Setup & Configuration
- Core Components
- Workflow: Implementing a Widget Test
- Interaction & State Management
- Examples
Setup & Configuration
Ensure the testing environment is properly configured before authoring widget tests.
- Add the
flutter_testdependency to thedev_dependenciessection ofpubspec.yaml. - Place all test files in the
test/directory at the root of the project. - Suffix all test file names with
_test.dart(e.g.,widget_test.dart).
Core Components
Utilize the following flutter_test components to interact with and validate the widget tree:
WidgetTester: The primary interface for building and interacting with widgets in the test environment. Provided automatically by thetestWidgets()function.Finder: Locates widgets in the test environment (e.g.,find.text('Submit'),find.byType(TextField),find.byKey(Key('submit_btn'))).Matcher: Verifies the presence or state of widgets located by aFinder(e.g.,findsOneWidget,findsNothing,findsNWidgets(2),matchesGoldenFile).
Workflow: Implementing a Widget Test
Copy the following checklist to track progress when implementing a new widget test.
Task Progress
- Step 1: Define the test. Use
testWidgets('description', (WidgetTester tester) async { ... }). - Step 2: Build the widget. Call
await tester.pumpWidget(MyWidget())to render the UI. Wrap the widget in aMaterialApporDirectionalitywidget if it requires inherited directional or theme data. - Step 3: Locate elements. Instantiate
Finderobjects for the target widgets. - Step 4: Verify initial state. Use
expect(finder, matcher)to validate the initial render. - Step 5: Simulate interactions. Execute gestures or inputs (e.g.,
await tester.tap(buttonFinder)). - Step 6: Rebuild the tree. Call
await tester.pump()orawait tester.pumpAndSettle()to process state changes. - Step 7: Verify updated state. Use
expect()to validate the UI after the interaction. - Step 8: Run and validate. Execute
flutter test test/your_test_file_test.dart. - Step 9: Feedback Loop. Review test output -> identify failing matchers -> adjust widget logic or test assertions -> re-run until passing.
Interaction & State Management
Apply the following conditional logic based on the type of interaction or state change being tested:
- If testing static rendering: Call
await tester.pumpWidget()once, then immediately runexpect()assertions. - If testing standard state changes (e.g., button taps):
- Call
await tester.tap(finder). - Call
await tester.pump()to trigger a single frame rebuild.
- Call
- If testing animations, transitions, or asynchronous UI updates:
- Trigger the action (e.g.,
await tester.drag(finder, Offset(500, 0))). - Call
await tester.pumpAndSettle()to repeatedly pump frames until no more frames are scheduled (animation completes).
- Trigger the action (e.g.,
- If testing text input: Call
await tester.enterText(textFieldFinder, 'Input string'). - If testing items in a dynamic or long list: Call
await tester.scrollUntilVisible(itemFinder, 500.0, scrollable: listFinder)to ensure the target widget is rendered before interacting with it.
Examples
High-Fidelity Widget Test Implementation
Target Widget (lib/todo_list.dart):
import 'package:flutter/material.dart';
class TodoList extends StatefulWidget {
const TodoList({super.key});
@override
State<TodoList> createState() => _TodoListState();
}
class _TodoListState extends State<TodoList> {
final todos = <String>[];
final controller = TextEditingController();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: [
TextField(controller: controller),
Expanded(
child: ListView.builder(
itemCount: todos.length,
itemBuilder: (context, index) {
final todo = todos[index];
return Dismissible(
key: Key('$todo$index'),
onDismissed: (_) => setState(() => todos.removeAt(index)),
child: ListTile(title: Text(todo)),
);
},
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
todos.add(controller.text);
controller.clear();
});
},
child: const Icon(Icons.add),
),
),
);
}
}Test Implementation (test/todo_list_test.dart):
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:my_app/todo_list.dart';
void main() {
testWidgets('Add and remove a todo item', (WidgetTester tester) async {
// 1. Build the widget
await tester.pumpWidget(const TodoList());
// 2. Verify initial state
expect(find.byType(ListTile), findsNothing);
// 3. Enter text into the TextField
await tester.enterText(find.byType(TextField), 'Buy groceries');
// 4. Tap the add button
await tester.tap(find.byType(FloatingActionButton));
// 5. Rebuild the widget to reflect the new state
await tester.pump();
// 6. Verify the item was added
expect(find.text('Buy groceries'), findsOneWidget);
// 7. Swipe the item to dismiss it
await tester.drag(find.byType(Dismissible), const Offset(500, 0));
// 8. Build the widget until the dismiss animation ends
await tester.pumpAndSettle();
// 9. Verify the item was removed
expect(find.text('Buy groceries'), findsNothing);
});
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

