Flutter Flatter Firebase身份验证错误

Flutter Flatter Firebase身份验证错误,flutter,firebase-authentication,Flutter,Firebase Authentication,我在摸索我的登录页。我升级了1.12之前的项目。 这似乎是迁移的最后一部分 我在代码块中将错误加粗 错误是: “用户”不是一个函数 尝试更正名称以匹配现有函数,或定义名为“User”的方法或函数 错误: 未为类型“UserCredential”定义获取程序“uid” 尝试导入定义“did”的库,更正除一个导入之外的所有导入的名称 错误: 库的包中未定义名称“User”:firebase\u auth/firebase\u auth.dar 尝试更正名称以匹配现有函数,或定义名为“User”的方法

我在摸索我的登录页。我升级了1.12之前的项目。 这似乎是迁移的最后一部分

我在代码块中将错误加粗

错误是:

“用户”不是一个函数 尝试更正名称以匹配现有函数,或定义名为“User”的方法或函数

错误:

未为类型“UserCredential”定义获取程序“uid” 尝试导入定义“did”的库,更正除一个导入之外的所有导入的名称

错误:

库的包中未定义名称“User”:firebase\u auth/firebase\u auth.dar 尝试更正名称以匹配现有函数,或定义名为“User”的方法或函数

希望有人能帮我

From firebase_core: ^0.4.0+1 to firebase_core: ^0.5.0
From firebase_auth: ^0.11.1+3 to firebase_auth: ^0.18.0+1
From cloud_firestore: ^0.12.7+1 to cloud_firestore: ^0.14.0+2
From firebase_storage: ^3.0.4 to firebase_storage: ^4.0.0
登录页

import 'package:firebase_auth/firebase_auth.dart';

import '../Models/appConstants.dart';
import '../Models/userObjects.dart';
import './guestHomePage.dart';
import './signUpPage.dart';

class LoginPage extends StatefulWidget {
  static final String routeName = '/loginPageRoute';

  LoginPage({Key key}) : super(key: key);

  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final _formKey = GlobalKey<FormState>();
  TextEditingController _emailController = TextEditingController();
  TextEditingController _passwordController = TextEditingController();

  void _signUp() {
    if (_formKey.currentState.validate()) {
      String email = _emailController.text;
      String password = _passwordController.text;
      **AppConstants.currentUser = User();**
      AppConstants.currentUser.email = email;
      AppConstants.currentUser.password = password;
      Navigator.pushNamed(context, SignUpPage.routeName);
    }
  }

