简体   繁体   English

如何在 Flutter 中创建小部件的下拉列表?

[英]How to create Drop Down list of widget in Flutter?

I'd like to implement a Drop Down button that open a list of other Card.我想实现一个下拉按钮来打开其他卡片的列表。 For example, what happens when we click on "Campionati Appuntati" in these screenshoots:例如,当我们在这些屏幕截图中单击“Campionati Appuntati”时会发生什么:

在此处输入图像描述

在此处输入图像描述

How could I code this in Flutter?我如何在 Flutter 中编写代码?

EDIT: I found ExpansionPanelList that could help me, but I don't know how to code expansionCallback field编辑:我找到了可以帮助我的ExpansionPanelList ,但我不知道如何编写expansionCallback字段

ExpansionPanelList(
        children: [
          ExpansionPanel(
              headerBuilder: (context, isExpanded) {
                return ListTile(
                  title: Text('Click To Expand', style: TextStyle(color: Colors.white),),
                );
              },
              body:ListTile(
                title: Text('Description text',style: TextStyle(color: Colors.black)),
                tileColor: Colors.white,
              ),
            backgroundColor: Colors.green
          ),
        ],
        expansionCallback: (panelIndex, isExpanded) {
         
        },
  )

You can create a state bool to handle expand mode.您可以创建一个状态布尔值来处理扩展模式。

class EXTEst extends StatefulWidget {
  EXTEst({Key? key}) : super(key: key);

  @override
  State<EXTEst> createState() => _EXTEstState();
}

class _EXTEstState extends State<EXTEst> {
  bool _isExpanded = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          ExpansionPanelList(
            children: [
              ExpansionPanel(
                  isExpanded: _isExpanded,
                  headerBuilder: (context, isExpanded) {
                    return ListTile(
                      title: Text(
                        'Click To Expand',
                        style: TextStyle(color: Colors.white),
                      ),
                    );
                  },
                  body: ListTile(
                    title: Text('Description text',
                        style: TextStyle(color: Colors.black)),
                    tileColor: Colors.white,
                  ),
                  backgroundColor: Colors.green),
            ],
            expansionCallback: (panelIndex, isExpanded) {
              debugPrint(isExpanded.toString());
              setState(() {
                _isExpanded = !isExpanded;
              });
            },
          ),
        ],
      ),
    );
  }
}

More about ExpansionPanel更多关于ExpansionPanel

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

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