将自定义扩展小部件作为 AlertDialog 内容

时间:2021-05-20 09:28:51

标签: flutter resize flutter-alertdialog

我想将自定义小部件:https://github.com/GotJimmy/accordion 作为 AlertDialog 内容。一般来说,它的工作方式如下:

showAlertDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            scrollable: true,
            title: Text("Select category"),
            content: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  height: MediaQuery.of(context).size.height,
                  width: MediaQuery.of(context).size.width,
                  child: Accordion(
                    maxOpenSections: 1,
                    headerTextStyle: TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold),
                    leftIcon: Icon(Icons.audiotrack, color: Colors.white),
                    children: [
                      AccordionSection(
                        isOpen: true,
                        headerText: 'Introduction',
                        content: Icon(Icons.airplanemode_active, size: 200, color: Colors.amber),
                      ),
                      AccordionSection(
                        isOpen: true,
                        headerText: 'About Us',
                        content: Icon(Icons.airline_seat_flat, size: 120, color: Colors.blue[200]),
                      ),
                      AccordionSection(
                        isOpen: true,
                        headerText: 'Company Info',
                        content: Icon(Icons.airplay, size: 70, color: Colors.green[200]),
                      ),
                      AccordionSection(
                        isOpen: true,
                        headerText: 'Contact',
                        content: Icon(Icons.contact_page, size: 300, color: Colors.grey),
                      ),
                      AccordionSection(
                        isOpen: false,
                        headerText: 'Technical Jobs',
                        content: Icon(Icons.computer, size: 200, color: Colors.amber),
                      ),
                      AccordionSection(
                        isOpen: false,
                        headerText: 'Administrative Jobs',
                        content: Icon(Icons.emoji_people, size: 200, color: Colors.amber),
                      ),
                      AccordionSection(
                        isOpen: false,
                        headerText: 'Culture',
                        content: Icon(Icons.calculate_rounded, size: 200, color: Colors.green),
                      ),
                      AccordionSection(
                        isOpen: false,
                        headerText: 'Community',
                        content: Icon(Icons.commute_outlined, size: 200, color: Colors.blueAccent),
                      ),
                      AccordionSection(
                        isOpen: false,
                        headerText: 'Friends Of Us',
                        content: Icon(Icons.child_friendly, size: 200, color: Colors.red),
                      ),
                      AccordionSection(
                        isOpen: false,
                        headerText: 'Map',
                        content: Icon(Icons.map, size: 200, color: Colors.blue),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          );
        });
  }

但是,我对此并不满意。当项目展开/折叠时,我想强制警报对话框适合子小部件的高度,以避免可扩展列表下方的多余空白空间 - 需要时应在展开/折叠组上更改对话框大小,如果没有空间显示所有项目,则显示滚动条.这就是我现在得到的:

enter image description here

有什么想法吗?

0 个答案:

没有答案