我的按钮没有随我的图标一起移动 |颤动|飞镖

问题描述 投票:0回答:1

I pressed a button and it is looking wierd

leading: Padding(
          padding:
              const EdgeInsets.only(left: 45.0), // устанавливаем отступ слева
          child: IconButton(
            icon: const Icon(
              Icons.menu,
              color: Colors.white,
            ),
            onPressed: () {},
          ),
        ),
        actions: [
          Padding(
            padding: const EdgeInsets.only(
                right: 45.0), // устанавливаем отступ справа
            child: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.notifications, color: Colors.white),
            ),
          ),
        ],
      ),

请帮忙解决这个问题。我将非常感激!

我尝试添加容器,但没有帮助。

flutter dart button icons flutter-appbar
1个回答
0
投票

那是因为 AppBar 小部件中的行距空间有限。您可以使用 Row 来对齐 AppBar 中的操作,如下所示:

AppBar(
      automaticallyImplyLeading: false,
      backgroundColor: Colors.black,
      actions: [
        SizedBox(
          width: MediaQuery.of(context).size.width,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Padding(
                padding: const EdgeInsets.only(
                    left: 45.0), // устанавливаем отступ слева
                child: IconButton(
                  icon: const Icon(
                    Icons.menu,
                    color: Colors.white,
                  ),
                  onPressed: () {
                    print('123');
                  },
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(
                    right: 45.0), // устанавливаем отступ справа
                child: IconButton(
                  onPressed: () {},
                  icon:
                      const Icon(Icons.notifications, color: Colors.white),
                ),
              ),
            ],
          ),
        ),
      ],
    ),

希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.