Skip to content

Commit 3ad18c7

Browse files
content: Open links in-app on Android
`url_launcher` plugin now supports the desired behavior, which is using Android Custom Tabs, so we don't need the workaround of opening the links in external browser anymore, thus removed them. Upstream PR: flutter/packages#4739 Fixes #279
1 parent b10296f commit 3ad18c7

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

lib/widgets/content.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,7 @@ void _launchUrl(BuildContext context, String urlString) async {
673673
bool launched = false;
674674
String? errorMessage;
675675
try {
676-
launched = await ZulipBinding.instance.launchUrl(url,
677-
mode: switch (Theme.of(context).platform) {
678-
// TODO(#279): On Android we settle for LaunchMode.externalApplication
679-
// because url_launcher's in-app is a weirdly bare UX.
680-
// Switch once that's fixed upstream (by us or otherwise).
681-
TargetPlatform.android => UrlLaunchMode.externalApplication,
682-
_ => UrlLaunchMode.platformDefault,
683-
},
684-
);
676+
launched = await ZulipBinding.instance.launchUrl(url);
685677
} on PlatformException catch (e) {
686678
errorMessage = e.message;
687679
}

pubspec.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -921,26 +921,26 @@ packages:
921921
dependency: "direct main"
922922
description:
923923
name: url_launcher
924-
sha256: "781bd58a1eb16069412365c98597726cd8810ae27435f04b3b4d3a470bacd61e"
924+
sha256: "47e208a6711459d813ba18af120d9663c20bdf6985d6ad39fe165d2538378d27"
925925
url: "https://pub.dev"
926926
source: hosted
927-
version: "6.1.12"
927+
version: "6.1.14"
928928
url_launcher_android:
929929
dependency: transitive
930930
description:
931931
name: url_launcher_android
932-
sha256: "3dd2388cc0c42912eee04434531a26a82512b9cb1827e0214430c9bcbddfe025"
932+
sha256: b04af59516ab45762b2ca6da40fa830d72d0f6045cd97744450b73493fa76330
933933
url: "https://pub.dev"
934934
source: hosted
935-
version: "6.0.38"
935+
version: "6.1.0"
936936
url_launcher_ios:
937937
dependency: transitive
938938
description:
939939
name: url_launcher_ios
940-
sha256: "9af7ea73259886b92199f9e42c116072f05ff9bea2dcb339ab935dfc957392c2"
940+
sha256: "7c65021d5dee51813d652357bc65b8dd4a6177082a9966bc8ba6ee477baa795f"
941941
url: "https://pub.dev"
942942
source: hosted
943-
version: "6.1.4"
943+
version: "6.1.5"
944944
url_launcher_linux:
945945
dependency: transitive
946946
description:
@@ -953,10 +953,10 @@ packages:
953953
dependency: transitive
954954
description:
955955
name: url_launcher_macos
956-
sha256: "1c4fdc0bfea61a70792ce97157e5cc17260f61abbe4f39354513f39ec6fd73b1"
956+
sha256: b55486791f666e62e0e8ff825e58a023fd6b1f71c49926483f1128d3bbd8fe88
957957
url: "https://pub.dev"
958958
source: hosted
959-
version: "3.0.6"
959+
version: "3.0.7"
960960
url_launcher_platform_interface:
961961
dependency: transitive
962962
description:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies:
5656
image_picker: ^1.0.0
5757
package_info_plus: ^4.0.1
5858
collection: ^1.17.2
59-
url_launcher: ^6.1.11
59+
url_launcher: ^6.1.14
6060

6161
dev_dependencies:
6262
flutter_test:

test/widgets/content_test.dart

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:io';
22

33
import 'package:checks/checks.dart';
4-
import 'package:flutter/foundation.dart';
54
import 'package:flutter/material.dart';
65
import 'package:flutter_test/flutter_test.dart';
76
import 'package:url_launcher/url_launcher.dart';
@@ -57,8 +56,6 @@ void main() {
5756
});
5857

