繁体   English   中英

如何在颤动中在 DropdownButton 和 DropdownMenuItem 之间缩进

[英]How to indent between DropdownButton and DropdownMenuItem in flutter

我正在使用DropdownButton并且遇到以下错误。 打开DropdownMenuItem列表时,按钮本身没有缩进。 也就是说,我需要获取按钮(DropdownButton)和下拉列表(DropdownMenuItem)之间的padding ,以便有距离。 但到目前为止,我还无法做到。 你怎么能在他们之间做一个缩进?

代码

@override
  Widget build(BuildContext context) {
    return SizedBox(
      width: widget.width,
      child: DropdownButtonHideUnderline(
        child: DropdownButton2(
          items: List.generate(
            widget.items.length,
            (index) => DropdownMenuItem<String>(
              value: widget.items[index],
              child: Container(
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(
                      color: Colors.white.withOpacity(0.1),
                      width: 1,
                    ),
                  ),
                ),
                child: StatefulBuilder(
                  builder: (context, setStateSB) => GFCheckboxListTile(
                    value: _selectedTitles.contains(widget.items[index]),
                    onChanged: (bool selected) {
                      _onItemSelect(selected, index);
                      setStateSB(() {});
                    },
                    selected: selected,
                    title: Text(
                      widget.items[index],
                      style: constants.Styles.smallTextStyleWhite,
                    ),
                    padding: const EdgeInsets.only(top: 12, bottom: 13),
                    margin: const EdgeInsets.only(right: 0, left: 0),
                    size: 22,
                    activeBgColor: constants.Colors.greyCheckbox,
                    activeBorderColor: constants.Colors.greyXMiddle,
                    inactiveBgColor: constants.Colors.greyCheckbox,
                    activeIcon: SvgPicture.asset(constants.Assets.checkboxIcon),
                    inactiveBorderColor: constants.Colors.greyXMiddle,
                    type: type,
                  ),
                ),
              ),
            ),
          ),
          hint: _selectedTitles.length > 1
              ? const Text('Selecte EV',
                  style: constants.Styles.bigBookTextStyleWhite)
              : Text(_selectedTitles.join().toString(),
                  style: constants.Styles.bigBookTextStyleWhite),
          value: selectedValue,
          onChanged: (value) {
            setState(() {
              selectedValue = value as String;
            });
          },
          icon: SvgPicture.asset(constants.Assets.arrowDropdown),
          iconSize: 21,
          buttonHeight: 27,
          itemHeight: 47,
          dropdownMaxHeight: 185,
          dropdownWidth: 140,
          dropdownDecoration: BoxDecoration(
              borderRadius: BorderRadius.circular(8),
              border: Border.all(
                color: constants.Colors.purpleMain,
              ),
              color: constants.Colors.greyDark),
          selectedItemBuilder: (context) {
            return widget.items.map(
              (item) {
                return Row(
                  children: [
                    widget.icon ?? const SizedBox(),
                    const SizedBox(width: 8),
                    Text(
                      item,
                      style: constants.Styles.bigBookTextStyleWhite,
                    ),
                  ],
                );
              },
            ).toList();
          },
        ),
      ),
    );
  }
}

dropdown_button2文档中,有一个用于移动下拉菜单Offset的属性。 你可以在这里看到它https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/offset.html

在该属性上,您只需要设置一个Offset ,它由XY值组成。

在您的情况下,它看起来像这样:

DropdownButton2(
  offset: Offset(0,10),
  ...
),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM