因为我想在“EditProfilePage”类中调用 setState 方法,所以我不得不将其更改为 statefulWidget:
class EditProfilePage extends StatefulWidget {
@override
_EditProfilePageState createState() => _EditProfilePageState();
}
class _EditProfilePageState extends State<EditProfilePage> {
TextEditingController nameController = new TextEditingController();
TextEditingController bioController = new TextEditingController();
File file;
.
.
.
applyChanges() {
Firestore.instance
.collection('insta_users')
.document(currentUserModel.id)
.updateData({
"displayName": nameController.text,
"bio": bioController.text
});
}
}
但是现在,我的类“Profile_page”似乎错过了“EditProfilePage”的方法“applyChanges()”并引发以下错误:
没有为类“EditProfilePage”定义方法“applyChanges”。
这是'Profile_Page'中的方法,它从'EditProfilePage'调用applyChanges():
editProfile() {
EditProfilePage editPage = new EditProfilePage();
Navigator.of(context)
.push(new MaterialPageRoute<bool>(builder: (BuildContext context) {
return new Center(
child: new Scaffold(
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(Icons.close),
onPressed: () {
Navigator.maybePop(context);
},
),
title: new Text('Edit Profile',
style: new TextStyle(
color: Colors.black, fontWeight: FontWeight.bold)),
elevation: 1.0,
backgroundColor: Colors.white,
actions: <Widget>[
new IconButton(
icon: new Icon(
Icons.check,
color: Colors.blueAccent,
),
onPressed: () {
editPage.applyChanges();
Navigator.maybePop(context);
})
有关如何解决此问题的任何建议?我没有忘记导入。
顺便说一句,我对扑腾很陌生,只是想了解飞镖。此致!