flet-ads 0.1.0__tar.gz → 0.2.0.dev34__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet-ads might be problematic. Click here for more details.

Files changed (38) hide show
  1. {flet_ads-0.1.0/src/flutter/flet_ads → flet_ads-0.2.0.dev34}/LICENSE +1 -1
  2. flet_ads-0.2.0.dev34/PKG-INFO +66 -0
  3. flet_ads-0.2.0.dev34/README.md +50 -0
  4. flet_ads-0.2.0.dev34/pyproject.toml +68 -0
  5. flet_ads-0.2.0.dev34/src/flet_ads/__init__.py +10 -0
  6. flet_ads-0.2.0.dev34/src/flet_ads/banner_ad.py +29 -0
  7. flet_ads-0.2.0.dev34/src/flet_ads/base_ad.py +67 -0
  8. flet_ads-0.2.0.dev34/src/flet_ads/interstitial_ad.py +21 -0
  9. flet_ads-0.2.0.dev34/src/flet_ads/native_ad.py +32 -0
  10. flet_ads-0.2.0.dev34/src/flet_ads/types.py +129 -0
  11. flet_ads-0.2.0.dev34/src/flet_ads.egg-info/PKG-INFO +66 -0
  12. flet_ads-0.2.0.dev34/src/flet_ads.egg-info/SOURCES.txt +14 -0
  13. flet_ads-0.2.0.dev34/src/flet_ads.egg-info/requires.txt +1 -0
  14. flet_ads-0.1.0/PKG-INFO +0 -97
  15. flet_ads-0.1.0/README.md +0 -83
  16. flet_ads-0.1.0/pyproject.toml +0 -36
  17. flet_ads-0.1.0/src/flet_ads/__init__.py +0 -10
  18. flet_ads-0.1.0/src/flet_ads/banner.py +0 -110
  19. flet_ads-0.1.0/src/flet_ads/base_ad.py +0 -174
  20. flet_ads-0.1.0/src/flet_ads/interstitial.py +0 -111
  21. flet_ads-0.1.0/src/flet_ads/native.py +0 -171
  22. flet_ads-0.1.0/src/flet_ads.egg-info/PKG-INFO +0 -97
  23. flet_ads-0.1.0/src/flet_ads.egg-info/SOURCES.txt +0 -24
  24. flet_ads-0.1.0/src/flet_ads.egg-info/requires.txt +0 -1
  25. flet_ads-0.1.0/src/flutter/flet_ads/CHANGELOG.md +0 -3
  26. flet_ads-0.1.0/src/flutter/flet_ads/README.md +0 -3
  27. flet_ads-0.1.0/src/flutter/flet_ads/analysis_options.yaml +0 -4
  28. flet_ads-0.1.0/src/flutter/flet_ads/lib/flet_ads.dart +0 -3
  29. flet_ads-0.1.0/src/flutter/flet_ads/lib/src/banner.dart +0 -96
  30. flet_ads-0.1.0/src/flutter/flet_ads/lib/src/create_control.dart +0 -29
  31. flet_ads-0.1.0/src/flutter/flet_ads/lib/src/interstitial.dart +0 -83
  32. flet_ads-0.1.0/src/flutter/flet_ads/lib/src/native.dart +0 -153
  33. flet_ads-0.1.0/src/flutter/flet_ads/lib/utils/native.dart +0 -69
  34. flet_ads-0.1.0/src/flutter/flet_ads/pubspec.lock +0 -759
  35. flet_ads-0.1.0/src/flutter/flet_ads/pubspec.yaml +0 -18
  36. {flet_ads-0.1.0 → flet_ads-0.2.0.dev34}/setup.cfg +0 -0
  37. {flet_ads-0.1.0 → flet_ads-0.2.0.dev34}/src/flet_ads.egg-info/dependency_links.txt +0 -0
  38. {flet_ads-0.1.0 → flet_ads-0.2.0.dev34}/src/flet_ads.egg-info/top_level.txt +0 -0
