npx skills add ...
npx skills add flutter/skills --skill flutter-add-widget-test
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.
This repo is now called flutter/agent-plugins. Both names install the same content, but the install count here only covers this one.
npx skills add flutter/skills --skill flutter-add-widget-test
Ensure the testing environment is properly configured before authoring widget tests.
flutter_test dependency to the dev_dependencies section of pubspec.yaml.test/ directory at the root of the project._test.dart (e.g., widget_test.dart).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).Copy the following checklist to track progress when implementing a new widget test.
testWidgets('description', (WidgetTester tester) async { ... }).await tester.pumpWidget(MyWidget()) to render the UI. Wrap the widget in a MaterialApp or Directionality widget if it requires inherited directional or theme data.Finder objects for the target widgets.expect(finder, matcher) to validate the initial render.await tester.tap(buttonFinder)).await tester.pump() or await tester.pumpAndSettle() to process state changes.expect() to validate the UI after the interaction.flutter test test/your_test_file_test.dart.Apply the following conditional logic based on the type of interaction or state change being tested:
await tester.pumpWidget() once, then immediately run expect() assertions.await tester.tap(finder).await tester.pump() to trigger a single frame rebuild.await tester.drag(finder, Offset(500, 0))).await tester.pumpAndSettle() to repeatedly pump frames until no more frames are scheduled (animation completes).await tester.enterText(textFieldFinder, 'Input string').await tester.scrollUntilVisible(itemFinder, 500.0, scrollable: listFinder) to ensure the target widget is rendered before interacting with it.Target Widget (lib/todo_list.dart):
Test Implementation (test/todo_list_test.dart):