Flutter Autocomplete如何删除下划线

q1qsirdb  于 2023-03-31  发布在  Flutter
关注(0)|答案(2)|浏览(158)

我的自动完成源代码有一些样式和自定义的下拉列表,因为下拉列表超出了屏幕,因为搜索图标添加到搜索栏:

这几乎就像是自动完成下拉框的顶部边框。无论如何要删除这个边框吗?

Container(
                  height:40.0,
                  padding: EdgeInsets.only(left:10.0,right:10.0),
                  child: InputDecorator(
                    decoration: InputDecoration(
                    prefixIcon: const Icon(Icons.search, size: 25.0,),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(50.0),
                        borderSide: const BorderSide(
                          width: 0,
                          style: BorderStyle.none,
                        ),
                      ),
                      filled: true,
                      hintStyle: TextStyle(color: Colors.grey[800]),
                      hintText: "Type in your text",
                      fillColor: Colors.white,
                      isDense: true,
                      // contentPadding: EdgeInsets.all(0.0),
                  ),
                    child: Autocomplete<String>(
                      optionsBuilder:
                          (TextEditingValue textEditingValue) {
                        if (textEditingValue.text == '') {
                          return const Iterable<String>.empty();
                        }
                        return _kOptions.where((String option) {
                          return option.contains(
                              textEditingValue.text.toLowerCase());
                        });
                      },
                      optionsViewBuilder: ((context, onSelected, options){
                        return Align(
                          alignment: Alignment.topLeft,
                          child: Material(
                            elevation: 4.0,
                            child: ConstrainedBox(
                              constraints: const BoxConstraints(maxHeight: 200, maxWidth: 300), //RELEVANT CHANGE: added maxWidth
                              child: ListView.builder(
                                padding: EdgeInsets.zero,
                                shrinkWrap: true,
                                itemCount: options.length,
                                itemBuilder: (BuildContext context, int index) {
                                  final String option = _kOptions.elementAt(index);
                                  return InkWell(
                                    onTap: () {
                                      onSelected(option);
                                    },
                                    child: Builder(builder: (BuildContext context) {
                                      final bool highlight = AutocompleteHighlightedOption.of(context) == index;
                                      return Container(
                                        color: highlight ? Theme.of(context).focusColor : null,
                                        padding: const EdgeInsets.all(16.0),
                                        child: Text(option),
                                      );
                                    }),
                                  );
                                },
                              ),
                            ),
                          ),
                        );
                      }
                      ),
                    ),
                  ),
                ),
zf2sa74q

zf2sa74q1#

试试这个

Container(
            height:40.0,
            padding: EdgeInsets.only(left:10.0,right:10.0),
            child: InputDecorator(
              decoration: InputDecoration(
                enabledBorder: InputBorder.none,//add this Disabling Underline/Border only when Enabled
focusedBorder: InputBorder.none, //Add this Removing the Underline/Border only when Focused
                border: InputBorder.none, //Add this when
                prefixIcon: const Icon(Icons.search, size: 25.0,),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(50.0),
                  borderSide: const BorderSide(
                    width: 0,
                    style: BorderStyle.none,
                  ),
                ),
                filled: true,
                hintStyle: TextStyle(color: Colors.grey[800]),
                hintText: "Type in your text",
                fillColor: Colors.white,
                isDense: true,
                // contentPadding: EdgeInsets.all(0.0),
              ),
              child: Autocomplete<String>(
                optionsBuilder:
                    (TextEditingValue textEditingValue) {
                  if (textEditingValue.text == '') {
                    return const Iterable<String>.empty();
                  }
                  return _kOptions.where((String option) {
                    return option.contains(
                        textEditingValue.text.toLowerCase());
                  });
                },
                optionsViewBuilder: ((context, onSelected, options){
                  return Align(
                    alignment: Alignment.topLeft,
                    child: Material(
                      elevation: 4.0,
                      child: ConstrainedBox(
                        constraints: const BoxConstraints(maxHeight: 200, maxWidth: 300), //RELEVANT CHANGE: added maxWidth
                        child: ListView.builder(
                          padding: EdgeInsets.zero,
                          shrinkWrap: true,
                          itemCount: options.length,
                          itemBuilder: (BuildContext context, int index) {
                            final String option = _kOptions.elementAt(index);
                            return InkWell(
                              onTap: () {
                                onSelected(option);
                              },
                              child: Builder(builder: (BuildContext context) {
                                final bool highlight = AutocompleteHighlightedOption.of(context) == index;
                                return Container(
                                  color: highlight ? Theme.of(context).focusColor : null,
                                  padding: const EdgeInsets.all(16.0),
                                  child: Text(option),
                                );
                              }),
                            );
                          },
                        ),
                      ),
                    ),
                  );
                }
                ),
              ),
            ),
          ),
sdnqo3pr

sdnqo3pr2#

你可以试试这个。这将创建一个没有下划线的矩形边框的自动补全。

Autocomplete<String>(
  fieldViewBuilder: (BuildContext context,
      TextEditingController fieldTextEditingController,
      FocusNode fieldFocusNode,
      VoidCallback onFieldSubmitted) {
    return TextFormField(
      cursorColor: Colors.white,
      validator: (value) {
        if (value == null || value.isEmpty) {
          return 'Please enter item name';
        }
        return null;
      },
      decoration: const InputDecoration(
        focusedBorder: OutlineInputBorder(
          borderSide: BorderSide(width: 1, color: Colors.white),
        ),
        border: OutlineInputBorder(
          borderSide: BorderSide(width: 1, color: Colors.white),
        ),
        labelText: "Enter Item Name",
        labelStyle: TextStyle(color: Colors.white),
      ),
      controller: fieldTextEditingController,
      focusNode: fieldFocusNode,
    );
  },
  optionsBuilder: (TextEditingValue textEditingValue) {
    if (textEditingValue.text == '') {
      return const Iterable<String>.empty();
    }
    return ["One", "Two", "Three", "Four"];
  },
  onSelected: (selectedValue) {},
);

相关问题