aashahin/ai-skills/flutter-add-widget-test
Claude Code and agent skill by aashahin/ai-skills
- community
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install aashahin/ai-skills/flutter-add-widget-testSKILL.md
The same SKILL.md was published earlier as flutter/skills/flutter-add-widget-test.
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 the
testWidgets()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 a
Finder(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.
- 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).
- 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`):
Test Implementation (`test/todo_list_test.dart`):
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingflutter-add-widget-test/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/aashahin/ai-skills/flutter-add-widget-test)