问题描述
我想对FormBuilderDropdown
中的项目进行自动完成。当我写一封信时,项目列表会更改为显示包含该字母的项目。
FormBuilderDropdown(
attribute: 'field_city',decoration: LikpechInputdecoration(_isLoading,'Selectionnez une ville'),items: _buildListCities(),/*initialValue: DropdownMenuItem(
value: _selectedCity,child: Text(_listCities[_selectedCity]['name']),),*/
onChanged: (index) {
setState(() {
_selectedCity = index;
});
fetchAgences(index);
},validators: [
FormBuilderValidators.required(errorText: '')
],) : Center(child: CupertinoActivityIndicator()),
解决方法
使用Typehead插件typehead flutter
import 'package:flutter_typeahead/flutter_typeahead.dart';
.
.
.
TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
autofocus: true,style: DefaultTextStyle.of(context).style.copyWith(
fontStyle: FontStyle.italic
),decoration: InputDecoration(
border: OutlineInputBorder()
)
),suggestionsCallback: (pattern) async {
return await BackendService.getSuggestions(pattern);
},itemBuilder: (context,suggestion) {
return ListTile(
leading: Icon(Icons.shopping_cart),title: Text(suggestion['name']),subtitle: Text('\$${suggestion['price']}'),);
},onSuggestionSelected: (suggestion) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ProductPage(product: suggestion)
));
},)
.
.
.