flutter - DropdownButtonFormField 没有得到重建
问题描述
我正在尝试以编程方式更新选定的值。
我使用了各种方法,包括 Consumer 等,并确保更新值并在值更改时调用小部件,但是,DropdownButtonFormField 从未使用最新值重建。
目前,我将 DropdownButtonFormField 包装在 StreamBuilder 中,据推测,只要有通过流发送的新事件,它就应该重建。这是我的代码:
宣言
final StreamController<String> _raceStreamController = new StreamController<String>();
下拉按钮表单字段
return
StreamBuilder<String>(
stream: _raceStreamController.stream,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
return new DropdownButtonFormField<String>(
value: snapshot.data,
hint: new Text(hint,
textAlign: TextAlign.center),
isExpanded: true,
items: items.map((String value) {
return new DropdownMenuItem<String>(
child: new Text(value),
value: value
);
}).toList(),
validator: (value) => value == null ? 'field required' : null,
onChanged: (value) {} // no use for now,
);
});
推送数据
onFocusChange: (focus) async {
if (!focus) {
try{
await userBloc.searchUser(controller.text.toUpperCase());
_raceStreamController.sink.add(userBloc.user.race);
} catch(e) {
if (e.toString() == ERROR_UNAUTHORISED)
navigateToRoot(context);
}
}
}
我试图删除尽可能多的冗余代码。
谢谢你。
解决方案
在 Flutter 1.17.2 版本中,该DropdownButtonFormField
错误已得到修复,因此请务必升级。
Github 问题:https ://github.com/flutter/flutter/issues/56898
在 1.17.2 版本中修复:https ://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel#1172-may-28-2020
推荐阅读
- java - java客户端调用python服务器报错org.apache.thrift.TApplicationException: Internal error
- docker - Dockerfile 找不到复制的文件夹
- batch-file - 批量使用 VBScript 中的变量
- django - 如何在 Django 中使用 form_validate() 和 CustomForm
- reactjs - 编写需要来自其他操作的数据的 redux 操作的最佳方法是什么
- node.js - Sequelize.js.如何在 findAndCountAll 函数中使用包含顺序?
- json - 无法打印多行json字符串的所有值
- python - imread() 中的图像变量
- apostrophe-cms - 带撇号-cms 的静态图像
- asp.net-web-api - 我应该使用哪种 AAD 应用程序类型?