Flutter:横幅广告与主屏幕重叠

Won*_*mmy 5 admob dart flutter

我正在制作Flutter应用,并设法展示了AdMob横幅广告,但是该广告与应用主屏幕的底部重叠:

在此处输入图片说明

通过遵循本文,我设法使应用程序屏幕的底部正确显示,但是牺牲了persistentFooterButtons,我认为这不是理想的解决方案。 在此处输入图片说明

我正在考虑将脚手架对象和固定高度区域放入Center对象所包含的列中,类似于以下内容:

  @override
  Widget build(BuildContext context) {

    return new Center(
      child: new Column (
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          new Expanded (
              child:  _getScaffold(),
          ),
          new Expanded (
              child: new Container(height: 50.0,)
          )
        ],
      ),
    );
  }
Run Code Online (Sandbox Code Playgroud)

但是通过这种方式,我得到了异常“ RenderFlex底部溢出228个像素 ”:

在此处输入图片说明

谁能告诉我如何建立这样的布局?我希望脚手架的每个组件都能正确显示,并且固定高度的虚拟页脚可以与Admob的横幅广告重叠。

任何帮助都非常欢迎。

吉米

Ish*_*ndo 9

我们也可以在 Scaffold 下添加一些像 bottomNavigationBar 这样的技巧

bottomNavigationBar: Container(
    height: 50.0,
    color: Colors.white,
  ),
Run Code Online (Sandbox Code Playgroud)

这将使浮动按钮向上。


azi*_*iza 2

如果我很好地理解您的问题,我认为您希望在使用 FAB 时从底部显示广告。我认为Stack在这里使用小部件是一个很好的解决方案,我匆忙创建了这个示例,但应该足以向您展示我的意思:

在此输入图像描述

class AdBar extends StatefulWidget {
  @override
  _AdBarState createState() => new _AdBarState();
}

class _AdBarState extends State<AdBar> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(),
        body: new ListView(
          children: new List.generate(50, (int index) {
            return new Text("widgets$index");
          }),
        ),
        persistentFooterButtons:

        <Widget>[
          new Stack(
            children: <Widget>[
              new Container (
                color: Colors.transparent,
                child: new Material(
                  color: Colors.cyanAccent,
                  child: new InkWell(
                    onTap: () {

                    },
                    child: new Container(
                      //color: Colors.cyanAccent,
                      width: MediaQuery
                          .of(context)
                          .size
                          .width * 0.90,
                      height: MediaQuery
                          .of(context)
                          .size
                          .height * 0.25,
                    ),
                  ),),),
              new Positioned(
                  right: 0.0,
                  child: new FloatingActionButton(
                      onPressed: () {}, child: new Icon(Icons.fastfood)))
            ],
          )
        ]

    );
  }
}
Run Code Online (Sandbox Code Playgroud)