Flutter I/flatter(8686):引发了另一个异常:NoSuchMethodError:The method';保存';被调用为空

Flutter I/flatter(8686):引发了另一个异常:NoSuchMethodError:The method';保存';被调用为空,flutter,dart,Flutter,Dart,处理手势时引发以下NoSuchMethodError: 对null调用了方法“save”。 收件人:空 已尝试调用:save() 我正在创建一个页面来更新用户注册数据,当我单击“更新”时,会出现此错误,但什么也没有发生。我现在正在学习颤振,还有很多我不知道的,有人能帮我吗 import 'package:flutter/material.dart'; import '../../generated/l10n.dart'; import '../models/user.dart'; import

处理手势时引发以下NoSuchMethodError: 对null调用了方法“save”。 收件人:空 已尝试调用:save()

我正在创建一个页面来更新用户注册数据,当我单击“更新”时,会出现此错误,但什么也没有发生。我现在正在学习颤振,还有很多我不知道的,有人能帮我吗

import 'package:flutter/material.dart';

import '../../generated/l10n.dart';
import '../models/user.dart';
import '../helpers/helper.dart';
import '../elements/BlockButtonWidget.dart';
import '../helpers/app_config.dart' as config;

import 'package:mvc_pattern/mvc_pattern.dart';
import '../repository/user_repository.dart' as repository;

import '../repository/user_repository.dart';

class SettingsController extends ControllerMVC {



  GlobalKey<FormState> loginFormKey;
  GlobalKey<ScaffoldState> scaffoldKey;

  SettingsController() {
    loginFormKey = new GlobalKey<FormState>();
    this.scaffoldKey = new GlobalKey<ScaffoldState>();

  }

  void update(User user) async {
    user.deviceToken = null;
    repository.update(user).then((value) {
      scaffoldKey?.currentState?.showSnackBar(SnackBar(
        content: Text("Atualizado com Sucesso"),
      ));
    });
  }
}

class ProfileSettingsDialog extends StatefulWidget {
  final User user;
  final VoidCallback onChanged;

  ProfileSettingsDialog({Key key, this.user, this.onChanged}) : super(key: key);


  @override
  _ProfileSettingsDialogState createState() => _ProfileSettingsDialogState();


}

