Lit*_*key 6 loading spinner flutter
我正在使用ModalProgressHud来显示微调器,同时它正在等待服务器的回答。我想测试当用户点击按钮时,CircularProgressIndicator显示。我的问题是pumpAndSettle()遗嘱会因此而超时CircularProgressIndicator,我认为,它会不断自我重建。关于如何测试 a 是否存在的任何建议CircularProgressIndicator?这是我的测试:
testWidgets(
'Should show a CircularProgressIndicator while it tries to login', (WidgetTester tester) async {
await (tester.pumpWidget(
generateApp(LoginView())
));
await tester.pumpAndSettle();
await tester.tap(find.byType(FlatButton));
await tester.pumpAndSettle();
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
Run Code Online (Sandbox Code Playgroud)
你的想法是正确的 - 你不能,pumpAndSettle因为 CircularProgressIndicator 无限期地动画。您可以尝试使用tester.pump()超时而不是pumpAndSettle.
您应该创建一个“加载”bool并setState((){})在登录屏幕之前使用,并在评估登录是否成功时使用另一个。
我不太确定如何遵循您的代码,但也许是这样的......
bool loading = false;
testWidgets(
'Should show a CircularProgressIndicator while it tries to login', (WidgetTester tester) async {
loading == false ? setState((){
loading = true;
await (tester.pumpWidget(
generateApp(LoginView())
));}
await tester.pumpAndSettle();
await tester.tap(find.byType(FlatButton));
await tester.pumpAndSettle();
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
917 次 |
| 最近记录: |