Flutter 颤振错误-断言失败:第298行位置10:&x27;数据!=空';:必须向文本小部件提供非空字符串。登录时

Flutter 颤振错误-断言失败:第298行位置10:&x27;数据!=空';:必须向文本小部件提供非空字符串。登录时,flutter,flutter-layout,flutter-web,Flutter,Flutter Layout,Flutter Web,我一直在一个使用RESTAPI登录和注销的小项目中工作。但每当我尝试登录时,我都会出错 [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: 'package:flutter/src/widgets/text.dart': Failed assertion: line 298 pos 10: 'data != null': A non-null String must be provided to a Text wid

我一直在一个使用RESTAPI登录和注销的小项目中工作。但每当我尝试登录时,我都会出错

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: 'package:flutter/src/widgets/text.dart': Failed assertion: line 298 pos 10: 'data != null': A non-null String must be provided to a Text widget.
出于测试目的,我的密码是12345,但当我将密码更改为仅限字符串示例abcd时,当我将密码更改为字符串和数字混合时,会产生相同的错误。这里是颤振登录页面代码谢谢

class LogIn extends StatefulWidget {
  @override
  _LogInState createState() => _LogInState();
}

class _LogInState extends State<LogIn> {
  bool _isLoading = false;
  TextEditingController mailController = TextEditingController();
  TextEditingController passwordController = TextEditingController();
  ScaffoldState scaffoldState;
  _showMsg(msg) { //
    final snackBar = SnackBar(
      content: Text(msg),
      action: SnackBarAction(
        label: 'Close',
        onPressed: () {
          // Some code to undo the change!
        },
      ),
    );
    Scaffold.of(context).showSnackBar(snackBar);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset : false,

      body: Container(
        child: Stack(
          children: <Widget>[
            ///////////  background///////////
            new Container(
              decoration: new BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  stops: [0.0, 0.4, 0.9],
                  colors: [
                    Color(0xFFFF835F),
                    Color(0xFFFC663C),
                    Color(0xFFFF3F1A),
                  ],
                ),
              ),
            ),

            Positioned(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Card(
                      elevation: 4.0,
                      color: Colors.white,
                      margin: EdgeInsets.only(left: 20, right: 20),
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(15)),
                      child: Padding(
                        padding: const EdgeInsets.all(10.0),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            /////////////  Email//////////////

                           TextField(
                              style: TextStyle(color: Color(0xFF000000)),
                              controller: mailController,
                              cursorColor: Color(0xFF9b9b9b),
                              keyboardType: TextInputType.text,
                              decoration: InputDecoration(
                                prefixIcon: Icon(
                                  Icons.account_circle,
                                  color: Colors.grey,
                                ),
                                hintText: "Email",
                                hintStyle: TextStyle(
                                    color: Color(0xFF9b9b9b),
                                    fontSize: 15,
                                    fontWeight: FontWeight.normal),
                              ),
                            ),

                            /////////////// password////////////////////
///passwordController
                            TextField(
                              style: TextStyle(color: Color(0xFF000000)),
                              cursorColor: Color(0xFF9b9b9b),
                              controller: passwordController,
                              obscureText: true,
                              decoration: InputDecoration(
                                prefixIcon: Icon(
                                  Icons.vpn_key,
                                  color: Colors.grey,
                                ),
                                hintText: "Password",
                                hintStyle: TextStyle(
                                    color: Color(0xFF9b9b9b),
                                    fontSize: 15,
                                    fontWeight: FontWeight.normal),
                              ),
                            ),

                            

                            /*TextFormField(
                              controller: passwordController,
                              cursorColor: Colors.white,
                              obscureText: true,
                              style: TextStyle(color: Colors.white70),
                              decoration: InputDecoration(
                                icon: Icon(Icons.lock, color: Colors.white70),
                                hintText: "Password",
                                border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.white70)),
                                hintStyle: TextStyle(color: Colors.white70),
                              ),
                            ),*/
                            /////////////  LogIn Botton///////////////////
                            Padding(
                              padding: const EdgeInsets.all(10.0),
                              child: FlatButton(
                                child: Padding(
                                  padding: EdgeInsets.only(
                                      top: 8, bottom: 8, left: 10, right: 10),
                                  child: Text(
                                    _isLoading? 'Loging...' : 'Login',
                                    textDirection: TextDirection.ltr,
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 15.0,
                                      decoration: TextDecoration.none,
                                      fontWeight: FontWeight.normal,
                                    ),
                                  ),
                                ),
                                color: Color(0xFFFF835F),
                                disabledColor: Colors.grey,
                                shape: new RoundedRectangleBorder(
                                    borderRadius:
                                    new BorderRadius.circular(20.0)),
                                onPressed: _isLoading ? null : _login,

                              ),
                            ),
                          ],
                        ),
                      ),
                    ),

                    ////////////   new account///////////////
                    Padding(
                      padding: const EdgeInsets.only(top: 20),
                      child: InkWell(
                        onTap: () {
                          Navigator.push(
                              context,
                              new MaterialPageRoute(
                                  builder: (context) => SignUp()));
                        },
                        child: Text(
                          'Create new Account',
                          textDirection: TextDirection.ltr,
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 15.0,
                            decoration: TextDecoration.none,
                            fontWeight: FontWeight.normal,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  void _login() async{
    setState(() {
      _isLoading = true;
    });


    var data = {
      'email' : mailController.text,
      'password' : passwordController.text
    };

    var res = await CallApi().postData(data, 'login');
    var body = json.decode(res.body);
    if(body['message']==true){ // success to messsage
    //  _showMsg(body['message']);
      print(body['accessToken']); // from token to accessToken
      /*SharedPreferences localStorage = await SharedPreferences.getInstance();
      localStorage.setString('token', body['token']);
     localStorage.setString('user', json.encode(body['user']));*/
      Navigator.push(
          context,
          new MaterialPageRoute(
              builder: (context) => Home()));

    }else{
      _showMsg(body['message']);
    }


    setState(() {
      _isLoading = false;
    });
   

  }

}
类登录扩展StatefulWidget{
@凌驾
_LogInState createState()=>\u LogInState();
}
类_LogInState扩展了状态{
bool_isLoading=false;
TextEditingController mailController=TextEditingController();
TextEditingController密码控制器=TextEditingController();
脚手架状态脚手架状态;
_showMsg(msg){//
最终蛇杆=蛇杆(
内容:文本(msg),
行动:SnackBarAction(
标签:“关闭”,
已按下:(){
//一些代码来撤销更改!
},
),
);
脚手架.of(上下文).showSnackBar(snackBar);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
resizeToAvoidBottomInset:false,
主体:容器(
子:堆栈(
儿童:[
///////////背景///////////
新容器(
装饰:新盒子装饰(
梯度:线性梯度(
开始:Alignment.topLeft,
结束:对齐。右下角,
停止:[0.0,0.4,0.9],
颜色:[
颜色(0xFFFF835F),
颜色(0xFFFC663C),
颜色(0xFFFF3F1A),
],
),
),
),
定位(
孩子:填充(
填充:常数边集全部(8.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
卡片(
标高:4.0,
颜色:颜色,白色,
边距:仅限边集(左:20,右:20),
形状:圆形矩形边框(
边界半径:边界半径。圆形(15)),
孩子:填充(
填充:常数边集全部(10.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
/////////////电子邮件//////////////
文本字段(
样式:TextStyle(颜色:颜色(0xFF000000)),
控制器:邮件控制器,
光标颜色:颜色(0xFF9b9b9b),
键盘类型:TextInputType.text,
装饰:输入装饰(
前缀:图标(
Icons.account_圈,
颜色:颜色。灰色,
),
hintText:“电子邮件”,
hintStyle:TextStyle(
颜色:颜色(0xFF9b9b9b),
尺寸:15,
fontWeight:fontWeight.正常),
),
),
///////////////密码////////////////////
///密码控制器
文本字段(
样式:TextStyle(颜色:颜色(0xFF000000)),
光标颜色:颜色(0xFF9b9b9b),
控制器:密码控制器,
蒙昧文字:对,
装饰:输入装饰(
前缀:图标(
Icons.vpn_键,
颜色:颜色。灰色,
),
hintText:“密码”,
hintStyle:TextStyle(
颜色:颜色(0xFF9b9b9b),
尺寸:15,
fontWeight:fontWeight.正常),
),
),
/*TextFormField(
控制器:密码控制器,
光标颜色:颜色。白色,
蒙昧文字:对,
样式:TextStyle(颜色:Colors.white70),
装饰:输入装饰(
图标:图标(Icons.lock,color:Colors.white70),
hintText:“密码”,
边框:下划线输入边框(borderSide:borderSide(颜色:Colors.white70)),
hintStyle:TextStyle(颜色:Colors.white70),
),
),*/
/////////////登录波顿///////////////////
填充物(
填充:常数边集全部(10.0),
孩子:扁平按钮(
孩子:填充(
填充:仅限边缘设置(
顶部:8,底部:8,左侧:10,右侧:10),
子:文本(
_正在加载?正在登录…:“登录”,
textDirection:textDirection.ltr,
样式:TextStyle(
颜色:颜色,白色,
return response([
            'success' => true,
            'token' =>$token,
            'user' =>$user,
            'message'=>'Successfully Logged In'
        ]);
return response()->json([
            'success' => true,
            'token' =>$token,
            'user' =>$user,
            'message'=>'Successfully Logged In'
        ]);