Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

dart - error showing white display...... await tester.pumpWidget(MyApp()); cant detect application

i got error dart analysis -

error: The method 'document' isn't defined for the type 'CollectionReference'. (undefined_method at [food_app] libscrprovidersauth.dart:51)

error: The function 'MyApp' isn't defined. (undefined_function at [food_app] testwidget_test.dart:15)`

main.dart:


import 'package:flutter/material.dart';
import 'package:food_app/scr/providers/auth.dart';
import 'package:food_app/scr/screens/home.dart';
import 'package:food_app/scr/screens/login.dart';
import 'package:food_app/scr/widgets/loading.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(MultiProvider(
      providers: [
        ChangeNotifierProvider.value(value: AuthProvider.initialize())
      ],
      child: MaterialApp(
          ebugShowCheckedModeBanner: false,
          title: 'Food app',
          theme: ThemeData(
            primarySwatch: Colors.red,
          ),
          home: ScreensController())));
}

class ScreensController extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final auth = Provider.of<AuthProvider>(context);
    switch (auth.status) {
      case Status.Uninitialized:
        return Loading();
      case Status.Unauthenticated:
      case Status.Authenticating:
        return LoginScreen();
      case Status.Authenticated:
        return Home();
      default:
        return LoginScreen();
    }
  }
}

Widget_test.dart:

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

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(
        MyApp()); // ERROR LINE error: The function 'MyApp' isn't defined. (undefined_function at [food_app] testwidget_test.dart:15)

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

i got error in (document) , when i m changing (document) to (doc) it will not showing error after that it showing error in (setData) same thing setData i m chnaging it to (set) it is fine or not ?

auth.dart:

Future<bool> signUp() async {
  try {
    _status = Status.Authenticating;
    notifyListeners();
    await _auth
        .createUserWithEmailAndPassword(
            email: email.text.trim(), password: password.text.trim())
        .then((result) {
      _firestore.collection('users').document(result.user.uid).setData({
        // ERROR LINE undefined document and setData
        'name': name.text,
        'email': email.text,
        'id': result.user.uid
      });
    });
question from:https://stackoverflow.com/questions/65840126/error-showing-white-display-await-tester-pumpwidgetmyapp-cant-detect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...