Skip to content

Commit 0c9d6ef

Browse files
committed
refactor(headlines-search): improve ad display and navigation flow
- Add asynchronous handling for interstitial ad display - Check widget's mount status before navigation - Ensure smooth transition from ad to entity details screen
1 parent 57d849e commit 0c9d6ef

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/headlines-search/widgets/topic_item_widget.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ class TopicItemWidget 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.topic.name, 'id': topic.id},
3036
);

0 commit comments

Comments
 (0)