DropdownButtonFormField 没有得到重建
DropdownButtonFormField not getting rebuilt
我正在尝试以编程方式更新所选值。
我使用了各种方法,包括 Consumer 等,并确保值已更新并在值更改时调用小部件,但是,DropdownButtonFormField 从未使用最新值重建。
目前,我正在将 DropdownButtonFormField 包装在 StreamBuilder 中,据推测,只要有新事件通过流发送,就应该重建它。这是我的代码:
声明
final StreamController<String> _raceStreamController = new StreamController<String>();
DropdownButtonFormField
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
bug 已修复,请务必升级。
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
我正在尝试以编程方式更新所选值。
我使用了各种方法,包括 Consumer 等,并确保值已更新并在值更改时调用小部件,但是,DropdownButtonFormField 从未使用最新值重建。
目前,我正在将 DropdownButtonFormField 包装在 StreamBuilder 中,据推测,只要有新事件通过流发送,就应该重建它。这是我的代码:
声明
final StreamController<String> _raceStreamController = new StreamController<String>();
DropdownButtonFormField
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
bug 已修复,请务必升级。
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