如何在Flutter中实现自定义下拉菜单项?

时间:2019-08-13 22:03:23

标签: flutter drop-down-menu dropdown flutter-layout

弹出菜单似乎为下拉菜单项分配了默认的填充。因此,我无法在模型中实现示例UI。

Widget buildCustomFormDropDown() {
  return FormField<String>(
    builder: (FormFieldState<String> state) {
      return ButtonTheme(
        alignedDropdown: true,
        child: DropdownButton(
          isExpanded: true,
          hint: Text(
            "University of Study",
            style: TextStyle(color: Colors.white),
          ),
          iconEnabledColor: Colors.white,
          items: <String>[
            'University of Ghana (Legon)',
            'University of Professional Studies',
          ].map((String value) {
            return new DropdownMenuItem<String>(
              value: value,
              child: SizedBox.expand(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(5.0),
                        color: Colors.grey[200],
                      ),padding: const EdgeInsets.all(13.0),
                      child: Text(value, textAlign: TextAlign.start, style: TextStyle(color: Colors.grey[400]),),

                    ),
                  ],
                ),
              ),
            );
          }).toList(),
          onChanged: (String value) {},
        ),
      );
    },
  );
}

这是预期的结果。

https://imgur.com/FjYJvLa.png

0 个答案:

没有答案