Home > other >  Error in const MyApp() in widget_test.dart file
Error in const MyApp() in widget_test.dart file

Time:03-29

I am a beginner in Flutter and when I started a new project using Visual Studio Code the widget_test.dart file in the test folder is showing an error in the code given below

await tester.pumpWidget(const MyApp());

The error detail is that the constructor being called isn't a const constructor and it suggest removing 'const' from the constructor.

The error will disappear if const is removed as suggested by flutter, But i want to know why this error appeared since the said file was created by default when new project was created and I also didn't edit it.

CodePudding user response:

When you first create a new application, a widget test is created for you automatically which checks it can pump your app without any exceptions, which generally should be a starting point to testing it

this is totally fine, but since when you create the app the constructor of the app class is a const constructor it uses a const instantiation, but since you did change it to be a non const constructor, you should also remove the const from the test :)

  • Related