【问题标题】:flutter move floatingActionButton up 50 pixels颤动将浮动操作按钮向上移动 50 像素
【发布时间】:2019-06-07 21:43:57
【问题描述】:

是否可以将floatingActionButton 向上移动 50 个像素?

我在一个使用firebase_admob 的应用中有一个floatingActionButton,并且广告横幅重叠在floatingActionButton 之上。

如何将floatingActionButton 设置为距屏幕底部50 像素

floatingActionButtondocumentation 中,我似乎无法确定按钮的位置。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    将您的 FloatingActionButton 包裹在 Padding 中并添加您想要的大小:

        floatingActionButton: Padding(
                padding: const EdgeInsets.only(bottom: 50.0),
                child: FloatingActionButton(
                  child: Icon(Icons.remove),
                  onPressed: () => null,
                ),
              ), 
    

    【讨论】:

    • 感谢您的帮助。这效果更好,尽管键盘的显示使按钮板与显示的键盘相距 50
    • 您可以检测您的键盘是否打开,然后将填充的值更改为 0,stackoverflow.com/questions/47823767/…
    • 在你的脚手架中设置 resizeToAvoidBottomInset 为 false 并且在键盘打开时它不会跳转
    【解决方案2】:

    很简单。

    class Test extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(),
          body: Container(),
          floatingActionButton: Align(
              child: FloatingActionButton(onPressed: null),
              alignment: Alignment(1, 0.7)),
        );
      }
    }
    

    使用对齐,因为在 Flutter 中一切都是 Widget。

    【讨论】:

    • 这确实有助于清除广告横幅,但是当显示键盘时,floatingActionButton 会跳到顶部。希望它保持 50 像素的底部填充
    • 修复它...等待
    • 嗯,它似乎用填充或使用对齐跳跃。你能分享代码或用户界面吗?
    • 按照 diegoveloper 的建议,Align 和 Padidng 都会发生跳转。然而,使用 Padding 的行为要好得多,因此我会将其评为正确答案。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2016-11-22
    • 2019-03-06
    • 1970-01-01
    • 2015-06-25
    • 2018-02-03
    相关资源
    最近更新 更多