Style Flutter Autocomplete match TextFormField widget visually?

Viewed 39

I am having issues styling my Autocomplete widget to match and fit in with my TextFormField Widget:

enter image description here

I have a couple of issues:

  1. Cant get hint text to show up

  2. Icon looks like it has some invisible padding on it on the left side

              TextFormField(
            controller: manufacturerController,
            decoration: const InputDecoration(
              icon: Icon(Icons.store),
              hintText: 'Manufacturer',
              labelText: 'Manufacturer',
            ),
          ),
          InputDecorator(
            decoration: const InputDecoration(
              prefixIcon: Icon(Icons.style),
              hintText: 'Item Category',
              //labelText: 'Item Category',
              border: InputBorder.none,
            ),
            child: Autocomplete<String>(
              optionsBuilder: (TextEditingValue textEditingValue) {
                if (textEditingValue.text == '') {
                  return const Iterable<String>.empty();
                }
                return itemTypeList.where((String option) {
                  return option
                      .contains(textEditingValue.text.toLowerCase());
                });
              },
              onSelected: (String selection) {
                debugPrint('You just selected $selection');
              },
            ),
    
1 Answers

Try below code in your code you have set Textfield widget icon and AutoComplete widget prefixIcon. Refer InputDecoration

Column(
  children: [
    TextFormField(
      controller: manufacturerController,
      decoration: const InputDecoration(
        icon: Icon(Icons.store),//with icon
        // prefixIcon: Icon(Icons.store), //with prefixIcon
        hintText: 'Manufacturer',
        labelText: 'Manufacturer',
      ),
    ),
    InputDecorator(
      decoration: const InputDecoration(
        icon: Icon(Icons.style),//with icon
        //prefixIcon: Icon(Icons.style), //with prefixIcon
        hintText: 'Item Category',
        //labelText: 'Item Category',
        border: InputBorder.none,
      ),
      child: Autocomplete<String>(
        optionsBuilder: (TextEditingValue textEditingValue) {
          if (textEditingValue.text == '') {
            return const Iterable<String>.empty();
          }
          return itemTypeList.where((String option) {
            return option.contains(textEditingValue.text.toLowerCase());
          });
        },
        onSelected: (String selection) {
          debugPrint('You just selected $selection');
        },
      ),
    ),
  ],
),

Result Screen With icon-> image

Result Screen With prefixIcon-> image2

Related