flutter - 屏幕底部有多个FAB

标签 flutter dart flutter-layout

我希望在屏幕底部添加均匀间隔的多个FAB。

我最初是通过以下方式实现的:

      body: Center(
        child: Stack(
          children: <Widget>[
            Row(
              children: <Widget>[
                Padding(
                  padding:
                      const EdgeInsets.only(left: 12.0, right: 20.0, top: 580),
                  child: FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.undo),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                ),
                Padding(
                  padding:
                      const EdgeInsets.only(left: 0.0, right: 20.0, top: 580),
                  child: FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.cancel),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                ),
                Padding(
                  padding:
                      const EdgeInsets.only(left: 0.0, right: 20.0, top: 580),
                  child: FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.favorite),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                ),
                Padding(
                  padding:
                      const EdgeInsets.only(left: 0.0, right: 20.0, top: 580),
                  child: FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.check_circle),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                ),
                Padding(
                  padding:
                      const EdgeInsets.only(left: 0, right: 20.0, top: 580),
                  child: FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.share),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                ),
              ],
            ),

但是,这确实令人讨厌,虽然在我的单个测试设备上看起来不错,但在迁移到其他设备时却无法扩展。

正确的做法是什么?

最佳答案

您已对大多数填充进行了硬编码,因此无法在许多屏幕上使用。尽量让 flutter 进行定位:)

这就是你想要的。它适用于纵向和横向的任何屏幕类型。

body: Stack(
          children: <Widget>[
            Container(
              alignment: Alignment.bottomCenter,
              padding: EdgeInsets.only(bottom: 20),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.undo),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                  FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.cancel),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                  FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.favorite),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                  FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.check_circle),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                  FloatingActionButton(
                    onPressed: () {},
                    child: const Icon(Icons.share),
                    splashColor: Colors.pink[900],
                    backgroundColor: Colors.pink[250],
                  ),
                ],
              ),
            ),
          ],
        ),

关于flutter - 屏幕底部有多个FAB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61687578/

相关文章:

flutter - 具有超过3个项目的Flutter BottomNavigationBar会根据所选项目自动应用填充

flutter - 在视频上放置文字-Flutter-web

dart - Flutter:如何通过 appbar 操作显示 snackbar

flutter - 我应该担心 Flutter 和 Dart 版本不同吗?

dart - 导入 Dart 库时使用 "show"除了意图和编译器速度之外还有其他好处吗?

android - ListView flutter 中的问题开关值

Flutter,如何设置最大高度以列出 View 项目

android - 一旦应用程序进入后台,在一定持续时间后 flutter 运行代码?

api - 我 flutter 的 Http 发布请求未发送表单数据

dart - 为 Flutter 使用 Google Play 游戏服务?