使用带有抖动的自动完成文本字段包添加光标

时间:2020-04-30 10:53:28

标签: flutter dart textfield

此刻,我正在Flutter应用程序的appBar中使用Autocomplete TextField包(可通过放大镜图标切换)来构建搜索栏。搜索栏在json文件中查找数据。这是我的搜索栏代码:

_searchTextField = AutoCompleteTextField<Fruit>(
  controller: _searchBarController,
  decoration: InputDecoration(
    hintText: 'Find your fruit here...',
    border: InputBorder.none,
    fillColor: Colors.white,
    contentPadding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
    filled: true,
  ),
  itemBuilder: (context, item) {
    return Padding(
      padding: EdgeInsets.only(
        top: 5.0,
        left: 10.0,
        right: 10.0,
        bottom: 5.0,
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            item.name,
            style: kSearchBarTextStyle,
          ),
          SizedBox(height: 2.0),
          Row(
            children: <Widget>[
              Text(
                item.variety,
                style: kSectionSubtitleTextStyle,
              ),
              SizedBox(width: 10.0),
              Text(
                item.country,
                style: kSectionSubtitleTextStyle,
              ),
            ],
          ),
          SizedBox(height: 2.0),
          Row(
            children: <Widget>[
              Text(
                item.colour,
                style: kSectionSubtitleTextStyle,
              ),
            ],
          ),
        ],
      ),
    );
  },
  itemFilter: (item, query) {
    return item.searchTerm.toLowerCase().contains(query.toLowerCase());
  },
  itemSorter: (a, b) {
    return a.searchTerm.compareTo(b.searchTerm);
  },
  itemSubmitted: (item) {
    setState(() {
      _searchTextField.textField.controller.text = item.name;
      country = item.country;
      colour = item.colour;
      name = item.name;
      variety = item.variety;
    });
  },
  key: key,
  suggestions: FruitsViewModel.fruits,
  clearOnSubmit: false,
);

我的问题是,此软件包似乎不允许我在标准TextField所在的位置添加光标。理想情况下,我希望能够添加它并控制其大小和样式。目前,由于没有光标,因此无法知道用户是否可以开始搜索。有谁知道如何使用此程序包添加游标?还是可能建议另一个行为完全相同但有游标的软件包?谢谢。

0 个答案:

没有答案