我是新手,所以我想知道如何在我的drpdownList上应用onSaved方法。 请帮忙!
Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width*.3,
child: Text('Départ:', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
),
Container(
width: MediaQuery.of(context).size.width*.5,
child: _fieldDropDown(_citiesdept, 0, 'depart'),
// onSaved: (value) => _citiesdept = value,
)
],
),
答案 0 :(得分:0)
这可以解决您的问题吗?
如果要回调小部件,则需要:
更改
_fieldDropDown(List theList, int resultPosition, var dbField) {
// to
_fieldDropDown(List theList, int resultPosition, var dbField, void Function(dynamic newValue) callback) {
在需要时在dropDown中拨打电话...
setState(() {
this.resultsList[resultPosition] = newValue;
// HERE is the callback:
callback(newValue);
state.didChange(newValue);
print(
'The List result = ' + this.resultsList[resultPosition]);
//write newValue to a database field, which can be used in the override init to set the field originally
});
并根据需要使用它,例如...
Container(
width: MediaQuery.of(context).size.width*.5,
child: _fieldDropDown(_citiesdept, 0, 'depart'),
callback: (value) => print(value),