Flutter dropdown menu with ListTiles and row of Buttons

青春壹個敷衍的年華 提交于 2020-04-17 22:23:59

问题


I'm trying to build out a custom dropdown menu that looks like this:

I've managed to implement the ListTiles and Row of Buttons without the dropdown, but I'm not sure how to nest all of that within a dropdown menu class. This is what I've got so far:

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: Drawer(),
      body: SizedBox.expand(
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              ListTile(
                onTap: () {},
                leading: CircleAvatar(backgroundColor: Colors.primaries[0]),
                title: Text('All Circles'),
              ),
              Divider(color: Colors.grey.shade400, indent: 72.0, height: 1.0),
              ListTile(
                onTap: () {},
                leading: CircleAvatar(backgroundColor: Colors.primaries[1]),
                title: Text('Pickup'),
              ),
              Divider(color: Colors.grey.shade400, indent: 72.0, height: 1.0),
              ListTile(
                onTap: () {},
                leading: CircleAvatar(backgroundColor: Colors.primaries[2]),
                title: Text('Kappa Delta'),
              ),
              Divider(color: Colors.grey.shade400, indent: 72.0, height: 1.0),
              ListTile(
                onTap: () {},
                leading: CircleAvatar(backgroundColor: Colors.primaries[3]),
                title: Text('Ok Boomer'),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  RaisedButton(
                    child: Text("Join a Circle"),
                    color: Color(0xffb74093),
                    shape: RoundedRectangleBorder(
                      borderRadius: new BorderRadius.circular(18.0),
                      side: BorderSide(color: Colors.red),
                    ),
                  ),
                  RaisedButton(
                    child: Text("Create a Circle"),
                    color: Colors.red,
                    textColor: Colors.white,
                    shape: RoundedRectangleBorder(
                      borderRadius: new BorderRadius.circular(18.0),
                      side: BorderSide(color: Colors.red),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

回答1:


this is very simple first create a drop-down menu widget and then give your widget to a drop-down menu item

like this

give value to each drop-down item according to your objects array

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 ListTile(
            onTap: () {},
            leading: CircleAvatar(backgroundColor: Colors.primaries[0]),
            title: Text(value),
          );
  })
  .toList(),

);



来源:https://stackoverflow.com/questions/60358034/flutter-dropdown-menu-with-listtiles-and-row-of-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!