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

5

6

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());
Anguine answered 11/10, 2021 at 14:17 Comment(1)
You need to keep the name of the root widget classBikol
S
10

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()); //<-
Shelton answered 11/10, 2021 at 14:43 Comment(0)
G
2

You should add

 await tester.pumpWidget(const MaterialApp());

at widget_test.dart file, if your main.dart begins like this:

void main() runApp(
MaterialApp(
  home: Scaffold( 
Ganof answered 19/10, 2021 at 9:3 Comment(0)
P
2

Try to remove the word "const"

Paramorph answered 22/8, 2022 at 9:36 Comment(0)
B
2

I think because you did not import a file main.dart into widget_test.dart You should insert "import 'package: yourapp folder/main.dart;'" It should be working.

Behnken answered 7/9, 2022 at 7:48 Comment(0)
A
0

try importing main.dart import 'package:appName/main.dart';

if it's work, try the app.dart import 'package:appName/app.dart';

Anemic answered 10/11, 2022 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.