Want to get banner size of smart banner? This is a code I’m using to get the height of a smartbanner, according to Google Specs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /// The initial size of the banner is calculated on the height of the /// viewport. Due to ADMob banner refresh policies, in order to have /// a consistent behaviour, we should keep track of the current AD size /// and maintain it when the user rotates the screen, and update that /// value at every banner successful. /// For now, we will avoid this complexity and set the banner height to /// the maximum height that a banner could get on this device, forcing /// the use of the longest side as the base. /// see https://developers.google.com/admob/android/banner#smart_banners double _getSmartBannerHeight(BuildContext context) { MediaQueryData mediaScreen = MediaQuery.of(context); double dpHeight = mediaScreen.orientation == Orientation.portrait ? mediaScreen.size.height : mediaScreen.size.width; log.fine("Device height: $dpHeight"); if (dpHeight <= 400.0) { return 32.0; } if (dpHeight > 720.0) { return 90.0; } return 50.0; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.