如果我打开我的应用程序,则显示一个初始屏幕,然后转到主页,我的admob标语不显示,并且整个应用程序在几秒钟后冻结。但是,如果我绕过启动页面直接进入HomePage
,横幅显示没有问题吗?
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
));
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((_) {
Admob.initialize('ca-app-pub-3940256099942544~3347511713');
runApp(MyApp());
});
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
showPerformanceOverlay: false,
// home: SplashPage(),//ads do not show
home: HomePage(),//ads show no problem
);
}
}
class SplashPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: GestureDetector(
onTap: () {
Navigator.pushReplacement(// or with .push yields the same outcome
context,
MaterialPageRoute(
builder: (context) {
return HomePage();
},
settings: RouteSettings(isInitialRoute: true),
),
);
},
child: Container(
color: Colors.black,
child: Center(
child: Text('Splash page'),
),
),
),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('Home Page'),
bottomNavigationBar: Container(
height: 60,
child: Column(
children: <Widget>[
AdmobBanner(
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
adSize: AdmobBannerSize.BANNER,
),
],
),
),
);
}
}
知道为什么会这样吗?从SplashPage
到HomePage
并没有允许横幅显示的内容。