Skip to content

Commit 37df02b

Browse files
committed
refactor(headlines-search): improve ad experience in country item widget
- Make the tap action asynchronous to await for the ad to be shown and dismissed - Add a check to ensure the widget is still in the tree before navigating - Proceed with navigation after the ad is closed to provide a smoother user experience
1 parent 9241723 commit 37df02b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/headlines-search/widgets/country_item_widget.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ class CountryItemWidget extends StatelessWidget {
2121
subtitle: country.isoCode.isNotEmpty
2222
? Text(country.isoCode, maxLines: 1, overflow: TextOverflow.ellipsis)
2323
: null,
24-
onTap: () {
25-
context.read<InterstitialAdManager>().onPotentialAdTrigger();
26-
context.pushNamed(
24+
onTap: () async {
25+
// Await for the ad to be shown and dismissed.
26+
await context.read<InterstitialAdManager>().onPotentialAdTrigger();
27+
28+
// Check if the widget is still in the tree before navigating.
29+
if (!context.mounted) return;
30+
31+
// Proceed with navigation after the ad is closed.
32+
await context.pushNamed(
2733
Routes.entityDetailsName,
2834
pathParameters: {'type': ContentType.country.name, 'id': country.id},
2935
);

0 commit comments

Comments
 (0)