小编Osa*_*arf的帖子

LateInitializationError:字段“_instance@99075166”尚未初始化

这是我第一次测试 flutter 应用程序。HomeView我尝试用这个测试代码来泵:

\n
void main() {\n  group('Home Test', () {\n    _pumpHome(WidgetTester tester) => tester.pumpWidget(\n          MaterialApp(\n            home: HomeView(),\n          ),\n        );\n\n    testWidgets('Route to Azkar page', (WidgetTester tester) async {\n      await _pumpHome(tester);\n      await tester.tap(find.byKey(Key('morning')));\n      expect(find.byType(ListView), findsOneWidget);\n    });\n  });\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但这两个例外却发生了。

\n
\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following LateError was thrown building HomeView(dirty):\nLateInitializationError: Field '_instance@99075166' has not been initialized.\n\nThe relevant error-causing widget was:\n  HomeView file:///E:/projects/flutterProject/tafra/test/home_test.dart:26:19\n\nWhen the exception was thrown, this was the stack:\n#0      ScreenUtil._instance (package:flutter_screenutil/screen_util.dart)\n#1      new ScreenUtil (package:flutter_screenutil/screen_util.dart:28:12)\n#2      SizeExtension.w …
Run Code Online (Sandbox Code Playgroud)

testing unit-testing flutter flutter-test widget-test-flutter

0
推荐指数
1
解决办法
2438
查看次数