Back to Flet

Ads

website/docs/controls/ads/index.md

0.85.0.dev23.1 KB
Original Source

import TabItem from '@theme/TabItem'; import Tabs from '@theme/Tabs'; import {CodeExample, Image} from '@site/src/components/crocodocs';

Ads

Displaying Google Ads in Flet apps.

It is powered by the google_mobile_ads Flutter package.

Platform Support

PlatformWindowsmacOSLinuxiOSAndroidWeb
Supported

Usage

To use ads controls add flet-ads package to your project dependencies:

<Tabs groupId="uv--pip"> <TabItem value="uv" label="uv"> ```bash uv add flet-ads ``` </TabItem> <TabItem value="pip" label="pip"> ```bash pip install flet-ads # (1)! ```
  1. After this, you will have to manually add this package to your requirements.txt or pyproject.toml. </TabItem>
</Tabs> ## Requirements

The below sections show the required configurations for each platform.

Android

A valid AdMob app ID is required to be specified, otherwise the app might crash on launch or behave unexpectedly.

<Tabs groupId="flet-build--pyproject-toml"> <TabItem value="flet-build" label="flet build"> ```bash flet build apk \ --android-meta-data com.google.android.gms.ads.APPLICATION_ID="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" ``` </TabItem> <TabItem value="pyproject-toml" label="pyproject.toml"> ```toml [tool.flet.android.meta_data] "com.google.android.gms.ads.APPLICATION_ID" = "ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" ``` </TabItem> </Tabs> See also:

iOS

A valid AdMob app ID is required to be specified, otherwise the app might crash on launch or behave unexpectedly.

<Tabs groupId="flet-build--pyproject-toml"> <TabItem value="flet-build" label="flet build"> ```bash flet build ipa \ --info-plist GADApplicationIdentifier="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" ``` </TabItem> <TabItem value="pyproject-toml" label="pyproject.toml"> ```toml [tool.flet.ios.info] GADApplicationIdentifier = "ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy" ``` </TabItem> </Tabs> See also:

Test Values

AdMob provides app and ad unit IDs for testing purposes.

  • AdMob app ID: "ca-app-pub-3940256099942544~3347511713"
  • BannerAd.unit_id
    • Android: "ca-app-pub-3940256099942544/9214589741"
    • iOS: "ca-app-pub-3940256099942544/2435281174"
  • InterstitialAd.unit_id
    • Android: "ca-app-pub-3940256099942544/1033173712"
    • iOS: "ca-app-pub-3940256099942544/4411468910"

They are not meant to be used in production.

Example

<CodeExample path={frontMatter.examples + '/example_1/main.py'} language="python" />

<Image src={frontMatter.example_images + '/example_1.gif'} width="55%" />