The name 'MyApp' isn't a class. Try correcting the name to match an existing class. flutter

2,750

On the pumpWidget method change "const MyApp()" to the same name of your first Widget class. The class you instance on the runApp function inside the main function on the main.dart file.

For example, if your main.dart content is:

void main() async {
     runApp(MyGreatApp());
}
        
class MyGreatApp extends StatelessWidget {
   const MyGreatApp();
        
  @override
  Widget build(BuildContext context) {
       return MaterialApp(
              //rest of code ...
       );
  }
}

Put in your widget_test.dart file:

await tester.pumpWidget(const MyGreatApp()); //<-
Share:
2,750
Leskeboy
Author by

Leskeboy

Updated on January 01, 2023

Comments

  • Leskeboy
    Leskeboy over 1 year

    I don't know what is the problem is / how to fix this while I tring to code it shows this error on the test folder widget_test.dart

    enter image description herex

     testWidgets('Counter increments smoke test', (WidgetTester tester) async {
        // Build our app and trigger a frame.
        await tester.pumpWidget(const MyApp());
    
    • princesanjivy
      princesanjivy over 2 years
      You need to keep the name of the root widget class