问题描述
当我在 dropdownMenuItem 中更改所选项目时,我的对话框不会将其更改为我选择的内容。
我有一个下拉菜单,显示客户端可以选择的内容,当我选择其中一个时,所选项目不会显示在字段中,提示会保留在那里。
它以“SERVIÇO:”开头,并在更改项目后保持不变。 变量获取值但在显示中不会改变。
Future<void> _addObraServico(BuildContext context) async {
return showDialog(
context: context,child: new Dialog(
backgroundColor: blueSoftwar,child: new Column(children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),child: Container(
child: Text(
"SERVIÇOS",style: TextStyle(
fontSize: 20,color: Colors.white,),Padding(
padding: const EdgeInsets.all(8.0),child: new Theme(
data: Theme.of(context).copyWith(
canvasColor: orangeSoftwar,child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),borderRadius: BorderRadius.all(Radius.circular(
5.0) // <--- border radius here
),child: DropdownButton<String>(
isExpanded: true,value: obraServicoDropDown,icon: const Icon(
Icons.arrow_downward,style: const TextStyle(color: Colors.white),underline: SizedBox(),onChanged: (String newValue) {
setState(() {
obraServicoDropDown = newValue;
print(obraServicoDropDown);
});
},items: <String>['','SERVICO1','SERVICO2','SERVICO3']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,child: Text(
value,style: TextStyle(
color: Colors.white,fontSize: 20,);
}).toList(),hint: Container(
child: Text(
" SERVIÇO:",style: TextStyle(color: Colors.white,fontSize: 20),textAlign: TextAlign.end,child: new TextField(
style: TextStyle(color: Colors.white,decoration: new InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0)),borderSide: BorderSide(color: Colors.white),border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0)),hintText: "Descrição *",hintStyle: TextStyle(fontSize: 20.0,color: Colors.white),controller: _tDescricaoObra,if (showAlert)
Text(
"Preencha os campos",style: TextStyle(fontSize: 20,color: Colors.red),new FlatButton(
color: Colors.orange,child: new Text(
"CADASTRAR",style: TextStyle(color: Colors.white),onPressed: () {
if (obraServicoDropDown == null || _tDescricaoObra.text.isEmpty) {
showAlert = true;
} else {
ServicoObra servico = new ServicoObra();
servico.servico = obraServicoDropDown;
servico.descricao = _tDescricaoObra.text;
setState(() {
servicos.add(servico);
});
obraServicoDropDown = null;
_tDescricaoObra.clear();
showAlert = false;
Navigator.pop(context);
}
},]),);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)