我的列表中有国家/地区列表当我第一次点击 TextFormField 时,我只能看到屏幕尺寸的一些建议。无法滚动列表中的所有建议。
建议按降序排列。但我希望它按升序排列,并且应该能够向上滚动以查看所有建议
这是我的代码
TypeAheadField(
controller: mrQuestionKeyNameAndControllerMap![list[index].keyName],
itemSeparatorBuilder: (context, index) {
return const Divider(
color: Colors.black,
);
},
direction: VerticalDirection.up,
emptyBuilder: (context) {
return Container(
height: 0.0,
width: 0.0,
);
},
suggestionsCallback: (pattern) async {
return getSuggestionsForCountry(pattern);
},
itemBuilder: (context, String suggestion) {
return Padding(padding: EdgeInsets.fromLTRB(20, 20, 20, 20), child: Text(suggestion));
},
onSelected: (String value) {
mrQuestionKeyNameAndControllerMap![list[index].keyName]!.text = value;
int countryId = 0;
String countryName = mrQuestionKeyNameAndControllerMap![list[index].keyName]!.text;
allCountryList.forEach((element) {
if (element.countryName == countryName) {
countryId = element.id;
}
});
districtNamesList.clear();
allDistrictList.forEach((element) {
if (element.countryId == countryId) {
districtNamesList.add(element.districtName);
}
});
setState(() {});
},
)
试试这个
TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
controller: mrQuestionKeyNameAndControllerMap![list[index].keyName],
decoration: InputDecoration(
labelText: list[index].question,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
),
suggestionsCallback: (pattern) async {
return getSuggestionsForCountry(pattern).then((suggestions) {
return suggestions..sort((a, b) => a.compareTo(b));
});
},
itemBuilder: (context, String suggestion) {
return Expanded(
child: ListTile(
title: Text(suggestion),
),
);
},
onSuggestionSelected: (String value) {
mrQuestionKeyNameAndControllerMap![list[index].keyName]!.text = value;
int countryId = 0;
String countryName = mrQuestionKeyNameAndControllerMap![list[index].keyName]!.text;
allCountryList.forEach((element) {
if (element.countryName == countryName) {
countryId = element.id;
}
});
districtNamesList.clear();
allDistrictList.forEach((element) {
if (element.countryId == countryId) {
districtNamesList.add(element.districtName);
}
});
setState(() {});
},
)