简体   繁体   English

如何制作下拉菜单 Flutter

[英]how to make drop down menu Flutter

how can I make like this drop down menu in flutter??如何在 flutter 中制作这样的下拉菜单?

and how to add any item into that menu??以及如何将任何项目添加到该菜单中?

在此处输入图像描述

There's a Widget called DropDownButton .有一个名为DropDownButtonWidget For more information check out the docs for that Widget.有关更多信息,请查看该小部件的文档 You can add items to the menu by passing a List<DropdownMenuItem<T>> to it's items parameter.您可以通过将List<DropdownMenuItem<T>>传递给它的items参数来将项目添加到菜单中。

DropdownButton<String>(
      value: dropdownValue,
      icon: Icon(Icons.arrow_downward),
      iconSize: 24,
      elevation: 16,
      style: TextStyle(color: Colors.deepPurple),
      underline: Container(
        height: 2,
        color: Colors.deepPurpleAccent,
      ),
      onChanged: (String newValue) {
        setState(() {
          dropdownValue = newValue;
        });
      },
      items: <String>['One', 'Two', 'Free', 'Four']
          .map<DropdownMenuItem<String>>((String value) {
        return DropdownMenuItem<String>(
          value: value,
          child: Text(value),
        );
      }).toList(),
    );

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

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