gpt4 book ai didi

flutter - AutoCompleteTextField Controller 无法正常工作

转载 作者:行者123 更新时间:2023-12-03 03:37:10 25 4
gpt4 key购买 nike

我遇到了一个问题,我有一个autocompletetextfield可以正常工作,但是当我settext throw controller什么都没发生时,contoller无法正常工作,其他工作正常(数量和价格 Controller )...

例子:

On search itemSubmit

这是我的TextField

AutoCompleteTextField<Services>(
controller: _serviceController,
itemSorter: (Services a, Services b) {
return a.name.compareTo(b.name);
},
decoration: InputDecoration(
fillColor: Colors.white,
labelText: "Service",
filled: true,
),
style: TextStyle(
fontFamily: "Light",
),
suggestions: Services.list,
itemFilter: (Services suggestion, String query) {
return suggestion.name.toLowerCase().startsWith(query.toLowerCase());
},

itemBuilder: (BuildContext context, Services suggestion) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(suggestion.name,
style: TextStyle(
fontSize: 16.0
),
),
],
),
);
},
key: null,

itemSubmitted: (Services data) {
setState(() {
**_serviceController.text = data.name;**
_priceController.text = data.price;
_quantityController.text = data.quantity.toString();
});
},

),

最佳答案

您应该给,只需将GlobalKey分配给AutoCompleteTextField小部件

GlobalKey key = new GlobalKey<AutoCompleteTextFieldState<Services>>();

AutoCompleteTextField<Services>(
controller: _serviceController,
itemSorter: (Services a, Services b) {
return a.name.compareTo(b.name);
},
decoration: InputDecoration(
fillColor: Colors.white,
labelText: "Service",
filled: true,
),
style: TextStyle(
fontFamily: "Light",
),
suggestions: Services.list,
itemFilter: (Services suggestion, String query) {
return suggestion.name.toLowerCase().startsWith(query.toLowerCase());
},

itemBuilder: (BuildContext context, Services suggestion) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(suggestion.name,
style: TextStyle(
fontSize: 16.0
),
),
],
),
);
},
key: key,

itemSubmitted: (Services data) {
setState(() {
_serviceController.text = data.name;
_priceController.text = data.price;
_quantityController.text = data.quantity.toString();
});
},

),

关于flutter - AutoCompleteTextField Controller 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60074936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com