  void _login() {
    if (_formKey.currentState.validate()) {
      String email = _emailController.text;
      String password = _passwordController.text;
      FirebaseAuth.instance
          .signInWithEmailAndPassword(
        email: email,
        password: password,
      )
          .then((firebaseUser) {
        **String userID = firebaseUser.uid;**
        **AppConstants.currentUser = User(id: userID);**
        AppConstants.currentUser
            .getPersonalInfoFromFirestore()
            .whenComplete(() {
          Navigator.pushNamed(context, GuestHomePage.routeName);
        });
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Center(
          child: Padding(
            padding: const EdgeInsets.fromLTRB(50, 100, 50, 0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Text(
                  'Welcome to ${AppConstants.appName}!',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 30.0,
                  ),
                  textAlign: TextAlign.center,
                ),
                Form(
                  key: _formKey,
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.only(top: 35.0),
                        child: TextFormField(
                          decoration: InputDecoration(labelText: 'Email'),
                          style: TextStyle(
                            fontSize: 25.0,
                          ),
                          validator: (text) {
                            if (!text.contains('@')) {
                              return 'Please enter a valid email';
                            }
                            return null;
                          },
                          controller: _emailController,
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(top: 25.0),
                        child: TextFormField(
                          decoration: InputDecoration(labelText: 'Password'),
                          style: TextStyle(
                            fontSize: 25.0,
                          ),
                          obscureText: true,
                          validator: (text) {
                            if (text.length < 6) {
                              return 'Password must be at least 6 characters';
                            }
                            return null;
                          },
                          controller: _passwordController,
                        ),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 30.0),
                  child: MaterialButton(
                    onPressed: () {
                      _login();
                    },
                    child: Text(
                      'Login',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                      ),
                    ),
                    color: Colors.blue,
                    height: MediaQuery.of(context).size.height / 12,
                    minWidth: double.infinity,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 30.0),
                  child: MaterialButton(
                    onPressed: () {
                      _signUp();
                    },
                    child: Text(
                      'Sign Up',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                      ),
                    ),
                    color: Colors.grey,
                    height: MediaQuery.of(context).size.height / 12,
                    minWidth: double.infinity,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
} ```
import'package:firebase_auth/firebase_auth.dart';
导入“../Models/appConstants.dart”;
导入“../Models/userObjects.dart”;
导入“/guestomepage.dart”;
导入“./signUpPage.dart”;
类LoginPage扩展StatefulWidget{
静态最终字符串routeName='/loginPageRoute';
LoginPage({Key}):超级(Key:Key);
@凌驾
_LoginPagentate createState()=>_LoginPagentate();
}
类_loginpagentate扩展状态{
final _formKey=GlobalKey();
TextEditingController_emailController=TextEditingController();
TextEditingController_passwordController=TextEditingController();
无效(注册){
if(_formKey.currentState.validate()){
字符串email=\u emailController.text;
字符串密码=_passwordController.text;
**AppConstants.currentUser=User()**
AppConstants.currentUser.email=电子邮件;
AppConstants.currentUser.password=密码;
Navigator.pushNamed(上下文,SignUpPage.routeName);
}
}
void_login(){
if(_formKey.currentState.validate()){
字符串email=\u emailController.text;
字符串密码=_passwordController.text;
FirebaseAuth.instance
.使用电子邮件和密码登录(
电邮:电邮,,
密码:密码,
)
.然后((firebaseUser){
**字符串userID=firebaseUser.uid**
**AppConstants.currentUser=User(id:userID)**
AppConstants.currentUser
.getPersonalInfoFromFirestore()中的
.完成时(){
Navigator.pushNamed(上下文,GuestHomePage.routeName);
});
});
}
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:SingleChildScrollView(
儿童:中心(
孩子:填充(
填充:LTRB(50,100,50,0)中的常数边集,
子:列(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
正文(
'欢迎使用${AppConstants.appName}!',
样式:TextStyle(
fontWeight:fontWeight.bold,
字体大小:30.0,
),
textAlign:textAlign.center,
),
形式(
键:_formKey,
子:列(
儿童:[
填充物(
填充:仅限常量边集(顶部:35.0),
子项:TextFormField(
装饰:输入装饰(标签文本:“电子邮件”),
样式:TextStyle(
字体大小:25.0,
),
验证器:(文本){
如果(!text.contains('@')){
返回“请输入有效电子邮件”;
}
返回null;
},
控制器:\u电子邮件控制器,
),
),
填充物(
填充:仅限常量边集(顶部:25.0),
子项:TextFormField(
装饰:输入装饰(标签文本:“密码”),
样式:TextStyle(
字体大小:25.0,
),
蒙昧文字:对,
验证器:(文本){
如果(文本长度<6){
返回“密码必须至少为6个字符”;
}
返回null;
},
控制器:_passwordController,
),
)
],
),
),
填充物(
填充:仅限常量边集(顶部:30.0),
子:材质按钮(
已按下:(){
_登录();
},
子:文本(
“登录”,
样式:TextStyle(
fontWeight:fontWeight.bold,
字体大小:25.0,
),
),
颜色:颜色,蓝色,
高度:MediaQuery.of(context).size.height/12,
minWidth:double.infinity,
形状:圆形矩形边框(
边界半径:边界半径。圆形(10),
),
),
),
填充物(
填充:仅限常量边集(顶部:30.0),
子:材质按钮(
已按下:(){
_注册();
},
子:文本(
“注册”,
样式:TextStyle(
fontWeight:fontWeight.bold,
字体大小:25.0,
),
),
final FirebaseAuth auth = FirebaseAuth.instance;

void inputData() async {
    final FirebaseUser user = await auth.currentUser();
    final uid = user.uid;
    // here you write the codes to input the data into firestore
  }
.then((credentials) {
    String userID = credentials.user.uid;