当我按下“材质”按钮时,会引发错误。该材质按钮在对话框中退出,并且当方法调用具有布尔值并且为true时,我想关闭该对话框。
MaterialButton(
elevation: 5.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
color: Theme.of(context).accentColor,
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Text(
"Save",
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
onPressed: () async{
if (formKey.currentState.validate()) {
bool success =await model.updateProfileInfo(
name:nameController.text,
email:emailController.text,
gender:selectedGender,
phone:phoneController.text,
address:addressController.text);
if(success){
Navigator.pop(context);
}else{
Fluttertoast.showToast(msg: "Something went wrong!");
}
}
},
),
引发了以下错误
E/flutter (22845): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'updateProfileInfo' was called on null.
E/flutter (22845): Receiver: null
E/flutter (22845): Tried calling: updateProfileInfo(address: "test test", email: "test@test.com", gender: "Male", name: "test test", phone: "9800000000")
E/flutter (22845): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (22845): #1 SheetButton.build.<anonymous closure> (package:ghyampay/screens/profile.dart:484:41)
E/flutter (22845): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter (22845): #3 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter (22845): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (22845): #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter (22845): #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter (22845): #7 BaseTapGestureRecognizer.handlePrimaryPointer
按预期的输出是在按下该按钮时调用updateProfileInfo方法。updateProfileInfo是另一个类,否则会抛出编译时错误。