@@ -198,4 +198,4 @@
198
198
  distributed under the License is distributed on an "AS IS" BASIS,
199
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
200
  See the License for the specific language governing permissions and
201
- limitations under the License.
201
+ limitations under the License.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: flet-ads
3
+ Version: 0.2.0.dev34
4
+ Summary: Display Google Ads in Flet apps.
5
+ Author-email: Flet contributors <hello@flet.dev>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://flet.dev
8
+ Project-URL: Documentation, https://flet-dev.github.io/flet-ads
9
+ Project-URL: Repository, https://github.com/flet-dev/flet-ads
10
+ Project-URL: Issues, https://github.com/flet-dev/flet-ads/issues
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: flet>=0.70.0
15
+ Dynamic: license-file
16
+
17
+ # flet-ads
18
+
19
+ [![pypi](https://img.shields.io/pypi/v/flet-ads.svg)](https://pypi.python.org/pypi/flet-ads)
20
+ [![downloads](https://static.pepy.tech/badge/flet-ads/month)](https://pepy.tech/project/flet-ads)
21
+ [![license](https://img.shields.io/github/license/flet-dev/flet-ads.svg)](https://github.com/flet-dev/flet-ads/blob/main/LICENSE)
22
+
23
+ Display Google Ads in [Flet](https://flet.dev) apps.
24
+
25
+ It is based on the [google_mobile_ads](https://pub.dev/packages/google_mobile_ads) Flutter package.
26
+
27
+ ## Documentation
28
+
29
+ Detailed documentation to this package can be found [here](https://flet-dev.github.io/flet-ads/).
30
+
31
+ ## Platform Support
32
+
33
+ This package supports the following platforms:
34
+
35
+ | Platform | Supported |
36
+ |----------|:---------:|
37
+ | Windows | ❌ |
38
+ | macOS | ❌ |
39
+ | Linux | ❌ |
40
+ | iOS | ✅ |
41
+ | Android | ✅ |
42
+ | Web | ❌ |
43
+
44
+ ## Installation
45
+
46
+ To install the `flet-ads` package and add it to your project dependencies:
47
+
48
+ - Using `uv`:
49
+ ```bash
50
+ uv add flet-ads
51
+ ```
52
+
53
+ - Using `pip`:
54
+ ```bash
55
+ pip install flet-ads
56
+ ```
57
+ After this, you will have to manually add this package to your `requirements.txt` or `pyproject.toml`.
58
+
59
+ - Using `poetry`:
60
+ ```bash
61
+ poetry add flet-ads
62
+ ```
63
+
64
+ ## Examples
65
+
66
+ For examples, see [this](./examples)
@@ -0,0 +1,50 @@
1
+ # flet-ads
2
+
3
+ [![pypi](https://img.shields.io/pypi/v/flet-ads.svg)](https://pypi.python.org/pypi/flet-ads)
4
+ [![downloads](https://static.pepy.tech/badge/flet-ads/month)](https://pepy.tech/project/flet-ads)
5
+ [![license](https://img.shields.io/github/license/flet-dev/flet-ads.svg)](https://github.com/flet-dev/flet-ads/blob/main/LICENSE)
6
+
7
+ Display Google Ads in [Flet](https://flet.dev) apps.
8
+
9
+ It is based on the [google_mobile_ads](https://pub.dev/packages/google_mobile_ads) Flutter package.
10
+
11
+ ## Documentation
12
+
13
+ Detailed documentation to this package can be found [here](https://flet-dev.github.io/flet-ads/).
14
+
15
+ ## Platform Support
16
+
17
+ This package supports the following platforms:
18
+
19
+ | Platform | Supported |
20
+ |----------|:---------:|
21
+ | Windows | ❌ |
22
+ | macOS | ❌ |
23
+ | Linux | ❌ |
24
+ | iOS | ✅ |
25
+ | Android | ✅ |
26
+ | Web | ❌ |
27
+
28
+ ## Installation
29
+
30
+ To install the `flet-ads` package and add it to your project dependencies:
31
+
32
+ - Using `uv`:
33
+ ```bash
34
+ uv add flet-ads
35
+ ```
36
+
37
+ - Using `pip`:
38
+ ```bash
39
+ pip install flet-ads
40
+ ```
41
+ After this, you will have to manually add this package to your `requirements.txt` or `pyproject.toml`.
42
+
43
+ - Using `poetry`:
44
+ ```bash
45
+ poetry add flet-ads
46
+ ```
47
+
48
+ ## Examples
49
+
50
+ For examples, see [this](./examples)
@@ -0,0 +1,68 @@
1
+ [project]
2
+ name = "flet-ads"
3
+ version = "0.2.0.dev34"
4
+ description = "Display Google Ads in Flet apps."
5
+ readme = "README.md"
6
+ authors = [{ name = "Flet contributors", email = "hello@flet.dev" }]
7
+ license = "Apache-2.0"
8
+ requires-python = ">=3.10"
9
+ dependencies = [
10
+ "flet >=0.70.0",
11
+ ]
12
+
13
+ [project.urls]
14
+ Homepage = "https://flet.dev"
15
+ Documentation = "https://flet-dev.github.io/flet-ads"
16
+ Repository = "https://github.com/flet-dev/flet-ads"
17
+ Issues = "https://github.com/flet-dev/flet-ads/issues"
18
+
19
+ [dependency-groups]
20
+ dev = [
21
+ "pre-commit>=4.2.0",
22
+ "ruff>=0.11.7",
23
+ ]
24
+ docs = [
25
+ "mkdocs",
26
+ "mkdocs-material",
27
+ "mkdocstrings[python]",
28
+ "mkdocstrings-python-xref",
29
+ "mike",
30
+ "markdown>=3.6",
31
+ "pymdown-extensions",
32
+ "mkdocs-glightbox",
33
+ "mkdocs-section-index",
34
+ "griffe-modernized-annotations",
35
+ "pygments>=2.16",
36
+ ]
37
+
38
+ [build-system]
39
+ requires = ["setuptools"]
40
+ build-backend = "setuptools.build_meta"
41
+
42
+ [tool.ruff]
43
+ line-length = 88
44
+ target-version = "py39"
45
+ fix = true
46
+ show-fixes = true
47
+
48
+ [tool.ruff.lint]
49
+ select = [
50
+ # pycodestyle
51
+ "E",
52
+ # Pyflakes
53
+ "F",
54
+ # pyupgrade
55
+ "UP",
56
+ # flake8-bugbear
57
+ "B",
58
+ # flake8-simplify
59
+ "SIM",
60
+ # isort
61
+ "I"
62
+ ]
63
+ preview = true
64
+
65
+ [tool.ruff.format]
66
+ quote-style = "double"
67
+ indent-style = "space"
68
+ line-ending = "auto"
@@ -0,0 +1,10 @@
1
+ from .banner_ad import BannerAd
2
+ from .base_ad import BaseAd
3
+ from .interstitial_ad import InterstitialAd
4
+ from .types import ( # NativeAdTemplateStyle,; NativeAdTemplateTextStyle,; NativeAdTemplateType,; NativeTemplateFontStyle,
5
+ AdRequest,
6
+ PaidAdEvent,
7
+ PrecisionType,
8
+ )
9
+
10
+ # from .native_ad import NativeAd
@@ -0,0 +1,29 @@
1
+ import flet as ft
2
+
3
+ from .base_ad import BaseAd
4
+ from .types import PaidAdEvent
5
+
6
+
7
+ @ft.control("BannerAd")
8
+ class BannerAd(BaseAd):
9
+ """
10
+ Displays a banner ad.
11
+
12
+ Raises:
13
+ AssertionError: When using this control on a web and/or non-mobile platform.
14
+ """
15
+
16
+ on_will_dismiss: ft.OptionalControlEventHandler["BannerAd"] = None
17
+ """
18
+ Called before dismissing a full screen view.
19
+
20
+ Note:
21
+ Only available on iOS.
22
+ """
23
+
24
+ on_paid: ft.OptionalControlEventHandler[PaidAdEvent["BannerAd"]] = None
25
+ """
26
+ Called when this ad is estimated to have earned money.
27
+
28
+ Available for allowlisted accounts only.
29
+ """
@@ -0,0 +1,67 @@
1
+ from dataclasses import field
2
+
3
+ import flet as ft
4
+
5
+ from flet_ads.types import AdRequest
6
+
7
+
8
+ @ft.control
9
+ class BaseAd(ft.Control):
10
+ """
11
+ Base class for all ad controls in Flet Ads package.
12
+
13
+ Raises:
14
+ AssertionError: When using this control on a web and/or non-mobile platform.
15
+ """
16
+
17
+ unit_id: str
18
+ """
19
+ Ad unit ID for this ad.
20
+ """
21
+
22
+ request: AdRequest = field(default_factory=lambda: AdRequest())
23
+ """
24
+ Targeting information used to fetch an Ad.
25
+ """
26
+
27
+ on_load: ft.OptionalControlEventHandler["BaseAd"] = None
28
+ """
29
+ Called when this ad is loaded successfully.
30
+ """
31
+
32
+ on_error: ft.OptionalControlEventHandler["BaseAd"] = None
33
+ """
34
+ Called when an ad request failed.
35
+
36
+ Event handler argument `data` property contains information about the error.
37
+ """
38
+
39
+ on_open: ft.OptionalControlEventHandler["BaseAd"] = None
40
+ """
41
+ Called when this ad opens up.
42
+
43
+ A full screen view/overlay is presented in response to the user clicking
44
+ on an ad. You may want to pause animations and time sensitive
45
+ interactions.
46
+ """
47
+
48
+ on_close: ft.OptionalControlEventHandler["BaseAd"] = None
49
+ """
50
+ Called when the full screen view has been closed. You should restart
51
+ anything paused while handling [`on_open`][..].
52
+ """
53
+
54
+ on_impression: ft.OptionalControlEventHandler["BaseAd"] = None
55
+ """
56
+ Called when an impression occurs on this ad.
57
+ """
58
+
59
+ on_click: ft.OptionalControlEventHandler["BaseAd"] = None
60
+ """
61
+ Called when this ad is clicked.
62
+ """
63
+
64
+ def before_update(self):
65
+ assert (
66
+ not self.page.web and self.page.platform.is_mobile()
67
+ ), f"{self.__class__.__name__} is only supported on Mobile (Android and iOS)"
@@ -0,0 +1,21 @@
1
+ import asyncio
2
+
3
+ import flet as ft
4
+
5
+ from .base_ad import BaseAd
6
+
7
+
8
+ @ft.control("InterstitialAd")
9
+ class InterstitialAd(BaseAd):
10
+ """
11
+ Displays a full-screen interstitial ad.
12
+
13
+ Raises:
14
+ AssertionError: When using this control on a web and/or non-mobile platform.
15
+ """
16
+
17
+ def show(self):
18
+ asyncio.create_task(self.show_async())
19
+
20
+ async def show_async(self):
21
+ await self._invoke_method_async("show")
@@ -0,0 +1,32 @@
1
+ import flet as ft
2
+
3
+ from .banner_ad import BannerAd
4
+ from .types import NativeAdTemplateStyle
5
+
6
+ __all__ = ["NativeAd"]
7
+
8
+
9
+ @ft.control("NativeAd")
10
+ class NativeAd(BannerAd):
11
+ """
12
+ Renders a native ad.
13
+
14
+ Raises:
15
+ AssertionError: When neither [`factory_id`][..] nor [`template_style`][..] is set.
16
+ """
17
+
18
+ factory_id: str = None
19
+ """
20
+ An identifier for the factory that creates the Platform view.
21
+ """
22
+
23
+ template_style: NativeAdTemplateStyle = None
24
+ """
25
+ A style for the native ad template.
26
+ """
27
+
28
+ def before_update(self):
29
+ super().before_update()
30
+ assert (
31
+ self.factory_id is not None or self.template_style is not None
32
+ ), "factory_id or template_style must be set"
@@ -0,0 +1,129 @@
1
+ from dataclasses import dataclass
2
+ from enum import Enum
3
+ from typing import Optional
4
+
5
+ import flet as ft
6
+
7
+ __all__ = [
8
+ "PrecisionType",
9
+ "PaidAdEvent",
10
+ "AdRequest",
11
+ "NativeAdTemplateType",
12
+ "NativeTemplateFontStyle",
13
+ "NativeAdTemplateTextStyle",
14
+ "NativeAdTemplateStyle",
15
+ ]
16
+
17
+
18
+ class PrecisionType(Enum):
19
+ UNKNOWN = "unknown"
20
+ """An ad value with unknown precision."""
21
+
22
+ ESTIMATED = "estimated"
23
+ """An ad value estimated from aggregated data."""
24
+
25
+ PUBLISHER_PROVIDED = "publisherProvided"
26
+ """A publisher-provided ad value, such as manual CPMs in a mediation group."""
27
+
28
+ PRECISE = "precise"
29
+ """The precise value paid for this ad."""
30
+
31
+
32
+ @dataclass
33
+ class PaidAdEvent(ft.Event[ft.EventControlType]):
34
+ """
35
+ Event data for paid ad events.
36
+ """
37
+
38
+ value: float
39
+ """
40
+ The monetary value of the ad.
41
+ """
42
+
43
+ precision: PrecisionType
44
+ """
45
+ The precision of the ad value.
46
+ """
47
+
48
+ currency_code: str
49
+ """
50
+ The currency code of the ad value.
51
+ """
52
+
53
+
54
+ @dataclass
55
+ class AdRequest:
56
+ """
57
+ Targeting info per the AdMob API.
58
+
59
+ This class's properties mirror the native AdRequest API. See for example:
60
+ [AdRequest.Builder for Android](https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest.Builder).
61
+ """
62
+
63
+ keywords: Optional[list[str]] = None
64
+ """
65
+ Words or phrases describing the current user activity.
66
+ """
67
+
68
+ content_url: Optional[str] = None
69
+ """
70
+ URL string for a webpage whose content matches the app’s primary content.
71
+
72
+ This webpage content is used for targeting and brand safety purposes.
73
+ """
74
+
75
+ neighboring_content_urls: Optional[list[str]] = None
76
+ """
77
+ URLs representing web content near an ad.
78
+ """
79
+
80
+ non_personalized_ads: Optional[bool] = None
81
+ """
82
+ Non-personalized ads are ads that are not based on a user’s past behavior.
83
+
84
+ For more information: https://support.google.com/admob/answer/7676680?hl=en
85
+ """
86
+
87
+ http_timeout: Optional[int] = None
88
+ """
89
+ A custom timeout (in milliseconds) for HTTPS calls during an ad request.
90
+
91
+ Note:
92
+ This is only supported in Android. (ignored on iOS)
93
+ """
94
+
95
+ extras: Optional[dict[str, str]] = None
96
+ """
97
+ Extras to pass to the AdMob adapter.
98
+ """
99
+
100
+
101
+ class NativeAdTemplateType(Enum):
102
+ SMALL = "small"
103
+ MEDIUM = "medium"
104
+
105
+
106
+ class NativeTemplateFontStyle(Enum):
107
+ NORMAL = "normal"
108
+ BOLD = "bold"
109
+ ITALIC = "italic"
110
+ MONOSPACE = "monospace"
111
+
112
+
113
+ @dataclass
114
+ class NativeAdTemplateTextStyle:
115
+ size: Optional[ft.Number] = None
116
+ text_color: Optional[ft.ColorValue] = None
117
+ bgcolor: Optional[ft.ColorValue] = None
118
+ style: Optional[NativeTemplateFontStyle] = None
119
+
120
+
121
+ @dataclass
122
+ class NativeAdTemplateStyle:
123
+ template_type: NativeAdTemplateType = NativeAdTemplateType.MEDIUM
124
+ main_bgcolor: Optional[ft.ColorValue] = None
125
+ corner_radius: Optional[ft.Number] = None
126
+ call_to_action_text_style: Optional[NativeAdTemplateTextStyle] = None
127
+ primary_text_style: Optional[NativeAdTemplateTextStyle] = None
128
+ secondary_text_style: Optional[NativeAdTemplateTextStyle] = None
129
+ tertiary_text_style: Optional[NativeAdTemplateTextStyle] = None
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: flet-ads
3
+ Version: 0.2.0.dev34
4
+ Summary: Display Google Ads in Flet apps.
5
+ Author-email: Flet contributors <hello@flet.dev>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://flet.dev
8
+ Project-URL: Documentation, https://flet-dev.github.io/flet-ads
9
+ Project-URL: Repository, https://github.com/flet-dev/flet-ads
10
+ Project-URL: Issues, https://github.com/flet-dev/flet-ads/issues
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: flet>=0.70.0
15
+ Dynamic: license-file
16
+
17
+ # flet-ads
18
+
19
+ [![pypi](https://img.shields.io/pypi/v/flet-ads.svg)](https://pypi.python.org/pypi/flet-ads)
20
+ [![downloads](https://static.pepy.tech/badge/flet-ads/month)](https://pepy.tech/project/flet-ads)
21
+ [![license](https://img.shields.io/github/license/flet-dev/flet-ads.svg)](https://github.com/flet-dev/flet-ads/blob/main/LICENSE)
22
+
23
+ Display Google Ads in [Flet](https://flet.dev) apps.
24
+
25
+ It is based on the [google_mobile_ads](https://pub.dev/packages/google_mobile_ads) Flutter package.
26
+
27
+ ## Documentation
28
+
29
+ Detailed documentation to this package can be found [here](https://flet-dev.github.io/flet-ads/).
30
+
31
+ ## Platform Support
32
+
33
+ This package supports the following platforms:
34
+
35
+ | Platform | Supported |
36
+ |----------|:---------:|
37
+ | Windows | ❌ |
38
+ | macOS | ❌ |
39
+ | Linux | ❌ |
40
+ | iOS | ✅ |
41
+ | Android | ✅ |
42
+ | Web | ❌ |
43
+
44
+ ## Installation
45
+
46
+ To install the `flet-ads` package and add it to your project dependencies:
47
+
48
+ - Using `uv`:
49
+ ```bash
50
+ uv add flet-ads
51
+ ```
52
+
53
+ - Using `pip`:
54
+ ```bash
55
+ pip install flet-ads
56
+ ```
57
+ After this, you will have to manually add this package to your `requirements.txt` or `pyproject.toml`.
58
+
59
+ - Using `poetry`:
60
+ ```bash
61
+ poetry add flet-ads
62
+ ```
63
+
64
+ ## Examples
65
+
66
+ For examples, see [this](./examples)
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/flet_ads/__init__.py
5
+ src/flet_ads/banner_ad.py
6
+ src/flet_ads/base_ad.py
7
+ src/flet_ads/interstitial_ad.py
8
+ src/flet_ads/native_ad.py
9
+ src/flet_ads/types.py
10
+ src/flet_ads.egg-info/PKG-INFO
11
+ src/flet_ads.egg-info/SOURCES.txt
12
+ src/flet_ads.egg-info/dependency_links.txt
13
+ src/flet_ads.egg-info/requires.txt
14
+ src/flet_ads.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ flet>=0.70.0
flet_ads-0.1.0/PKG-INFO DELETED
@@ -1,97 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: flet-ads
3
- Version: 0.1.0
4
- Summary: Ads controls for Flet
5
- Author-email: Flet contributors <hello@flet.dev>
6
- Project-URL: Homepage, https://flet.dev
7
- Project-URL: Documentation, https://flet.dev/docs/controls/ads
8
- Project-URL: Repository, https://github.com/flet-dev/flet-ads
9
- Project-URL: Issues, https://github.com/flet-dev/flet-ads/issues
10
- Classifier: License :: OSI Approved :: Apache Software License
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: flet>=0.25.2
14
-
15
- # Ads controls for Flet
16
-
17
- `BannerAd` and `InterstitialAd` controls for Flet.
18
-
19
- ## Usage
20
-
21
- Add `flet-ads` as dependency (`pyproject.toml` or `requirements.txt`) to your Flet project.
22
-
23
- ## Example
24
-
25
- ```py
26
-
27
- import flet as ft
28
-
29
- import flet_ads as ads
30
-
31
-
32
- def main(page: ft.Page):
33
- page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
34
-
35
- id_interstitial = (
36
- "ca-app-pub-3940256099942544/1033173712"
37
- if page.platform == ft.PagePlatform.ANDROID
38
- else "ca-app-pub-3940256099942544/4411468910"
39
- )
40
-
41
- id_banner = (
42
- "ca-app-pub-3940256099942544/6300978111"
43
- if page.platform == ft.PagePlatform.ANDROID
44
- else "ca-app-pub-3940256099942544/2934735716"
45
- )
46
-
47
- def handle_interstitial_close(e):
48
- nonlocal iad
49
- print("InterstitialAd closed")
50
- page.overlay.remove(e.control)
51
- page.overlay.append(iad := get_new_interstitial_ad())
52
- page.update()
53
-
54
- def get_new_interstitial_ad():
55
- return ads.InterstitialAd(
56
- unit_id=id_interstitial,
57
- on_load=lambda e: print("InterstitialAd loaded"),
58
- on_error=lambda e: print("InterstitialAd error", e.data),
59
- on_open=lambda e: print("InterstitialAd opened"),
60
- on_close=handle_interstitial_close,
61
- on_impression=lambda e: print("InterstitialAd impression"),
62
- on_click=lambda e: print("InterstitialAd clicked"),
63
- )
64
-
65
- def display_new_banner_ad():
66
- page.add(
67
- ft.Container(
68
- content=ads.BannerAd(
69
- unit_id=id_banner,
70
- on_click=lambda e: print("BannerAd clicked"),
71
- on_load=lambda e: print("BannerAd loaded"),
72
- on_error=lambda e: print("BannerAd error", e.data),
73
- on_open=lambda e: print("BannerAd opened"),
74
- on_close=lambda e: print("BannerAd closed"),
75
- on_impression=lambda e: print("BannerAd impression"),
76
- on_will_dismiss=lambda e: print("BannerAd will dismiss"),
77
- ),
78
- width=320,
79
- height=50,
80
- bgcolor=ft.colors.TRANSPARENT,
81
- )
82
- )
83
-
84
- page.overlay.append(iad := get_new_interstitial_ad())
85
- page.appbar = ft.AppBar(
86
- adaptive=True,
87
- title=ft.Text("Mobile Ads Playground"),
88
- bgcolor=ft.colors.LIGHT_BLUE_300,
89
- )
90
- page.add(
91
- ft.OutlinedButton("Show InterstitialAd", on_click=lambda e: iad.show()),
92
- ft.OutlinedButton("Show BannerAd", on_click=lambda e: display_new_banner_ad()),
93
- )
94
-
95
-
96
- ft.app(main)
97
- ```