5958
group('LinkNode interactions', () {
60-
const expectedModeAndroid = LaunchMode.externalApplication;
61-
6259
// The Flutter test font uses square glyphs, so width equals height:
6360
// https://github.com/flutter/flutter/wiki/Flutter-Test-Fonts
6461
const fontSize = 48.0;
@@ -80,10 +77,8 @@ void main() {
8077
'<p><a href="https://example/">hello</a></p>');
8178

8279
await tester.tap(find.text('hello'));
83-
final expectedMode = defaultTargetPlatform == TargetPlatform.android ?
84-
LaunchMode.externalApplication : LaunchMode.platformDefault;
8580
check(testBinding.takeLaunchUrlCalls())
86-
.single.equals((url: Uri.parse('https://example/'), mode: expectedMode));
81+
.single.equals((url: Uri.parse('https://example/'), mode: LaunchMode.platformDefault));
8782
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
8883

8984
testWidgets('multiple links in paragraph', (tester) async {
@@ -97,19 +92,19 @@ void main() {
9792

9893
await tester.tapAt(base.translate(1*fontSize, 0)); // "fXo bar baz"
9994
check(testBinding.takeLaunchUrlCalls())
100-
.single.equals((url: Uri.parse('https://a/'), mode: expectedModeAndroid));
95+
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
10196

10297
await tester.tapAt(base.translate(9*fontSize, 0)); // "foo bar bXz"
10398
check(testBinding.takeLaunchUrlCalls())
104-
.single.equals((url: Uri.parse('https://b/'), mode: expectedModeAndroid));
99+
.single.equals((url: Uri.parse('https://b/'), mode: LaunchMode.platformDefault));
105100
});
106101

107102
testWidgets('link nested in other spans', (tester) async {
108103
await prepareContent(tester,
109104
'<p><strong><em><a href="https://a/">word</a></em></strong></p>');
110105
await tester.tap(find.text('word'));
111106
check(testBinding.takeLaunchUrlCalls())
112-
.single.equals((url: Uri.parse('https://a/'), mode: expectedModeAndroid));
107+
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
113108
});
114109

115110
testWidgets('link containing other spans', (tester) async {
@@ -120,27 +115,27 @@ void main() {
120115

121116
await tester.tapAt(base.translate(1*fontSize, 0)); // "tXo words"
122117
check(testBinding.takeLaunchUrlCalls())
123-
.single.equals((url: Uri.parse('https://a/'), mode: expectedModeAndroid));
118+
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
124119

125120
await tester.tapAt(base.translate(6*fontSize, 0)); // "two woXds"
126121
check(testBinding.takeLaunchUrlCalls())
127-
.single.equals((url: Uri.parse('https://a/'), mode: expectedModeAndroid));
122+
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
128123
});
129124

130125
testWidgets('relative links are resolved', (tester) async {
131126
await prepareContent(tester,
132127
'<p><a href="/a/b?c#d">word</a></p>');
133128
await tester.tap(find.text('word'));
134129
check(testBinding.takeLaunchUrlCalls())
135-
.single.equals((url: Uri.parse('${eg.realmUrl}a/b?c#d'), mode: expectedModeAndroid));
130+
.single.equals((url: Uri.parse('${eg.realmUrl}a/b?c#d'), mode: LaunchMode.platformDefault));
136131
});
137132

138133
testWidgets('link inside HeadingNode', (tester) async {
139134
await prepareContent(tester,
140135
'<h6><a href="https://a/">word</a></h6>');
141136
await tester.tap(find.text('word'));
142137
check(testBinding.takeLaunchUrlCalls())
143-
.single.equals((url: Uri.parse('https://a/'), mode: expectedModeAndroid));
138+
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
144139
});
145140

146141
testWidgets('error dialog if invalid link', (tester) async {
@@ -150,7 +145,7 @@ void main() {
150145
await tester.tap(find.text('word'));
151146
await tester.pump();
152147
check(testBinding.takeLaunchUrlCalls())
153-
.single.equals((url: Uri.parse('file:///etc/bad'), mode: expectedModeAndroid));
148+
.single.equals((url: Uri.parse('file:///etc/bad'), mode: LaunchMode.platformDefault));
154149
checkErrorDialog(tester, expectedTitle: 'Unable to open link');
155150
});
156151
});

0 commit comments

Comments
 (0)