如何修复“引发了另一个异常:NoSuchMethodError:在空值上调用了吸气剂'值'”错误

时间:2019-08-29 16:25:36

标签: flutter dart

我试图为我的应用程序创建一个注册页面,但是当我加载页面时出现此错误

我正在Visual Studio代码中使用Flutter

Widget build(BuildContext context) {

TextFormField email = new TextFormField(
  validator: (value) {
    Pattern pattern =
        r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
    RegExp regex = new RegExp(pattern);
    if (!regex.hasMatch(value))
      return 'Ingrese un correo valido';
    else
      return null;
  },
  controller: emailcontroller,
  decoration: InputDecoration(
    hintText: 'Email',
    prefixIcon: Icon(Icons.account_circle),
    border: _textFieldBorder,
  ),
  style: TextStyle(),
  textAlign: TextAlign.left,
);

TextFormField name = new TextFormField(
  controller: namecontroller,
  decoration: InputDecoration(
    hintText: 'Nombre',
    prefixIcon: Icon(Icons.person_pin),
    border: _textFieldBorder,
  ),
  style: TextStyle(),
  textAlign: TextAlign.left,
  validator: (value) {
    if (value.isEmpty) {
      return 'Este campo no puede estar vacio';
    } else
      return null;
  },
);

TextFormField cellphone = new TextFormField(
  maxLength: 9,
  controller: phonecontroller,
  decoration: InputDecoration(
    hintText: 'Phone',
    prefixIcon: Icon(Icons.phone),
    border: _textFieldBorder,
  ),
  style: TextStyle(),
  textAlign: TextAlign.left,
);

TextFormField password = new TextFormField(
  controller: passwordcontroller,
  obscureText: true,
  decoration: InputDecoration(
    hintText: 'Contraseña',
    prefixIcon: Icon(Icons.lock),
    border: _textFieldBorder,
  ),
  style: TextStyle(),
  textAlign: TextAlign.left,
);

TextFormField confirmpassword = new TextFormField(
  obscureText: true,
  decoration: InputDecoration(
    hintText: 'Repita la contraseña',
    prefixIcon: Icon(Icons.lock),
    border: _textFieldBorder,
  ),
  style: TextStyle(),
  textAlign: TextAlign.left,
  validator: (value) {
    if (value == passwordcontroller.text) {
      return null;
    } else {
      return 'Las contraseñas no son iguales';
    }
  },
);

return Scaffold(
    appBar: AppBar(
      title: Text(
        'Registro',
        style: TextStyle(fontSize: 35),
      ),
      backgroundColor: Color(0xff2196F3),
      centerTitle: true,
    ),
    body: Mutation(            
        options: MutationOptions(
          document: query,
        ),
        builder: (RunMutation insert, QueryResult result) {              
          return new SingleChildScrollView(
            child: Form(
              key: _formKey,
              child: Center(
                child: Container(
                  height: MediaQuery.of(context).size.height / 1.1,
                  child: Padding(
                    padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
                    child: Column(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        email,
                        SizedBox(height: 8),
                        name,
                        SizedBox(height: 8),
                        cellphone,
                        SizedBox(height: 8),
                        password,
                        SizedBox(height: 8),
                        confirmpassword,
                        Divider(height: 40),
                        GestureDetector(
                          onTap: () {

                            if (_formKey.currentState.validate()) {
                              insert(<String, dynamic>{
                                "name": namecontroller.text,
                                "phone": phonecontroller.text,
                                "password": passwordcontroller.text,
                                "email": emailcontroller.text
                              });

                              Navigator.pop(context);
                            }

                          },
                          child: new Container(
                          height: 50,
                          width: MediaQuery.of(context).size.width / 1.2,
                            decoration: BoxDecoration(
                              color: Color(0xff2196F3),
                              border: Border.all(
                                  width: 1.0, color: Colors.transparent),
                              borderRadius: BorderRadius.all(
                                  Radius.circular(10.0)
                                  ),                                ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              mainAxisSize: MainAxisSize.max,
                              children: <Widget>[
                              Text('Registrarse', style: _loginTextStyle)
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              ),
            ),
          );
        }));
  }

我希望看到注册页面,但我唯一得到的是此错误“引发了另一个异常:NoSuchMethodError:在空值上调用了getter'value'”

1 个答案:

答案 0 :(得分:0)

问题是我使用的是GraphQL客户端,而该客户端使用的是我的小部件实例RegisterPage,并且我试图导航到RegisterPage,但是正确的做法是导航到我的GraphQL客户端RegistarPageGraphQL,然后客户端构建RegisterPage