相关疑难解决方法(0)

如何在flutter中实现下拉列表?

我有一个我希望在Flutter中作为下拉列表实现的位置列表.我对这门语言很陌生.这就是我所做的.

new DropdownButton(
  value: _selectedLocation,
  onChanged: (String newValue) {
    setState(() {
      _selectedLocation = newValue;
     });
},
items: _locations.map((String location) {
  return new DropdownMenuItem<String>(
     child: new Text(location),
  );
}).toList(),
Run Code Online (Sandbox Code Playgroud)

这是我的项目清单:

List<String> _locations = ['A', 'B', 'C', 'D'];
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.

Another exception was thrown: 'package:flutter/src/material/dropdown.dart': Failed assertion: line 468 pos 15: 'value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not true.
Run Code Online (Sandbox Code Playgroud)

我假设值为_selectedLocationnull.但我正在初始化它.

String _selectedLocation = 'Please choose a location';

dart drop-down-menu flutter

33
推荐指数
9
解决办法
5万
查看次数

如何为Flutter中的下拉菜单设置动态高度

我是扑扑发展的新手。我正在使用应用程序的下拉按钮。打开下拉菜单时,文本将在弹出对话框中被剪切。下面我附上了带有编码的屏幕截图。请指导我解决此问题。

                 DropdownButtonHideUnderline(
                  child: new DropdownButton(
                    isExpanded: true,
                    value: dropDownValue,
                    isDense: true,
                    //icon: Icon(Icons.keyboard_arrow_down, color: Colors.white,),
                    onChanged: (String newValue) {
                      setState(() {
                        dropDownValue = newValue;

                        state.didChange(newValue);
                      });
                    },
                    items: dropDownList.map((String value) {
                      return new DropdownMenuItem(

                        value: value,
                          child: new SizedBox(
                          width: MediaQuery.of(context).size.width / 1.4,
                          child: new Text(value,
                          softWrap: true,
                          style: TextStyle(color: Colors.white, fontSize: 18.0),),)
                      );
                    }).toList(),
                  ),
                ),);
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

flutter flutter-layout

4
推荐指数
1
解决办法
495
查看次数

标签 统计

flutter ×2

dart ×1

drop-down-menu ×1

flutter-layout ×1