Skip to content

Commit 3093050

Browse files
committed
refactor(account): improve ad trigger and navigation flow
- Convert onHeadlineTap to an async function - Add await for interstitial ad presentation - Check if context is still mounted before navigation - Add await for navigation after ad is closed
1 parent 83790d8 commit 3093050

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/account/view/saved_headlines_page.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ class SavedHeadlinesPage extends StatelessWidget {
7272
);
7373
}
7474

75-
void onHeadlineTap(Headline headline) {
76-
context.read<InterstitialAdManager>().onPotentialAdTrigger();
77-
context.goNamed(
75+
Future<void> onHeadlineTap(Headline headline) async {
76+
// Await for the ad to be shown and dismissed.
77+
await context.read<InterstitialAdManager>().onPotentialAdTrigger();
78+
79+
// Check if the widget is still in the tree before navigating.
80+
if (!context.mounted) return;
81+
82+
// Proceed with navigation after the ad is closed.
83+
await context.pushNamed(
7884
Routes.accountArticleDetailsName,
7985
pathParameters: {'id': headline.id},
8086
extra: headline,

0 commit comments

Comments
 (0)