无法滚动浏览 flutter type advance 包中的建议列表

问题描述 投票:0回答:1
  1. 我的列表中有国家/地区列表当我第一次点击 TextFormField 时,我只能看到屏幕尺寸的一些建议。无法滚动列表中的所有建议。

  2. 建议按降序排列。但我希望它按升序排列,并且应该能够向上滚动以查看所有建议

这是我的代码

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(() {});
            },
          )
flutter scroll flutter-typeahead
1个回答
0
投票

试试这个

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(() {});
  },
)
© www.soinside.com 2019 - 2024. All rights reserved.