如何在 DropdownBelow 中显示不应在其列表中的提示文本

How to show hinttext in DropdownBelow which should not be in its list

我想在 DropdownBelow 中添加 hintText,但它用它的 value 覆盖了它,如果像这样在值中传递空字符串。

 var _selectedCategory = "";

它打印这个错误

'package:dropdown_below/dropdown_below.dart': Failed assertion: line 421 pos 16: 'value == null ||
package:dropdown_below/dropdown_below.dart:1
            items
                    .where((DropdownMenuItem<T> item) => item.value == value)
                    .length ==
                1': is not true.

这意味着你不能传递空值,你必须传递应该在其列表中的值,就像我的下拉列表是这样的,

var categorylist = <String>[
    'Other',];

那么值应该有 Other , var _selectedCategory = "Other";

所以这意味着我不能再使用 hintText。

这是我的下拉代码。

var categorylist = <String>[
    'Other',
  ];

var _selectedCategory = "Other";


Container(
              width: MediaQuery.of(context).size.width * 0.9,
              child: DropdownBelow(
                itemWidth: 370,
                itemTextstyle: TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.w400,
                    color: Colors.black),
                boxTextstyle: TextStyle(
                    //fontSize: 14,
                    fontWeight: FontWeight.w400,
                    color: Colors.black),
                boxPadding: EdgeInsets.fromLTRB(13, 12, 13, 12),
                boxWidth: 370,
                boxHeight: 50,
                boxDecoration: BoxDecoration(
                    color: Colors.transparent,
                    shape: BoxShape.rectangle,
                    borderRadius:
                        new BorderRadius.all(new Radius.circular(10.0)),
                    border: Border.all(width: 1, color: Colors.grey)),
                icon: Icon(
                  Icons.keyboard_arrow_down_outlined,
                  color: Colors.black,
                ),
                hint: Text('Category',
                    style: GoogleFonts.montserrat(
                        color: HexColor("#6e6b7b"), fontSize: 15)),
                value: _selectedCategory,
                items:categorylist.map<DropdownMenuItem<String>>((String value) {
                  return DropdownMenuItem<String>(
                      value: value,
                      child: Text(value,
                          style: GoogleFonts.montserrat(
                            color: HexColor("#6e6b7b"),
                          )));
                }).toList(),
                onChanged: (newValue) {
                  setState(() {
                    this._selectedCategory = newValue.toString();
                    if (this._selectedCategory == "Other") {
                      _newCatgoryFlag = true;
                    } else {
                      _newCatgoryFlag = false;
                    }
                  });
                },
              ),
            ),


输出

这是我 运行 应用程序时得到的结果。

请告诉我哪里做错了。我必须做什么才能显示 hintText

dropDown 在此处获取初始值 value: _selectedCategory 尝试将其删除,您将获得 hintText

但更好的改变

var _selectedCategory = "Other";

String? _selectedCategory;

你什么时候会选择_selectedCategory取代hintText