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.1 Answer
Reset to default 0Run 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
版权声明:本文标题:Flutter How to test CupertinoActionSheet - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736280770a1926105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论