Skip to content

Commit 2c858a2

Browse files
committed
fix(account): ensure widget is mounted before navigating
- Add async handling for interstitial ad trigger - Check if context is still mounted before navigation - Improve UX by proceeding with navigation only after ad is closed
1 parent 3093050 commit 2c858a2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/account/view/manage_followed_items/countries/followed_countries_list_page.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,20 @@ class FollowedCountriesListPage extends StatelessWidget {
9696
);
9797
},
9898
),
99-
onTap: () {
100-
context.read<InterstitialAdManager>().onPotentialAdTrigger();
101-
context.pushNamed(
99+
onTap: () async {
100+
// Await for the ad to be shown and dismissed.
101+
await context
102+
.read<InterstitialAdManager>()
103+
.onPotentialAdTrigger();
104+
105+
// Check if the widget is still in the tree before navigating.
106+
if (!context.mounted) return;
107+
108+
// Proceed with navigation after the ad is closed.
109+
await context.pushNamed(
102110
Routes.entityDetailsName,
103111
pathParameters: {
104-
'type': ContentType.country.name, // 'topic'
112+
'type': ContentType.country.name,
105113
'id': country.id,
106114
},
107115
);

0 commit comments

Comments
 (0)