Flet Ads in andriod
Duplicate Check
- [x] I have searched the opened issues and there are no duplicates
Describe the bug
i try build a app with ads and my id_banner flet build apk --include-packages flet_ads --android-meta-data com.google.android.gms.ads.APPLICATION_ID="ca-app-pub-1327011022394480~5377121235" -vv
and this is my code
Code sample
Code
import flet as ft
import flet.ads as ads
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
# استبدال المعرّفات بمعلوماتك الحقيقية
id_interstitial = (
"ca-app-pub-1327011022394480/4993682708" # الإعلان البيني
)
id_banner = (
"ca-app-pub-1327011022394480/3983853363" # الإعلان البانر
)
def handle_interstitial_close(e):
nonlocal iad
print("InterstitialAd closed")
page.overlay.remove(e.control)
page.overlay.append(iad := get_new_interstitial_ad())
page.update()
def get_new_interstitial_ad():
return ads.InterstitialAd(
unit_id=id_interstitial,
on_load=lambda _: print("InterstitialAd loaded"),
on_error=lambda e: print("InterstitialAd error", e.data),
on_open=lambda _: print("InterstitialAd opened"),
on_close=handle_interstitial_close,
on_impression=lambda _: print("InterstitialAd impression"),
on_click=lambda _: print("InterstitialAd clicked"),
)
def display_new_banner_ad():
page.add(
ft.Container(
content=ads.BannerAd(
unit_id=id_banner,
on_click=lambda _: print("BannerAd clicked"),
on_load=lambda _: print("BannerAd loaded"),
on_error=lambda e: print("BannerAd error", e.data),
on_open=lambda _: print("BannerAd opened"),
on_close=lambda _: print("BannerAd closed"),
on_impression=lambda _: print("BannerAd impression"),
on_will_dismiss=lambda _: print("BannerAd will dismiss"),
),
width=320,
height=50,
bgcolor=ft.colors.TRANSPARENT,
)
)
page.overlay.append(iad := get_new_interstitial_ad())
page.appbar = ft.AppBar(
adaptive=True,
title=ft.Text("Mobile Ads Playground"),
bgcolor=ft.colors.LIGHT_BLUE_300,
)
page.add(
ft.OutlinedButton("Show InterstitialAd", on_click=lambda _: iad.show()),
ft.OutlinedButton("Show BannerAd", on_click=lambda _: display_new_banner_ad()),
)
ft.app(main)
To reproduce
and after i run my app in my phone i see this
my app dont work can you help me ?
Expected behavior
No response
Screenshots / Videos
Captures
[Upload media here]
Operating System
Windows
Operating system details
windows 22H2 , andriod 14
Flet version
0.25.2
Regression
Yes, it used to work in a previous Flet version (please specify the version in additional details)
Suggestions
No response
Logs
Logs
[Paste your logs here]
Additional details
No response
Duplicate Check
- [x] I have searched the opened issues and there are no duplicates
Describe the bug
i try build a app with ads and my id_banner
flet build apk --include-packages flet_ads --android-meta-data com.google.android.gms.ads.APPLICATION_ID="ca-app-pub-1327011022394480~5377121235" -vvand this is my codeCode sample
Code import flet as ft import flet.ads as ads
def main(page: ft.Page): page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
# استبدال المعرّفات بمعلوماتك الحقيقية id_interstitial = ( "ca-app-pub-1327011022394480/4993682708" # الإعلان البيني ) id_banner = ( "ca-app-pub-1327011022394480/3983853363" # الإعلان البانر ) def handle_interstitial_close(e): nonlocal iad print("InterstitialAd closed") page.overlay.remove(e.control) page.overlay.append(iad := get_new_interstitial_ad()) page.update() def get_new_interstitial_ad(): return ads.InterstitialAd( unit_id=id_interstitial, on_load=lambda _: print("InterstitialAd loaded"), on_error=lambda e: print("InterstitialAd error", e.data), on_open=lambda _: print("InterstitialAd opened"), on_close=handle_interstitial_close, on_impression=lambda _: print("InterstitialAd impression"), on_click=lambda _: print("InterstitialAd clicked"), ) def display_new_banner_ad(): page.add( ft.Container( content=ads.BannerAd( unit_id=id_banner, on_click=lambda _: print("BannerAd clicked"), on_load=lambda _: print("BannerAd loaded"), on_error=lambda e: print("BannerAd error", e.data), on_open=lambda _: print("BannerAd opened"), on_close=lambda _: print("BannerAd closed"), on_impression=lambda _: print("BannerAd impression"), on_will_dismiss=lambda _: print("BannerAd will dismiss"), ), width=320, height=50, bgcolor=ft.colors.TRANSPARENT, ) ) page.overlay.append(iad := get_new_interstitial_ad()) page.appbar = ft.AppBar( adaptive=True, title=ft.Text("Mobile Ads Playground"), bgcolor=ft.colors.LIGHT_BLUE_300, ) page.add( ft.OutlinedButton("Show InterstitialAd", on_click=lambda _: iad.show()), ft.OutlinedButton("Show BannerAd", on_click=lambda _: display_new_banner_ad()), )ft.app(main)
To reproduce
and after i run my app in my phone i see this
my app dont work can you help me ?
Expected behavior
No response
Screenshots / Videos
Captures [Upload media here]
Operating System
Windows
Operating system details
windows 22H2 , andriod 14
Flet version
0.25.2
Regression
Yes, it used to work in a previous Flet version (please specify the version in additional details)
Suggestions
No response
Logs
Logs [Paste your logs here]
Additional details
No response
me too the same problem
do you know how can fix this?
just add WidgetsFlutterBinding.ensureInitialized(); in main.dart inside main void
can you make a video about this because i dont know how can i fix it
just add WidgetsFlutterBinding.ensureInitialized(); in main.dart inside main void
@FeodorFitsner @ndonkoHenri
I am with the same problem. I used the code 'flet build apk --include-packages flet_ads' to build the apk that run successfully without ads, but when I add adbanner in to the code and had the application built again to it get running into the android phone the app doesn't open
just add WidgetsFlutterBinding.ensureInitialized(); in main.dart inside main void
Good afternoon, dear! How do you ensure that this change or added code is not deleted/overwritten when compiling with flet build?
Bunu nasıl düzeltebilirim biliyor musunuz?
can you make a video about this because i dont know how can i fix it
Did you solve it
Guys, I have been trying to fix an error of ad error in my application since 10/01. Tried to change a lot of things, but nothing works
Bunu nasıl düzeltebilirim biliyor musunuz?
can you make a video about this because i dont know how can i fix it
Did you solve it
I need to know too
@FeodorFitsner @ndonkoHenri Good morning! Do you have an estimated date for when the next release with this fix-bug will be available? Regards!
Video tutorial: https://youtu.be/CgScZlh_xRs
Video tutorial: https://youtu.be/CgScZlh_
check for web ads https://pub.dev/packages/flutter_ad_manager_web