我弹出 1 个错误,但是当我尝试运行该应用程序时,它说我有所有其他错误

Posted

技术标签:

【中文标题】我弹出 1 个错误,但是当我尝试运行该应用程序时,它说我有所有其他错误【英文标题】:I have 1 error popping up but When I try to run the app it says I have all of these other errors that are wrong 【发布时间】:2022-01-18 05:32:30 【问题描述】:

enter image description here

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:time_trackerpractice/app/sign_in/home_page.dart';
import 'package:time_trackerpractice/app/sign_in/sign_in_page.dart';
import 'package:time_trackerpractice/services/auth.dart';

class LandingPage extends StatefulWidget 
  const LandingPage(Key key, this.auth) : super(key: key);
  final AuthBase auth;

  @override
  _LandingPageState createState() => _LandingPageState();



class _LandingPageState extends State<LandingPage> 

  User _user;

  @override
  void initState() 
    // TODO: implement initState
    super.initState();

    _updateUser(widget.auth.currentUser);
  


  void _updateUser(User user) 
    setState(() 
      _user = user;
    );
  

  

  @override
  Widget build(BuildContext context) 
   return StreamBuilder<User>(
     stream: widget.auth.authStateChanges(),
     builder: (context,snapshot)
     if(snapshot.connectionState == ConnectionState.active)
       final User user =snapshot.data;
       if(user == null)
         return SignInPage(
           auth: widget.auth,
           onSignIn: _updateUser,
         );
       
       return HomePage(
           auth: widget.auth,
           onSignOut: => _updateUser(null),
       );
     

       return Scaffold(
       body:Center(
       child: CircularProgressIndicator(),
       );
       );

     ,
   );

我一直在学习颤振课程,并且在我为应用程序键入的代码上弹出 1 个错误,但是当我尝试运行应用程序时,它说我有所有其他错误的错误。这个是唯一出现的错误和分号onSignOut: =&gt; _updateUser(null),所以我不知道我错了。但这些是下面弹出的错误:

lib/app/sign_in/landing_page.dart:38:38: Error: Can't find '' to match ''.
Widget build(BuildContext context) 
                                   ^
lib/app/sign_in/landing_page.dart:16:52: Error: Can't find '' to match ''.
class _LandingPageState extends State<LandingPage> 
                                                   ^
lib/app/sign_in/landing_page.dart:52:23: Error: Expected an identifier, but got '=>'.
Try inserting an identifier before '=>'.
       onSignOut: => _updateUser(null),
                  ^^
lib/app/sign_in/landing_page.dart:52:26: Error: Expected ',' before this.
       onSignOut: => _updateUser(null),
                     ^^^^^^^^^^^
lib/app/sign_in/landing_page.dart:52:26: Error: Place positional arguments before named arguments.
Try moving the positional argument before the named arguments, or add a name to the argument.
       onSignOut: => _updateUser(null),
                     ^^^^^^^^^^^
lib/app/sign_in/landing_page.dart:52:26: Error: Expected named argument.
           onSignOut: => _updateUser(null),
                         ^
lib/app/sign_in/landing_page.dart:50:23: Error: No named parameter with the name '#2'.

【问题讨论】:

【参考方案1】:

您有两个错误,一个是您没有关闭方法,请在代码末尾添加此行:


应该是这样的:

 ...
 return Scaffold(
       body:Center(
       child: CircularProgressIndicator(),
       );
       );

     ,
   );
 

之所以需要这样做是因为您必须同时关闭构建和小部件类

class _LandingPageState extends State<LandingPage> 

  @override
  Widget build(BuildContext context) 
    // some code
   // <--- you missed this
 // <--- you also missed this one, so you must add two  at the end of the file

第二个错误,你忘记了lambda函数上的括号:

从这里:

onSignOut: => _updateUser(null),

到这里:

onSignOut: () => _updateUser(null),

如果您不了解 lambda 是什么,请查看以下资源:https://dart.dev/guides/language/language-tour#anonymous-functions

【讨论】:

感谢您的帮助。我真的很感激。它帮助了我很多

以上是关于我弹出 1 个错误,但是当我尝试运行该应用程序时,它说我有所有其他错误的主要内容,如果未能解决你的问题,请参考以下文章

通知弹出窗口不适用于单个实例

当我尝试运行代码时,我将第二个输出作为垃圾值。谁能说出该代码中的错误

我已经使用 IntelliJ 创建了一个 jar,但是当我尝试运行该 jar 时,我收到一个错误,因为无法加载主类清单 [重复]

当我开始训练数据集时弹出输入用完数据错误

弹出层如何覆盖住播放器,我弹出的是注册页面,但是被播放器给覆盖住了

Parse for iOS:尝试运行应用程序时出错(38 个错误)