Mobile Ads
Closes #286
Test Code:
import flet as ft
import flet.ads as ads
def main(page: ft.Page):
page.overlay.append(
iad := ads.InterstitialAd(
unit_id="ca-app-pub-3940256099942544/1033173712",
on_load=lambda e: print("InterstitialAd loaded"),
on_error=lambda e: print("InterstitialAd error", e.data),
on_open=lambda e: print("InterstitialAd opened"),
on_close=lambda e: print("InterstitialAd closed"),
on_impression=lambda e: print("InterstitialAd impression"),
on_click=lambda e: print("InterstitialAd clicked"),
)
)
page.update()
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Container(
content=ads.BannerAd(
unit_id="ca-app-pub-3940256099942544/6300978111",
on_click=lambda e: print("BannerAd clicked"),
on_load=lambda e: print("BannerAd loaded"),
on_error=lambda e: print("BannerAd error", e.data),
on_open=lambda e: print("BannerAd opened"),
on_close=lambda e: print("BannerAd closed"),
on_impression=lambda e: print("BannerAd impression"),
on_will_dismiss=lambda e: print("BannerAd will dismiss"),
),
width=320,
height=50,
bgcolor="red",
),
ft.OutlinedButton("show interstitial", on_click=lambda e: iad.show()),
]
)
)
)
ft.app(main)
Can you add (Rewarded interstitial - Interstitial Video - App Open)
Reviewer's Guide by Sourcery
This pull request introduces support for mobile ads (Banner and Interstitial) in the application. It includes the creation of new classes for handling different types of ads, integration of the flet_mobile_ads package into the main client application, and implementation of controls for handling these ads in Flutter. The changes ensure that the ads are properly initialized and managed within the application.
File-Level Changes
| Files | Changes |
|---|---|
sdk/python/packages/flet-core/src/flet_core/ads/native.pysdk/python/packages/flet-core/src/flet_core/ads/base_ad.pysdk/python/packages/flet-core/src/flet_core/ads/interstitial.pysdk/python/packages/flet-core/src/flet_core/ads/banner.py |
Added new classes for handling different types of ads (Native, Base, Interstitial, Banner) with properties and event handlers. |
packages/flet_mobile_ads/lib/src/native.dartpackages/flet_mobile_ads/lib/src/banner.dartpackages/flet_mobile_ads/lib/src/interstitial.dartpackages/flet_mobile_ads/lib/src/create_control.dart |
Implemented controls for handling native, banner, and interstitial ads in Flutter, and created a control factory. |
client/lib/main.dartclient/pubspec.yaml |
Integrated flet_mobile_ads package into the main client application, including initialization and control creation. |
Tips
- Trigger a new Sourcery review by commenting
@sourcery-ai reviewon the pull request. - Continue your discussion with Sourcery by replying directly to review comments.
- You can change your review settings at any time by accessing your dashboard:
- Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
- Change the review language;
- You can always contact us if you have any questions or feedback.
Waiting on https://github.com/flet-dev/flet/issues/3345 to finalize (the unit ID for the ads is passed as property, but however needs to be added to iOS .plist and Android .xml equally)
.
Waiting on #3345 to finalize (the unit ID for the ads is passed as property, but however needs to be added to iOS .plist and Android .xml equally)
please can you add native ads in documentation?
I faced some issues while trying to add Native ads (forgot which one though). It's files are present in this PR, but the Control can't be accessed nor used as its not fully ready-for-use.
For a start, we will have just Banner and Interstitial ads. Native might come up later on...
@sourcery-ai review
i test baner you ad code . and why error in app
"unknow control : banner_ad "
i test in android
version = 0.25.1
import flet as ft
import flet.ads as ads
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
id_banner = (
"ca-app-pub-3940256099942544/6300978111"
if page.platform == ft.PagePlatform.ANDROID
else "ca-app-pub-3940256099942544/2934735716"
)
def display_new_banner_ad():
page.add(
ft.Container(
content=ads.BannerAd(
unit_id=id_banner,
on_click=lambda e: print("BannerAd clicked"),
on_load=lambda e: print("BannerAd loaded"),
on_error=lambda e: print("BannerAd error", e.data),
on_open=lambda e: print("BannerAd opened"),
on_close=lambda e: print("BannerAd closed"),
on_impression=lambda e: print("BannerAd impression"),
on_will_dismiss=lambda e: print("BannerAd will dismiss"),
),
width=320,
height=50,
bgcolor=ft.colors.TRANSPARENT,
)
)
page.appbar = ft.AppBar(
adaptive=True,
title=ft.Text("Mobile Ads Playground"),
bgcolor=ft.colors.LIGHT_BLUE_300,
)
page.add(
ft.OutlinedButton("Show BannerAd", on_click=lambda e: display_new_banner_ad()),
)
ft.app(main)
Using the Flet mobile app? Or you packaged as apk?
Using the Flet mobile app? Or you packaged as apk?
Flet mobile . Yeah it shouldn't work . But is there a way to debug directly into android . Like . Flutter run android . That would be useful. When the development
But is there a way to debug directly into android . Like . Flutter run android . That would be useful. When the development
Taking note.