Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 登录页面状态的断言问题失败_Android_Flutter_Dart_Firebase Authentication - Fatal编程技术网

Android 登录页面状态的断言问题失败

Android 登录页面状态的断言问题失败,android,flutter,dart,firebase-authentication,Android,Flutter,Dart,Firebase Authentication,生成登录页时抛出了以下断言(脏,状态:_loginpagentate35;bf00d): 必须向文本小部件提供非空字符串。 'package:flatter/src/widgets/text.dart': 断言失败:第360行位置10:“数据!”空' 我有此错误,text.dart中似乎没有问题 这是我的登录页面 我找不到问题 import 'package:flutter/material.dart'; import 'package:sporprojesi/login/primary_but

生成登录页时抛出了以下断言(脏,状态:_loginpagentate35;bf00d): 必须向文本小部件提供非空字符串。 'package:flatter/src/widgets/text.dart': 断言失败:第360行位置10:“数据!”空'

我有此错误,text.dart中似乎没有问题

这是我的登录页面

我找不到问题

import 'package:flutter/material.dart';
import 'package:sporprojesi/login/primary_button.dart';
import 'package:sporprojesi/login/signin.dart';



class LoginPage extends StatefulWidget {
  LoginPage({Key key, this.title, this.auth, this.onSignIn}) : super(key: key);

  final String title;
  final BaseAuth auth;
  final VoidCallback onSignIn;

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

enum FormType {
  login,
  register
}

class _LoginPageState extends State<LoginPage> {
  static final formKey = new GlobalKey<FormState>();

  String _email;
  String _password;
  FormType _formType = FormType.login;
  String _authHint = '';


  @override
  void initState() {

    super.initState();}

  bool validateAndSave() {
    final form = formKey.currentState;
    if (form.validate()) {
      form.save();
      return true;
    }
    return false;
  }

  void validateAndSubmit() async {
    if (validateAndSave()) {
      try {
        String userId = _formType == FormType.login
            ? await widget.auth.signIn(_email, _password)
            : await widget.auth.createUser(_email, _password);
        setState(() {
          _authHint = 'Signed In\n\nUser id: $userId';
        });
        widget.onSignIn();
      }
      catch (e) {
        setState(() {
          _authHint = 'Sign In Error\n\n${e.toString()}';
        });
        print(e);
      }
    } else {
      setState(() {
        _authHint = '';
      });
    }
  }

  void moveToRegister() {
    formKey.currentState.reset();
    setState(() {
      _formType = FormType.register;
      _authHint = '';
    });
  }

  void moveToLogin() {
    formKey.currentState.reset();
    setState(() {
      _formType = FormType.login;
      _authHint = '';
    });
  }

  List<Widget> usernameAndPassword() {
    return [
      padded(child: new TextFormField(
        key: new Key('email'),
        decoration: new InputDecoration(labelText: 'Email'),
        autocorrect: false,
        validator: (val) => val.isEmpty ? 'Email can\'t be empty.' : "",
        onSaved: (val) => _email = val,
      )),
      padded(child: new TextFormField(
        key: new Key('password'),
        decoration: new InputDecoration(labelText: 'Password'),
        obscureText: true,
        autocorrect: false,
        validator: (val) => val.isEmpty ? 'Password can\'t be empty.' : "",
        onSaved: (val) => _password = val,
      )),
    ];
  }

  List<Widget> submitWidgets() {
    switch (_formType) {
      case FormType.login:
        return [
          new PrimaryButton(
              key: new Key('login'),
              text: 'Login',
              height: 44.0,
              onPressed: validateAndSubmit
          ),
          new FlatButton(
              key: new Key('need-account'),
              child: new Text("Need an account? Register"),
              onPressed: moveToRegister
          ),
        ];
      case FormType.register:
        return [
          new PrimaryButton(
              key: new Key('register'),
              text: 'Create an account',
              height: 44.0,
              onPressed: validateAndSubmit
          ),
          new FlatButton(
              key: new Key('need-login'),
              child: new Text("Have an account? Login"),
              onPressed: moveToLogin
          ),
        ];
    }
    return null;
  }

