Flutter创建用户电子邮件和密码不起作用

qcbq4gxm  于 2023-01-06  发布在  Flutter
关注(0)|答案(1)|浏览(228)

我在创建新用户时收到一个错误。我输入电子邮件和密码信息来创建新用户,但当我按下创建帐户按钮时,没有新用户添加到firestore,并且控制台中出现一个错误。
错误:enter image description here手势捕获异常处理手势时引发以下TypeErrorImpl:意外的空值。
创建帐户表格代码如下:

import 'package:ajanda_flutter/pages/main_page.dart';
import 'package:ajanda_flutter/widgets/input_decorator.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';

class CreateAccountForm extends StatelessWidget {
  const CreateAccountForm({
    Key? key,
    required TextEditingController emailTextController,
    required TextEditingController passwordTextController,
    GlobalKey<FormState>? formKey,
  })  : _emailTextController = emailTextController,
        _passwordTextController = passwordTextController,
        _globalKey = formKey,
        super(key: key);

  final TextEditingController _emailTextController;
  final TextEditingController _passwordTextController;
  final GlobalKey<FormState>? _globalKey;

  @override
  Widget build(BuildContext context) {
    return Form(
      key: _globalKey,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
              'Please enter a valid e-mail and password that is at least 6 character.'),
          Padding(
            padding: const EdgeInsets.all(15.0),
            child: TextFormField(
              validator: (value) {
                return value!.isEmpty ? 'Please enter an e-mail' : null;
              },
              controller: _emailTextController,
              decoration: buildInputDecoration('e-mail', 'idil@gmail.com'),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(15.0),
            child: TextFormField(
              validator: (value) {
                return value!.isEmpty ? 'Please enter a password' : null;
              },
              obscureText: true,
              controller: _passwordTextController,
              decoration: buildInputDecoration('password', ''),
            ),
          ),
          SizedBox(
            height: 20,
          ),
          TextButton(
              style: TextButton.styleFrom(
                  primary: Colors.white,
                  padding: EdgeInsets.all(15),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(4)),
                  backgroundColor: Colors.deepPurple,
                  textStyle: TextStyle(fontSize: 15)),
              onPressed: () {
                if (_globalKey!.currentState!.validate()) {
                  FirebaseAuth.instance
                      .createUserWithEmailAndPassword(
                          email: _emailTextController.text,
                          password: _passwordTextController.text)
                      .then((value) => print(value.user!.uid));
                }
              }, 
              child: Text('Sign Up')) 
        ],
      ),
    );
  }
}**
11dmarpk

11dmarpk1#

你已经使用了一个手势图像,为此你必须添加图像的描述以继续前进。

相关问题