如何解决如何在 OnChanged
我有一个 DropdownButtonFormField,其中最后一项是 DropdownMenuItem,用于使用对话框添加新对象。
Padding(
padding: const EdgeInsets.only(bottom: 15),child: Observer(
builder: (_){
return DropdownButtonFormField(
value: createdContentStore.subjectTitleSelected,isDense: true,decoration: Inputdecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 10),border: OutlineInputBorder()
),onChanged: (value) async {
// print(value);
if(value == 'newSubject'){
Subject newSubject = await showDialog(
context: context,builder: (_) => CreatedSubjectDialogBox(isNewContent: true,)
);
if(newSubject != null){
createdContentStore.setSubjectTitleSelected(newSubject.title);
createdContentStore.setSubject(newSubject);
} else {
// WHAT CAN I DO HERE TO RESET DROP'S VALUE?
}
} else {
createdContentStore.setSubjectTitleSelected(value);
}
},iconSize: 30,hint: Text('Selecione uma matéria'),items: subjectStore.subjectList.map((subject) => DropdownMenuItem(
value: subject.title,child: Text(subject.title),onTap: () {
createdContentStore.setSubject(subject);
},)).toList()..add(DropdownMenuItem(
value: 'newSubject',child: Center(
child: Text(
'Nova Matéria'.toupperCase(),style: TextStyle(color: redRevise),),)),);
},);
当对话框显示时,用户可以创建一个将出现在下拉列表中的新对象。当用户取消对话框时,它会显示最后一个项目。所需的行为是显示提示。
有人可以帮我吗? 谢谢!
解决方法
您所要做的就是从下拉列表中删除值,
DropdownButtonFormField(
//** REMOVE THE VALUE **
isDense: true,decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 10),isDense: true,border: OutlineInputBorder()
),onChanged: (value) async {
if(value == 'newSubject'){
Subject newSubject = await showDialog(
context: context,builder: (_) => CreatedSubjectDialogBox(isNewContent: true,)
);
if(newSubject != null){
createdContentStore.setSubjectTitleSelected(newSubject.title);
createdContentStore.setSubject(newSubject);
} else {
// WHAT CAN I DO HERE TO RESET DROP'S VALUE?
}
} else {
createdContentStore.setSubjectTitleSelected(value);
}
},iconSize: 30,hint: Text('Selecione uma matéria'),items: subjectStore.subjectList.map((subject) => DropdownMenuItem(
value: subject.title,child: Text(subject.title),onTap: () {
createdContentStore.setSubject(subject);
},)).toList()..add(DropdownMenuItem(
value: 'newSubject',child: Center(
child: Text(
'Nova Matéria'.toUpperCase(),style: TextStyle(color: redRevise),),)),);
},);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。