class _ProfileSettingsDialogState extends State<ProfileSettingsDialog> {
  GlobalKey<FormState> _profileSettingsFormKey = new GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: Helper.of(context).onWillPop,
      child: Scaffold(
        resizeToAvoidBottomPadding: false,
        body: Stack(
          alignment: AlignmentDirectional.topCenter,
          children: <Widget>[
            Positioned(
              top: 0,
              child: Container(
                width: config.App(context).appWidth(100),
                height: config.App(context).appHeight(29.5),
                decoration: BoxDecoration(color: Theme.of(context).accentColor),
              ),
            ),
            Positioned(
              top: config.App(context).appHeight(29.5) - 120,
              child: Container(
                width: config.App(context).appWidth(84),
                height: config.App(context).appHeight(29.5),
                child: Text(
                  S.of(context).lets_start_with_register,
                  style: Theme.of(context).textTheme.headline2.merge(TextStyle(color: Theme.of(context).primaryColor)),
                ),
              ),
            ),
            Positioned(
              top: config.App(context).appHeight(29.5) - 50,
              child: Container(
                decoration: BoxDecoration(color: Theme.of(context).primaryColor, borderRadius: BorderRadius.all(Radius.circular(10)), boxShadow: [
                  BoxShadow(
                    blurRadius: 50,
                    color: Theme.of(context).hintColor.withOpacity(0.2),
                  )
                ]),
                margin: EdgeInsets.symmetric(
                  horizontal: 20,
                ),
                padding: EdgeInsets.symmetric(vertical: 50, horizontal: 27),
                width: config.App(context).appWidth(88),
//              height: config.App(context).appHeight(55),
                child: Form(

                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      TextFormField(
                        keyboardType: TextInputType.text,
                        onSaved: (input) => widget.user.phone = input,
                        validator: (input) => input.trim().length < 3 ? S.of(context).not_a_valid_phone : null,
                        decoration: InputDecoration(
                          labelText: "Celular",
                          labelStyle: TextStyle(color: Theme.of(context).accentColor),
                          contentPadding: EdgeInsets.all(12),
                          hintText: S.of(context).john_doe,
                          hintStyle: TextStyle(color: Theme.of(context).focusColor.withOpacity(0.7)),
                          prefixIcon: Icon(Icons.person_outline, color: Theme.of(context).accentColor),
                          border: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.2))),
                          focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.5))),
                          enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.2))),
                        ),
                      ),
                      SizedBox(height: 30),
                      TextFormField(
                        keyboardType: TextInputType.text,
                          onSaved: (input) => widget.user.address = input,
                          validator: (input) => input.trim().length < 3 ? S.of(context).not_a_valid_address : null,
                          decoration: InputDecoration(
                          labelText: "Endereço",
                          labelStyle: TextStyle(color: Theme.of(context).accentColor),
                          contentPadding: EdgeInsets.all(12),
                          hintText: 'johndoe@gmail.com',
                          hintStyle: TextStyle(color: Theme.of(context).focusColor.withOpacity(0.7)),
                          prefixIcon: Icon(Icons.alternate_email, color: Theme.of(context).accentColor),
                          border: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.2))),
                          focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.5))),
                          enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.2))),
                        ),
                      ),
                      SizedBox(height: 30),
                      TextFormField(
                          keyboardType: TextInputType.text,
                          onSaved: (input) => widget.user.bio = input,
                          validator: (input) => input.trim().length < 3 ? S.of(context).not_a_valid_biography : null,
                          decoration: InputDecoration(
                          labelText: "Biografia",
                          labelStyle: TextStyle(color: Theme.of(context).accentColor),
                          contentPadding: EdgeInsets.all(12),
                          hintText: 'johndoe@gmail.com',
                          hintStyle: TextStyle(color: Theme.of(context).focusColor.withOpacity(0.7)),
                          prefixIcon: Icon(Icons.alternate_email, color: Theme.of(context).accentColor),
                          border: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.2))),
                          focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.5))),
                          enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).focusColor.withOpacity(0.2))),
                        ),
                      ),

                      SizedBox(height: 30),
                      BlockButtonWidget(
                        text: Text(
                          S.of(context).register,
                          style: TextStyle(color: Theme.of(context).primaryColor),
                        ),
                        color: Theme.of(context).accentColor,

                        onPressed: () {
                          _profileSettingsFormKey.currentState.save();
                          widget.onChanged();
                          Navigator.pop(context);
                          update(currentUser.value);
                              //setState(() {});
                          },
                        //  widget.update(currentUser.value);
                      ),
                      SizedBox(height: 25),
