我跟踪this example是为了测试101是否出现在我的视图中,但即使Flutter 构建树显示小部件存在,我仍然得到以下异常:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _WidgetFinder:<zero widgets with the given widget
(CircularProgressIndicator(<indeterminate>)) (ignoring offstage widgets)>
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main.<anonymous closure> (file:///D:/xxxx/xxxx/xxxx/test/widget_test/widget_test.dart:173:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
This was caught by the test expectation on the following line:
file:///D:/xxxx/xxxx/xxxx/test/widget_test/widget_test.dart line 173
The test description was:
ViewRequest: Waiting Types List
════════════════════════════════════════════════════════════════════════════════════════════════════
Edit
我做了一个方法,只用一个101小部件作为它的"子部件"来构建100:
Widget createMockViewRequest() {
return MaterialApp(
title: 'SmartDevice Simulator',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const CircularProgressIndicator());
}
以下测试仍然失败,但有一个例外:
testWidgets('ViewRequest: Waiting Types List', (WidgetTester tester) async {
const childWidget = CircularProgressIndicator();
// Build our app and trigger a frame.
await tester.pumpWidget(createMockViewRequest());
// Verify that the page is loading until we receive the types.
expect(find.byWidget(childWidget), findsOneWidget);
await tester.pumpAndSettle();
});
我做错什么了吗?也许100不算集装箱?但在这种情况下,我不明白为什么不应该这样做.