在Flutter自适应容器中创建6个按钮框

vu8f3i0k  于 2023-01-02  发布在  Flutter
关注(0)|答案(2)|浏览(137)

我需要根据图像创建一个用户界面,使其具有自适应性,并在两侧填充。我需要提示的最佳方式来做到这一点。我尝试使用一列和两行,但它没有正确的填充。我应该用GridView.builder吗?

child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              menuButtom(
                  icon: (CustomIcons.play_circled2)),
              menuButtom(
                  icon: (CustomIcons.editar)),
              menuButtom(
                  icon: (CustomIcons.apagar))
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              menuButtom(
                  icon: (CustomIcons.favorite_border)),
              menuButtom(
                  icon: (CustomIcons.anotacao)),
              menuButtom(
                  icon: (CustomIcons.duvidas))
            ],
          ),
        ],
      ),
ryevplcw

ryevplcw1#

您可以创建Padding小部件,并将您的Column作为子部件。

Padding(
    padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
    child: Column(
               ...
cigdeys3

cigdeys32#

使用具有所需间距和填充的Gridview.builder

return Scaffold(
      backgroundColor: Colors.grey.shade100,
      body: SafeArea(
        child: GridView.builder(
          padding: const EdgeInsets.all(16),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            // number of items per row
            crossAxisCount: 3,
            // vertical spacing between the items
            mainAxisSpacing: 10,
            // horizontal spacing between the items
            crossAxisSpacing: 10,
          ),
          // number of items in your list
          itemCount: 6,
          itemBuilder: (context, index) {
            switch (index) {
              case 0:
                return Card(
                  child: IconButton(
                      onPressed: () {},
                      icon: const Icon(Icons.play_circle_fill)),
                );
              case 1:
                return Card(
                  child: IconButton(
                      onPressed: () {}, icon: const Icon(Icons.home)),
                );
              case 2:
                return Card(
                  child: IconButton(
                      onPressed: () {}, icon: const Icon(Icons.edit)),
                );
              case 3:
                return Card(
                  child: IconButton(
                      onPressed: () {},
                      icon: const Icon(Icons.menu_book_outlined)),
                );
              case 4:
                return Card(
                  child: IconButton(
                      onPressed: () {}, icon: const Icon(Icons.favorite)),
                );
              case 5:
                return Card(
                  child: IconButton(
                      onPressed: () {},
                      icon: const Icon(Icons.edit_note_sharp)),
                );
              case 6:
                return Card(
                  child: IconButton(
                      onPressed: () {}, icon: const Icon(Icons.help)),
                );

              default:
            }
            return null;
          },
        ),
      ),
    );

输出:

相关问题