//                      FlatButton(
//                        onPressed: () {
//                          Navigator.of(context).pushNamed('/MobileVerification');
//                        },
//                        padding: EdgeInsets.symmetric(vertical: 14),
//                        color: Theme.of(context).accentColor.withOpacity(0.1),
//                        shape: StadiumBorder(),
//                        child: Text(
//                          'Register with Google',
//                          textAlign: TextAlign.start,
//                          style: TextStyle(
//                            color: Theme.of(context).accentColor,
//                          ),
//                        ),
//                      ),
                    ],
                  ),
                ),
              ),
            ),
      
          ],
        ),
      ),
    );
  }

  InputDecoration getInputDecoration({String hintText, String labelText}) {
    return new InputDecoration(
      hintText: hintText,
      labelText: labelText,
      hintStyle: Theme.of(context).textTheme.bodyText2.merge(
            TextStyle(color: Theme.of(context).focusColor),
          ),
      enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Theme.of(context).hintColor.withOpacity(0.2))),
      focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Theme.of(context).hintColor)),
      floatingLabelBehavior: FloatingLabelBehavior.auto,
      labelStyle: Theme.of(context).textTheme.bodyText2.merge(
            TextStyle(color: Theme.of(context).hintColor),
          ),
    );
  }



}
导入“包装:颤振/材料.省道”;
导入“../generated/l10n.dart”;
导入“../models/user.dart”;
导入“../helpers/helper.dart”;
导入“../elements/BlockButtonWidget.dart”;
将“../helpers/app_config.dart”作为配置导入;
导入“package:mvc_pattern/mvc_pattern.dart”;
导入“../repository/user_repository.dart”作为存储库;
导入“../repository/user_repository.dart”;
类设置Controller扩展了ControllerMVC{
GlobalKey-loginFormKey;
GlobalKey脚手架;
设置控制器(){
loginFormKey=newglobalkey();
this.scaffoldKey=new GlobalKey();
}
无效更新(用户)异步{
user.deviceToken=null;
repository.update(用户)。然后((值){
脚手架钥匙?.currentState?.showSnackBar(SnackBar(
内容:文本(“Atualizado com SUCCESSO”),
));
});
}
}
类配置文件设置Dialog扩展StatefulWidget{
最终用户;
更改后的最终作废;
ProfileSettingsDialog({Key-Key,this.user,this.onChanged}):super(Key:Key);
@凌驾
_ProfileSettingsDialogState createState()=>\u ProfileSettingsDialogState();
}
类_profilesetingsdialogstate扩展状态{
GlobalKey _profilesetingsformkey=newglobalkey();
@凌驾
小部件构建(构建上下文){
返回式示波器(
onWillPop:Helper.of(context).onWillPop,
孩子:脚手架(
resizeToAvoidBottomPadding:false,
主体:堆栈(
对齐:对齐方向.topCenter,
儿童:[
定位(
排名:0,
子:容器(
宽度:config.App(context).appWidth(100),
高度:config.App(context).appHeight(29.5),
装饰:盒子装饰(颜色:主题.of(上下文).accentColor),
),
),
定位(
顶部:config.App(context).appHeight(29.5)-120,
子:容器(
宽度:config.App(context).appWidth(84),
高度:config.App(context).appHeight(29.5),
子:文本(
让我们从注册开始,
样式:Theme.of(context).textTheme.headline2.merge(TextStyle(颜色:Theme.of(context.primaryColor)),
),
),
),
定位(
顶部:config.App(context).appHeight(29.5)-50,
子:容器(
装饰:框装饰(颜色:主题。背景)。原色,边框半径:边框半径。全部(半径。圆形(10)),框阴影:[
箱形阴影(
半径:50,
颜色:Theme.of(context).hintColor.withOpacity(0.2),
)
]),
边距:边缘组。对称(
横向:20,
),
填充:边缘组。对称(垂直:50,水平:27),
宽度:config.App(context).appWidth(88),
//高度:config.App(上下文).appHeight(55),
孩子:表格(
子:列(
crossAxisAlignment:crossAxisAlignment.stretch,
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
TextFormField(
键盘类型:TextInputType.text,
onSaved:(输入)=>widget.user.phone=输入,
验证器:(输入)=>input.trim()。长度<3?S.of(上下文)。无效\u电话:null,
装饰:输入装饰(
标签文字:“Celular”,
labelStyle:TextStyle(颜色:Theme.of(context).accentColor),
contentPadding:EdgeInsets.all(12),
hintText:S.of(上下文).john_doe,
hintStyle:TextStyle(颜色:Theme.of(context).focusColor.withOpacity(0.7)),
前缀:图标(Icons.person\u轮廓,颜色:Theme.of(context.accentColor),
border:OutlineInputBorder(borderSide:borderSide(颜色:Theme.of(context.focusColor.withOpacity(0.2)),
FocusedOrder:OutlineInputBorder(borderSide:borderSide(颜色:Theme.of(context.focusColor.withOpacity(0.5)),
enabledBorder:OutlineInputBorder(borderSide:borderSide(颜色:Theme.of(context.focusColor.withOpacity(0.2)),
),
),
尺寸箱(高度:30),
TextFormField(
键盘类型:TextInputType.text,
onSaved:(输入)=>widget.user.address=输入,
验证器:(输入)=>input.trim()。长度<3?S.of(上下文)。无效地址:null,
装饰:输入装饰(
labelText:“Endereço”,
labelStyle:TextStyle(颜色:Theme.of(context).accentColor),
contentPadding:EdgeInsets.all(12),
hintText:'johndoe@gmail.com',
hintStyle:TextStyle(颜色:Theme.of(context).focusColor.withOpacity(0.7)),
前缀:图标(Icons.alternate_电子邮件,颜色:Theme.of(context.accentColor),
border:OutlineInputBorder(borderSide:borderSide(颜色:Theme.of(context.focusColor.withOpacity(0.2)),
F
    return Form(
        key: _profileSettingsFormKey,
Form(
  key: _profileSettingsFormKey,
  // ...
)