  Widget hintText() {
    return new Container(
      //height: 80.0,
        padding: const EdgeInsets.all(32.0),
        child: new Text(
            _authHint,
            key: new Key('hint'),
            style: new TextStyle(fontSize: 18.0, color: Colors.grey),
            textAlign: TextAlign.center)
    );
  }


  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text(widget.title),
        ),
        backgroundColor: Colors.grey[300],
        body: new SingleChildScrollView(child: new Container(
            padding: const EdgeInsets.all(16.0),
            child: new Column(
                children: [
                  new Card(
                      child: new Column(
                          mainAxisSize: MainAxisSize.min,
                          children: <Widget>[
                            new Container(
                                padding: const EdgeInsets.all(16.0),
                                child: new Form(
                                    key: formKey,
                                    child: new Column(
                                      crossAxisAlignment: CrossAxisAlignment.stretch,
                                      children: usernameAndPassword() + submitWidgets(),
                                    )
                                )
                            ),
                          ])
                  ),
                  hintText()
                ]
            )
        ))
    );
  }

  Widget padded({Widget child}) {
    return new Padding(
      padding: EdgeInsets.symmetric(vertical: 8.0),
      child: child,
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“包:sporprojesi/login/primary_button.dart”;
导入“package:sporprojesi/login/signin.dart”;
类LoginPage扩展StatefulWidget{
LoginPage({Key-Key,this.title,this.auth,this.onSignIn}):super(Key:Key);
最后的字符串标题;
最终BaseAuth-auth;
最终无效信号;
@凌驾
_LoginPagentate createState()=>新建;
}
枚举表单类型{
登录,
登记
}
类_loginpagentate扩展状态{
静态final formKey=new GlobalKey();
字符串\u电子邮件;
字符串\u密码;
FormType _FormType=FormType.login;
字符串_authHint='';
@凌驾
void initState(){
super.initState();}
bool validateAndSave(){
最终形式=formKey.currentState;
if(form.validate()){
form.save();
返回true;
}
返回false;
}
void validateAndSubmit()异步{
if(validateAndSave()){
试一试{
字符串userId=\u formType==formType.login
?等待widget.auth.sign(\u电子邮件,\u密码)
:wait widget.auth.createUser(\u电子邮件,\u密码);
设置状态(){
_authHint='已登录\n\n用户id:$userId';
});
onSignIn();
}
捕获(e){
设置状态(){
_authHint='登录错误\n\n${e.toString()}';
});
印刷品(e);
}
}否则{
设置状态(){
_authHint='';
});
}
}
作废移动注册表(){
formKey.currentState.reset();
设置状态(){
_formType=formType.register;
_authHint='';
});
}
void moveToLogin(){
formKey.currentState.reset();
设置状态(){
_formType=formType.login;
_authHint='';
});
}
列出用户名和密码(){
返回[
填充(子项:新TextFormField(
密钥:新密钥(“电子邮件”),
装饰:新输入装饰(标签文本:“电子邮件”),
自动更正:错误,
验证程序:(val)=>val.isEmpty?“电子邮件不能为空。”:“”,
onSaved:(val)=>\u email=val,
)),
填充(子项:新TextFormField(
密钥:新密钥(“密码”),
装饰:新输入装饰(标签文本:“密码”),
蒙昧文字:对,
自动更正:错误,
验证程序:(val)=>val.isEmpty?“密码不能为空。”:“”,
onSaved:(val)=>_password=val,
)),
];
}
列出submitWidgets(){
开关(_formType){
case FormType.login:
返回[
新主按钮(
密钥:新密钥(“登录”),
文本:“登录”,
身高:44.0,
onPressed:validateAndSubmit
),
新扁平按钮(
密钥:新密钥(“需求账户”),
子项:新文本(“需要帐户?注册”),
按下:移动到注册表
),
];
case FormType.register:
返回[
新主按钮(
密钥:新密钥(“寄存器”),
文本:“创建帐户”,
身高:44.0,
onPressed:validateAndSubmit
),
新扁平按钮(
密钥:新密钥(“需要登录”),
子项:新文本(“拥有帐户?登录”),
onPressed:moveToLogin
),
];
}
返回null;
}
小部件hintText(){
退回新货柜(
//身高:80.0,
填充:常数边集全部(32.0),
儿童:新文本(
_authint,
key:newkey('hint'),
样式:新文本样式(字体大小:18.0,颜色:Colors.grey),
textAlign:textAlign.center)
);
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:新文本(widget.title),
),
背景颜色:颜色。灰色[300],
正文:新建SingleChildScrollView(子级:新建容器(
填充:常数边集全部(16.0),
子:新列(
儿童:[
新卡(
子:新列(
mainAxisSize:mainAxisSize.min,
儿童:[
新容器(
填充:常数边集全部(16.0),
儿童:新表格(
key:formKey,
子:新列(
crossAxisAlignment:crossAxisAlignment.stretch,
子项:UserName和Password()+submitWidgets(),
)
)
),
])
),
hintText()
]
)
))
);
}
小部件填充({Widget child}){
返回新的填充(
填充:边缘设置。对称(垂直:8.0),
孩子:孩子,
);
}
}

看起来像是“authHint”为空

修改
hintText
方法,如下所示,其中??操作员使用。类似地,如果需要,您也应该为其他文本小部件创建一个

 Widget hintText() {
    return new Container(
      //height: 80.0,
        padding: const EdgeInsets.all(32.0),
        child: new Text(
            _authHint?? "",
            key: new Key('hint'),
            style: new TextStyle(fontSize: 18.0, color: Colors.grey),
            textAlign: TextAlign.center)
    );
  }

我做了,但我仍然收到同样的问题,你能告诉我它到底失败了哪一行吗包:flatter/src/widgets/text.dart”:失败的断言:第360行第10位:“数据!”空和360。第行是这个断言(data!=null,'必须向文本小部件提供非null字符串',),对吗