Skip to content

Commit 57d849e

Browse files
committed
refactor(headlines-search): improve ad experience in source item widget
- Add async/await to onTap callback for smoother ad display - Check if context is still mounted before navigation - Improve user experience by ensuring ads are fully viewed before page transition
1 parent 37df02b commit 57d849e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/headlines-search/widgets/source_item_widget.dart

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

0 commit comments

Comments
 (0)