Skip to content

Commit cefd3b8

Browse files
committed
fix(ads): use url_launcher to open interstitial ad URLs
- Replace GoRouter with url_launcher for opening external URLs - Handle URL launching failures gracefully - Update imports and remove unused packages
1 parent 1501cf1 commit cefd3b8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/ads/widgets/local_interstitial_ad_dialog.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:go_router/go_router.dart';
43
import 'package:ui_kit/ui_kit.dart';
4+
import 'package:url_launcher/url_launcher.dart'; // Import url_launcher
55

66
/// {@template local_interstitial_ad_dialog}
77
/// A dialog widget that displays a [LocalInterstitialAd].
@@ -36,10 +36,17 @@ class LocalInterstitialAdDialog extends StatelessWidget {
3636
Padding(
3737
padding: const EdgeInsets.all(AppSpacing.lg),
3838
child: InkWell(
39-
onTap: () {
40-
// Navigate to the target URL when the ad image is tapped.
41-
// Using context.go to open external URL.
42-
context.go(localInterstitialAd.targetUrl);
39+
onTap: () async {
40+
// Launch the target URL in an external browser.
41+
final uri = Uri.parse(localInterstitialAd.targetUrl);
42+
if (await canLaunchUrl(uri)) {
43+
await launchUrl(uri);
44+
} else {
45+
// Log an error or show a user-friendly message
46+
// if the URL cannot be launched.
47+
// For now, we'll just print to debug console.
48+
debugPrint('Could not launch ${localInterstitialAd.targetUrl}');
49+
}
4350
},
4451
child: Image.network(
4552
localInterstitialAd.imageUrl,

0 commit comments

Comments
 (0)