web-dev-qa-db-ja.com

Flutterのエラー:widget_test.dartはmyapp()を検出できません

全初心者であることは、さまざまなフラッター機能を試しています。エラーが他の理由によるものであるかどうかを指摘してください。

main.dart

import 'package:flutter/material.Dart';
 void main(){
   var app = MaterialApp(
     title: 'FlutterApp',
     debugShowCheckedModeBanner: true,
     theme: ThemeData(
        primaryColor: Colors.black12,
        accentColor: Colors.orange,
     ),
     home: Scaffold(
       appBar: AppBar(
         title: Text('Stateless'),
         backgroundColor: Colors.black,
         ),
   ),
   );
   runApp(app);
 }
 _

widget_test.dart

// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

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

import 'package:stateless/main.Dart';

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

    // 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);
  });
}
 _

これは私の最初の質問であり、私は質問を正しい方法で置くことができなかったらすみれてすみません

4
joel

私はちょうどフィクスルされたばかりで、解決策はデフォルトのタップカウンターアプリによって与えられたデフォルトの 'my​​app'の代わりにあなたの実際のステートフルウィジェット名を単に置くだけです!

0
Tejas MD

簡単なもので、Widget_Test.Dartファイルのクラス名にmyapp名を置き換えることができます。

例えば。 Widget_Test.DARTファイルでMyAppをApp(あなたの場合の)に置き換えます

0
Vijay Singh