Skip to content

Commit 01e7fb7

Browse files
committed
refactor(widgets): enhance entity tap handling in metadata row
- Make _handleEntityTap asynchronous to await ad trigger completion - Add context.mounted check before navigation to prevent errors - Improve method documentation to reflect new behavior
1 parent a4ccb3e commit 01e7fb7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/shared/widgets/feed_core/headline_metadata_row.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ class HeadlineMetadataRow extends StatelessWidget {
4040

4141
/// Handles a tap on an entity (topic or source) within the metadata row.
4242
///
43-
/// This method triggers the interstitial ad manager and navigates to the
44-
/// entity details page.
45-
void _handleEntityTap(BuildContext context, ContentType type, String id) {
46-
context.read<InterstitialAdManager>().onPotentialAdTrigger();
47-
context.pushNamed(
43+
/// This method triggers the interstitial ad manager, awaits its completion,
44+
/// and then navigates to the entity details page.
45+
Future<void> _handleEntityTap(
46+
BuildContext context,
47+
ContentType type,
48+
String id,
49+
) async {
50+
await context.read<InterstitialAdManager>().onPotentialAdTrigger();
51+
52+
// Check if the widget is still in the tree before navigating.
53+
if (!context.mounted) return;
54+
55+
await context.pushNamed(
4856
Routes.entityDetailsName,
4957
pathParameters: {'type': type.name, 'id': id},
5058
);

0 commit comments

Comments
 (0)