为什么在 flutter 项目中自动创建测试文件夹,在这个文件夹中文件 widget_test..dart 总是显示红线(类似错误)

Why the test folder automatically gets created on flutter projects, inside this folder the file widget_test..dart always showing red line(ilke error)

我所有的 Flutter 项目都有它。该文件夹是否必需或不需要t? 我要删除文件夹吗?

删除 const。喜欢 await tester.pumpWidget(MyApp());

基本上 runApp() 方法(在 main.dart 内)包含一个 class 并且它应该与此 tester.pumpWidget(....) 方法中定义的相同。如果它们不匹配,则会导致此错误。

例如 在你的 main.dart if runApp() 方法有一个 class HomePage runApp(const HomePage()); 然后在 widget_test.dart 文件中它应该像 await tester.pumpWidget(const HomePage());