【问题标题】:Open DropDown below the selected value flutter在所选值flutter下方打开DropDown
【发布时间】:2021-04-16 03:45:03
【问题描述】:

我需要在所选值下方显示下拉菜单。我们如何像在android中一样在flutter中设置Dropdown垂直偏移量。有没有创建自定义下拉菜单的简单方法?附上图片和

这是我的下拉代码:

  Container(
             width: percentWidth(77, context),
                                  padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
                                  child: DropdownButton<String>(
                                    isExpanded: true,
                                    value: state.selectedSubject,
                                    underline: Container(
                                      height: 1.0,
                                      decoration: const BoxDecoration(
                                          border: Border(
                                              bottom: BorderSide(
                                                  color: Colors.transparent,
                                                  width: 0.0))),
                                    ),
                                    icon: Icon(Icons.arrow_drop_down),
                                    iconSize: 0,
                                    elevation: 16,
                                    style: TextStyle(color: Colors.black, fontSize: 15),
                                    onChanged: (String data) {
                                      _userFeedbackBloc
                                          .add(UserFeedbackEvent.onDropDownChanged(data));
                                    },
                                    items: spinnerItems.map<DropdownMenuItem<String>>(
                                            (String newValue) {
                                          return DropdownMenuItem<String>(
                                            value: newValue,
                                            child: Text(newValue),
                                          );
                                        }).toList(),
                                  ),
                                ),

【问题讨论】:

    标签: flutter


    【解决方案1】:

    啊,这里用offset我的朋友。

    offset: Offset(0, 100),
    

    把那个好的 Offset 放在 PopupMenuButton 里面

    【讨论】:

    • 我应该使用 PopupMenuButton 而不是 DropdownButton??
    • 是的,但它需要一个小的自定义来显示选定的值,就像 DropdownButton 一样。
    • 谢谢..我会试试的。
    • @DwiKurniantoM 你能帮我在哪里设置 DropDownButton 类中的 PopupMenuButton 吗?
    【解决方案2】:

    您可以使用 CustomDropDown

    https://github.com/DhavalRKansara/CustomDropDown/blob/main/custom_drop_down.dart

    从上面的行复制代码并过去在 dart 文件中

    然后你可以像下面这样使用它

    CustomDropdownButton(
                      value: _selectedCompany,
                      items: _dropdownMenuItems,
                      onChanged: onChangeDropdownItem,
                    ),
    

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2023-04-05
      • 2020-01-24
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多