-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] BannerAd is right aligned on some devices #261
Comments
@pixelgroup-israel thanks for filing the issue. Could you please share the output of code sampleimport 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
runApp(BannerApp());
}
class BannerApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: CenteredBanner());
}
}
class CenteredBanner extends StatefulWidget {
const CenteredBanner({Key? key}) : super(key: key);
@override
_CenteredBannerState createState() => _CenteredBannerState();
}
class _CenteredBannerState extends State<CenteredBanner> {
late BannerAd _bannerAd;
bool isAdloaded = false;
@override
void initState() {
super.initState();
_bannerAd = BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.mediumRectangle,
request: AdRequest(),
listener: BannerAdListener(
onAdLoaded: (Ad ad) {
print('$BannerAd loaded.');
setState(() {
isAdloaded = true;
});
},
),
);
_bannerAd.load();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Banner Ad')),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
color: Colors.blue,
alignment: Alignment.center,
child: SizedBox(
width: _bannerAd.size.width.toDouble(),
height: _bannerAd.size.height.toDouble(),
child: AdWidget(ad: _bannerAd),
),
),
],
),
);
}
} flutter doctor -v
Let me know if I am missing anything. Thank you. |
me too. |
@morio77 could you provide more info on the issue and possibly a minimal code sample. Thanks |
@maheshmnj Here is the code. return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
children: [
Container(),
Container(),
),
],
),
),
// Bottom(バナー広告)
bottomNavigationBar: const SafeArea(
child: AdBanner(size: AdSize.fullBanner),
left: true,
right: true,
bottom: true,
),
); class AdBanner extends StatelessWidget {
const AdBanner({
required this.size, // サイズは利用時に指定
});
final AdSize size;
Widget build(BuildContext context) {
final banner = BannerAd(
size: size,
adUnitId: BannerAd.testAdUnitId,
listener: AdManagerBannerAdListener(
onAdLoaded: (Ad ad) => print('Ad loaded.'),
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('Ad failed to load: $error');
},
onAdOpened: (Ad ad) => print('Ad opened.'),
onAdClosed: (Ad ad) => print('Ad closed.'),
),
// リクエストはデフォルトを使う
request: const AdRequest())
// 表示を行うloadをつける
..load();
// 戻り値はContainerで包んで返す
return Container(
alignment: Alignment.center,
width: banner.size.width.toDouble(),
height: banner.size.height.toDouble(),
child: SizedBox(
child: AdWidget(ad: banner),
),
);
}
// 広告IDをプラットフォームに合わせて取得
static String get bannerAdUnitId {
if (Platform.isAndroid) {
return "XXX";
} else if (Platform.isIOS) {
return "YYY";
} else {
//どちらでもない場合は、テスト用を返す
return BannerAd.testAdUnitId;
}
}
} |
@mario77 what is your expected output? As per your code your output is correct also note that you are trying to show a fullsized banner AdBanner(size: AdSize.fullBanner), so it will cover the full width regardless of whatever alignment you pass to the banner. |
@maheshmnj The ads seem to have shifted to the right overall. The expected output is that there is no black area on the left and the YouTube logo on the right is all visible. |
@morio77 thanks for the clarification, I am able to reproduce the issue this issue is mainly on Android, The ads are shifted to right AdBanner(size: AdSize.fullBanner),
flutter doctor -v
|
cc: @jjliu15 |
same here devices : |
@jjliu15 @maheshmnj any updates on that , still happens on |
Unfortunately no update so far, Please keep an eye on this issue for future updates. |
same using flutter |
We're looking into this issue. |
This appears to be happening when the size of the rendered ad does not match the AdSize that was requested. For example, in #261 (comment) the size requested was I think generally we need a better way to handle the case where the returned banner ad size does not match the requested size. Maybe something similar to |
Hi, for those facing the same issue: According to the official Android Docs However, for us Flutter developers, the banner ad always appears even if you define AdSize as greater than your container's width. This is what I think is causing the issue we are facing. Also note that In short:
|
We’re closing this issue due to inactivity. If you’re still impacted, please create a new issue via the Developer Forum. |
I have created a new bug for this. please fix it. And this is the response from the developer forum after a few weeks. |
Re-open this issue as there is a similar report recently #928. |
I have tried several Google forums to get this fixed or obtain a proper implementation method. This is the last response I got. Not sure where to go from here. I can't release the app ads shown like this. It looks horrible. This is my test device https://www.motorola.com.au/smartphone-motorola-moto-g22/p. This is my code. Please provide me with a working solution.
|
@patolax per the documentation, you should be calling Please take a look at the code example in docs and see if the code provided can be used to resolve your issue. Thanks. |
Plugin Version
0.13.0
Steps to Reproduce
I have implemented adWidget in the following format:
Expected results:
Ad should be centered and should cover the green rectangle.
Actual results:
Ad is aligned to the right of the screen.
The text was updated successfully, but these errors were encountered: