簡體   English   中英

如何在凸起按鈕上實現下拉菜單

[英]how to implement drop menu on raisedbutton

如果未按下下拉按鈕:

在此處輸入圖像描述

按下放下按鈕時:

在此處輸入圖像描述

您好,如何在這樣的凸起按鈕中實現下拉設計。 誰能幫我?

對於這種情況,您可以檢查ExpansionTile 。此外,您可以使用條件 if 來使用一些 animation 渲染 1 到 n 項。

 bool isExpanded = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LayoutBuilder(
        builder: (context, constraints) => Padding(
          padding: const EdgeInsets.all(8.0),
          child: SingleChildScrollView(
            child: Column(
              children: [
                ListTileTheme(
                    dense: true,
                    contentPadding: EdgeInsets.all(0),
                    child: ExpansionTile(
                      childrenPadding: EdgeInsets.zero,
                      tilePadding: EdgeInsets.zero,
                      title: item(constraints),
                      children: [
                        for (int i = 0; i < 4; i++) item(constraints),
                      ],
                    )),
                Divider(),
                GestureDetector(
                    onTap: () {
                      setState(() {
                        isExpanded = !isExpanded;
                      });
                    },
                    child: item(constraints)),
                if (isExpanded)
                  Column(
                    children: [
                      for (int i = 0; i < 4; i++) item(constraints),
                    ],
                  ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  SizedBox item(BoxConstraints constraints) {
    return SizedBox(
      width: constraints.maxWidth,
      child: Row(
        children: [
          Container(
            width: constraints.maxWidth - 64,
            height: 64,
            decoration: BoxDecoration(border: Border.all()),
            child: Row(
              children: [
                SizedBox(
                  width: 12,
                ),
                Icon(Icons.add),
                SizedBox(
                  width: 24,
                ),
                Text("addd"),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM