admin管理员组

文章数量:1122832

I have a button that when I click on it opens Cupertino Action Sheet so how to make widget testing for this i have tried adding a key and get Cupertino Action Sheet by key by type and finally by text nothing is working as expected I tried also make runAsync but it didn't work you can find the code below.

testWidgets(
      'Should show action sheet buttons',
      (widgetTester) async {
          await widgetTester.pumpWidget(
            _makeTestableWidget(const RegisterScreen())
          );
          var pickImageGestureDetector = find.byKey(ValueKey("pickImage"));
          expect(pickImageGestureDetector, findsOneWidget);
          await widgetTester.runAsync(() async => await widgetTester.tap(pickImageGestureDetector, warnIfMissed: false));
          await widgetTester.pumpAndSettle();
          final actionSheetFinder = find.byKey(Key('actionSheetKey'));
          expect(actionSheetFinder, findsOneWidget);
        }
    );

Found 0 widgets with key [<'actionSheetKey'>]

I have a button that when I click on it opens Cupertino Action Sheet so how to make widget testing for this i have tried adding a key and get Cupertino Action Sheet by key by type and finally by text nothing is working as expected I tried also make runAsync but it didn't work you can find the code below.

testWidgets(
      'Should show action sheet buttons',
      (widgetTester) async {
          await widgetTester.pumpWidget(
            _makeTestableWidget(const RegisterScreen())
          );
          var pickImageGestureDetector = find.byKey(ValueKey("pickImage"));
          expect(pickImageGestureDetector, findsOneWidget);
          await widgetTester.runAsync(() async => await widgetTester.tap(pickImageGestureDetector, warnIfMissed: false));
          await widgetTester.pumpAndSettle();
          final actionSheetFinder = find.byKey(Key('actionSheetKey'));
          expect(actionSheetFinder, findsOneWidget);
        }
    );

Found 0 widgets with key [<'actionSheetKey'>]

Share Improve this question asked yesterday Heba OthmanHeba Othman 1 New contributor Heba Othman is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

Run your app and use Flutter Inspector. This will confirm that you have the key set correctly. Keys in Flutter inspector appear in square brackets in the widget tree.

There could also be a workaround where you give the text option on the action sheet a Key and do the expect on that. Example:

expect(actionSheetOption1Finder, findsOneWidget);

本文标签: Flutter How to test CupertinoActionSheetStack Overflow