1

enter image description here

-> In the above code I am having problem in my widgets_test.dart file where its telling can't find the class name in my above code.

-> But I have changed my code like there is no "MyApp" class, I have been calling "MaterialApp" class directly in runApp() function, so please help to fix this.

enter image description here

2

2 Answers 2

1

Initially, in widgets_test.dart, you have this code:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:app/main.dart';

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async 
 {
  // Build our app and trigger a frame.
  await tester.pumpWidget(const MyApp());

  // Verify that our counter starts at 0.
  expect(find.text('0'), findsOneWidget);
  expect(find.text('1'), findsNothing);

  // Tap the '+' icon and trigger a frame.
  await tester.tap(find.byIcon(Icons.add));
  await tester.pump();

  // Verify that our counter has incremented.
  expect(find.text('0'), findsNothing);
  expect(find.text('1'), findsOneWidget);
  });
 }

Since you deleted the MyApp class from main.dart file, then you get the error, because the program cant find the class. You can delete the code from widgets_test.dart file, and have just this:

void main() {}
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of passing a MaterialApp directly to runApp, wrap it in a MyApp widget and pass MyApp to runApp.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My Flutter App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

In MyApp, there should be a StatelessWidget that contains Material components.

runApp(MyApp();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.