From d708e5f878d2b4ce224cb03ce3d1f82939cc7da7 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 28 Jul 2026 11:39:08 +0200 Subject: [PATCH 1/4] fix(ads): move platform guard to before_update so ad controls are constructable The mobile-only guard read self.page inside init(), which runs at construction before the control is mounted, so self.page raised "must be added to the page first" for every ad (BannerAd, InterstitialAd, NativeAd, ConsentManager). Move it back to before_update(), a post-mount hook where self.page resolves. Fixes #6726 --- sdk/python/packages/flet-ads/src/flet_ads/base_ad.py | 4 ++-- sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/python/packages/flet-ads/src/flet_ads/base_ad.py b/sdk/python/packages/flet-ads/src/flet_ads/base_ad.py index f64da9d242..a1670f0594 100644 --- a/sdk/python/packages/flet-ads/src/flet_ads/base_ad.py +++ b/sdk/python/packages/flet-ads/src/flet_ads/base_ad.py @@ -66,8 +66,8 @@ class BaseAd(ft.BaseControl): Called when this ad is clicked. """ - def init(self): - super().init() + def before_update(self): + super().before_update() if self.page.web or not self.page.platform.is_mobile(): raise ft.FletUnsupportedPlatformException( f"{self.__class__.__name__} is only supported on " diff --git a/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py b/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py index e7e7208e93..7be4b58989 100644 --- a/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py +++ b/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py @@ -33,8 +33,8 @@ class ConsentManager(ft.Service): a web and/or non-mobile platform. """ # noqa: E501 - def init(self): - super().init() + def before_update(self): + super().before_update() if self.page.web or not self.page.platform.is_mobile(): raise ft.FletUnsupportedPlatformException( f"{self.__class__.__name__} is only supported on " From bbeffac719153cddbc701bf7196d888602aecd86 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 28 Jul 2026 11:39:08 +0200 Subject: [PATCH 2/4] docs(changelog): add entry for flet_ads construction fix (#6726) --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 561b94a4cd..abe138689d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.86.4 + +### Bug fixes + +* Fix every `flet_ads` control (`BannerAd`, `InterstitialAd`, `NativeAd`, `ConsentManager`) crashing on construction with `RuntimeError: (N) Control must be added to the page first`, which made the package unusable since 0.85. The mobile-only platform guard read `self.page` from `init()`, which runs at construction — before the control is attached to the page — so the parent-chain lookup raised. The guard is back in `before_update()`, a post-mount hook where `self.page` resolves, so ads construct freely and only reject web/desktop at mount time ([#6726](https://github.com/flet-dev/flet/issues/6726)) by @ndonkoHenri. + ## 0.86.3 ### Bug fixes From 7aac1b8d6d625f1c42dad42b4aa20012969202d6 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 28 Jul 2026 12:00:58 +0200 Subject: [PATCH 3/4] docs(changelog): reference PR #6735 in the flet_ads fix entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abe138689d..f12d0a31e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Bug fixes -* Fix every `flet_ads` control (`BannerAd`, `InterstitialAd`, `NativeAd`, `ConsentManager`) crashing on construction with `RuntimeError: (N) Control must be added to the page first`, which made the package unusable since 0.85. The mobile-only platform guard read `self.page` from `init()`, which runs at construction — before the control is attached to the page — so the parent-chain lookup raised. The guard is back in `before_update()`, a post-mount hook where `self.page` resolves, so ads construct freely and only reject web/desktop at mount time ([#6726](https://github.com/flet-dev/flet/issues/6726)) by @ndonkoHenri. +* Fix every `flet_ads` control (`BannerAd`, `InterstitialAd`, `NativeAd`, `ConsentManager`) crashing on construction with `RuntimeError: (N) Control must be added to the page first`, which made the package unusable since 0.85. The mobile-only platform guard read `self.page` from `init()`, which runs at construction — before the control is attached to the page — so the parent-chain lookup raised. The guard is back in `before_update()`, a post-mount hook where `self.page` resolves, so ads construct freely and only reject web/desktop at mount time ([#6726](https://github.com/flet-dev/flet/issues/6726), [#6735](https://github.com/flet-dev/flet/pull/6735)) by @ndonkoHenri. ## 0.86.3 From 4550cdeb7d184f30a24e1642902477ae2d678b95 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 28 Jul 2026 12:42:36 +0200 Subject: [PATCH 4/4] docs(ads): fix ConsentManager Raises note for before_update lifecycle The mobile-only guard now runs in before_update() (at mount), not per method call, so the docstring no longer claims the exception is raised "when any of its methods are called". Matches the wording used by the other ad controls. Addresses Copilot review feedback on #6735. --- sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py b/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py index 7be4b58989..61427b5a93 100644 --- a/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py +++ b/sdk/python/packages/flet-ads/src/flet_ads/consent_manager.py @@ -29,8 +29,8 @@ class ConsentManager(ft.Service): More info in the [AdMob documentation](https://developers.google.com/admob/flutter/privacy). Raises: - FletUnsupportedPlatformException: When any of its methods are called on - a web and/or non-mobile platform. + FletUnsupportedPlatformException: When used on a web and/or non-mobile + platform. """ # noqa: E501 def before_update(self):