flutter-autocomplete-textfield icon indicating copy to clipboard operation
flutter-autocomplete-textfield copied to clipboard

Cursor disappears when using the plugin inside an app bar

Open jgolding94 opened this issue 5 years ago • 1 comments

I've implemented this package in my app. it is toggle-able inside my app bar (i.e. it replaces the text title when the user clicks on a search icon button, and is replaced by the text title when the user clicks the 'X' button.

I've noticed though that when inside the app bar, the cursor has complete disappeared. I don't know if it is because it is inside the app bar and therefore a bug in the package, or if I have possibly, somehow, 'turned it off' via my own implementation mistake.

Below is my implementation of the package. Hopefully there's a simple solution, since it isn't user-friendly to have a textfield without a cursor. Thanks!

_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,
);

jgolding94 avatar May 01 '20 07:05 jgolding94

Just as an update, I've noticed that the cursor is present on the Android simulator, but not the iOS simulator. Either way, there is seemingly no way to style it. Could it be an iOS-related bug? Is there any way to style the cursor?

jgolding94 avatar May 01 '20 15:05 jgolding94