Skip to content

Commit 707f237

Browse files
committed
refactor(shared): replace url_launcher with InAppBrowser for internal navigation
- Replace url_launcher package with custom InAppBrowser for internal navigation - Update HeadlineTapHandler to use InAppBrowser for internal navigation - Maintain external application launch for external navigation - Remove dependency on url_launcher_string.dart
1 parent 2975ffa commit 707f237

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/shared/widgets/feed_core/headline_tap_handler.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import 'package:flutter/material.dart';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/ads/services/interstitial_ad_manager.dart';
88
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
9-
import 'package:url_launcher/url_launcher_string.dart';
9+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/in_app_browser.dart';
10+
import 'package:url_launcher/url_launcher.dart';
1011

1112
/// {@template headline_tap_handler}
1213
/// A utility class for handling headline taps, including interstitial ad
@@ -44,12 +45,16 @@ abstract final class HeadlineTapHandler {
4445
behavior = appState.remoteConfig?.features.feed.itemClickBehavior;
4546
}
4647

47-
final mode = behavior == FeedItemClickBehavior.internalNavigation
48-
? LaunchMode.inAppWebView
49-
: LaunchMode.externalApplication;
50-
51-
if (await canLaunchUrlString(headline.url)) {
52-
await launchUrlString(headline.url, mode: mode);
48+
// Use the new InAppBrowser for internal navigation, otherwise use url_launcher.
49+
if (behavior == FeedItemClickBehavior.internalNavigation) {
50+
await InAppBrowser.show(context, url: headline.url);
51+
} else {
52+
if (await canLaunchUrl(Uri.parse(headline.url))) {
53+
await launchUrl(
54+
Uri.parse(headline.url),
55+
mode: LaunchMode.externalApplication,
56+
);
57+
}
5358
}
5459
}
5560

@@ -127,8 +132,8 @@ abstract final class HeadlineTapHandler {
127132
final headline = await context.read<DataRepository<Headline>>().read(
128133
id: headlineId,
129134
);
130-
if (context.mounted && await canLaunchUrlString(headline.url)) {
131-
await launchUrlString(headline.url, mode: LaunchMode.inAppWebView);
135+
if (context.mounted) {
136+
await InAppBrowser.show(context, url: headline.url);
132137
}
133138
} finally {
134139
if (navigator.canPop()) navigator.pop();

0 commit comments

Comments
 (0)