首页 > 解决方案 > Firebase Admob - 与导航抽屉重叠的横幅广告

问题描述

添加 firebase_admob 插件并启动并运行后,我注意到它覆盖了 fab 和导航抽屉。我已经使用persistentFooterButtons 修复了工厂,但我似乎找不到导航抽屉的解决方法。任何帮助深表感谢。

在下面找到一个示例实现,以在颤振中重新创建问题:

import 'package:flutter/material.dart';
import 'package:firebase_admob/firebase_admob.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
            title: 'Firebase AdMob',
            theme: new ThemeData(
                primarySwatch: Colors.blue,
            ),
            home: new MyHomePage(title: 'AdMob Test App'),
        );
    }
}

class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
    final String title;

    @override
    _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
    int _counter = 0;
    BannerAd myBanner;

    void _incrementCounter() {
        setState(() {
            _counter++;
        });
    }

    @override
    void initState() {
        super.initState();
        myBanner = new BannerAd(
            // Replace the testAdUnitId with an ad unit id from the AdMob dash.
            // https://developers.google.com/admob/android/test-ads
            // https://developers.google.com/admob/ios/test-ads
            adUnitId: BannerAd.testAdUnitId,
            size: AdSize.smartBanner,
            targetingInfo: new MobileAdTargetingInfo(
                // gender: MobileAdGender.unknown
            ),
            listener: (MobileAdEvent event) {
                print("BannerAd event is $event");
            },
        );
        myBanner..load()..show(
            // Banner Position
            anchorType: AnchorType.bottom,
        );
    }

    @override
    void dispose() {
        myBanner?.dispose();
        super.dispose();
    }

    @override
    Widget build(BuildContext context) {

        return new Scaffold(
            appBar: new AppBar(
                title: new Text(widget.title),
            ),
            drawer: new Drawer(),
            body: new Center(
                child: new Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        new Text('You have pushed the button this many times:'),
                        new Text('$_counter', style: Theme.of(context).textTheme.display1),
                    ],
                ),
            ),
            floatingActionButton: new FloatingActionButton(
                onPressed: _incrementCounter,
                tooltip: 'Increment',
                child: new Icon(Icons.add),
            ), // This trailing comma makes auto-formatting nicer for build methods.
        );
    }
}

标签: navigation-drawerflutter

解决方案


我对此有点晚了,但遇到了同样的问题。

我的导航抽屉位于一个具有固定高度的可滚动容器中,因此它在添加上方停止并且可以滚动。可能不是完美的答案,但对我有用。


推荐阅读