Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit e76b994

Browse files
committed
Move away from shared method channel implementation in native packages.
1 parent 72dff1b commit e76b994

File tree

26 files changed

+1713
-17
lines changed

26 files changed

+1713
-17
lines changed

packages/url_launcher/url_launcher_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.15
2+
3+
* Moved away from shared method channel implementation.
4+
15
## 6.0.14
26

37
* Updates code for new analysis options.

packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/MethodCallHandlerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void startListening(BinaryMessenger messenger) {
6161
stopListening();
6262
}
6363

64-
channel = new MethodChannel(messenger, "plugins.flutter.io/url_launcher");
64+
channel = new MethodChannel(messenger, "plugins.flutter.io/url_launcher_android");
6565
channel.setMethodCallHandler(this);
6666
}
6767

packages/url_launcher/url_launcher_android/android/src/test/java/io/flutter/plugins/urllauncher/MethodCallHandlerImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
@RunWith(RobolectricTestRunner.class)
2929
public class MethodCallHandlerImplTest {
30-
private static final String CHANNEL_NAME = "plugins.flutter.io/url_launcher";
30+
private static final String CHANNEL_NAME = "plugins.flutter.io/url_launcher_android";
3131
private UrlLauncher urlLauncher;
3232
private MethodCallHandlerImpl methodCallHandler;
3333

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:flutter/services.dart';
8+
import 'package:url_launcher_platform_interface/link.dart';
9+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
10+
11+
const MethodChannel _channel =
12+
MethodChannel('plugins.flutter.io/url_launcher_android');
13+
14+
/// An implementation of [UrlLauncherPlatform] that uses method channels.
15+
class UrlLauncherAndroid extends UrlLauncherPlatform {
16+
/// Registers this class as the default instance of [UrlLauncherPlatform].
17+
static void registerWith() {
18+
UrlLauncherPlatform.instance = UrlLauncherAndroid();
19+
}
20+
21+
@override
22+
final LinkDelegate? linkDelegate = null;
23+
24+
@override
25+
Future<bool> canLaunch(String url) {
26+
return _channel.invokeMethod<bool>(
27+
'canLaunch',
28+
<String, Object>{'url': url},
29+
).then((bool? value) => value ?? false);
30+
}
31+
32+
@override
33+
Future<void> closeWebView() {
34+
return _channel.invokeMethod<void>('closeWebView');
35+
}
36+
37+
@override
38+
Future<bool> launch(
39+
String url, {
40+
required bool useSafariVC,
41+
required bool useWebView,
42+
required bool enableJavaScript,
43+
required bool enableDomStorage,
44+
required bool universalLinksOnly,
45+
required Map<String, String> headers,
46+
String? webOnlyWindowName,
47+
}) {
48+
return _channel.invokeMethod<bool>(
49+
'launch',
50+
<String, Object>{
51+
'url': url,
52+
'useSafariVC': useSafariVC,
53+
'useWebView': useWebView,
54+
'enableJavaScript': enableJavaScript,
55+
'enableDomStorage': enableDomStorage,
56+
'universalLinksOnly': universalLinksOnly,
57+
'headers': headers,
58+
},
59+
).then((bool? value) => value ?? false);
60+
}
61+
}

packages/url_launcher/url_launcher_android/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: url_launcher_android
22
description: Android implementation of the url_launcher plugin.
33
repository: https://github.com/flutter/plugins/tree/main/packages/url_launcher/url_launcher_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
5-
version: 6.0.14
5+
version: 6.0.15
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"
9-
flutter: ">=2.5.0"
9+
flutter: ">=2.8.0"
1010

1111
flutter:
1212
plugin:
@@ -15,6 +15,7 @@ flutter:
1515
android:
1616
package: io.flutter.plugins.urllauncher
1717
pluginClass: UrlLauncherPlugin
18+
dartPluginClass: UrlLauncherAndroid
1819

1920
dependencies:
2021
flutter:
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/services.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:url_launcher_android/url_launcher_android.dart';
8+
9+
void main() {
10+
TestWidgetsFlutterBinding.ensureInitialized();
11+
12+
group('$UrlLauncherAndroid', () {
13+
const MethodChannel channel =
14+
MethodChannel('plugins.flutter.io/url_launcher_android');
15+
final List<MethodCall> log = <MethodCall>[];
16+
channel.setMockMethodCallHandler((MethodCall methodCall) async {
17+
log.add(methodCall);
18+
19+
// Return null explicitly instead of relying on the implicit null
20+
// returned by the method channel if no return statement is specified.
21+
return null;
22+
});
23+
24+
final UrlLauncherAndroid launcher = UrlLauncherAndroid();
25+
26+
tearDown(() {
27+
log.clear();
28+
});
29+
30+
test('canLaunch', () async {
31+
await launcher.canLaunch('http://example.com/');
32+
expect(
33+
log,
34+
<Matcher>[
35+
isMethodCall('canLaunch', arguments: <String, Object>{
36+
'url': 'http://example.com/',
37+
})
38+
],
39+
);
40+
});
41+
42+
test('canLaunch should return false if platform returns null', () async {
43+
final bool canLaunch = await launcher.canLaunch('http://example.com/');
44+
45+
expect(canLaunch, false);
46+
});
47+
48+
test('launch', () async {
49+
await launcher.launch(
50+
'http://example.com/',
51+
useSafariVC: true,
52+
useWebView: false,
53+
enableJavaScript: false,
54+
enableDomStorage: false,
55+
universalLinksOnly: false,
56+
headers: const <String, String>{},
57+
);
58+
expect(
59+
log,
60+
<Matcher>[
61+
isMethodCall('launch', arguments: <String, Object>{
62+
'url': 'http://example.com/',
63+
'useSafariVC': true,
64+
'useWebView': false,
65+
'enableJavaScript': false,
66+
'enableDomStorage': false,
67+
'universalLinksOnly': false,
68+
'headers': <String, String>{},
69+
})
70+
],
71+
);
72+
});
73+
74+
test('launch with headers', () async {
75+
await launcher.launch(
76+
'http://example.com/',
77+
useSafariVC: true,
78+
useWebView: false,
79+
enableJavaScript: false,
80+
enableDomStorage: false,
81+
universalLinksOnly: false,
82+
headers: const <String, String>{'key': 'value'},
83+
);
84+
expect(
85+
log,
86+
<Matcher>[
87+
isMethodCall('launch', arguments: <String, Object>{
88+
'url': 'http://example.com/',
89+
'useSafariVC': true,
90+
'useWebView': false,
91+
'enableJavaScript': false,
92+
'enableDomStorage': false,
93+
'universalLinksOnly': false,
94+
'headers': <String, String>{'key': 'value'},
95+
})
96+
],
97+
);
98+
});
99+
100+
test('launch force SafariVC', () async {
101+
await launcher.launch(
102+
'http://example.com/',
103+
useSafariVC: true,
104+
useWebView: false,
105+
enableJavaScript: false,
106+
enableDomStorage: false,
107+
universalLinksOnly: false,
108+
headers: const <String, String>{},
109+
);
110+
expect(
111+
log,
112+
<Matcher>[
113+
isMethodCall('launch', arguments: <String, Object>{
114+
'url': 'http://example.com/',
115+
'useSafariVC': true,
116+
'useWebView': false,
117+
'enableJavaScript': false,
118+
'enableDomStorage': false,
119+
'universalLinksOnly': false,
120+
'headers': <String, String>{},
121+
})
122+
],
123+
);
124+
});
125+
126+
test('launch universal links only', () async {
127+
await launcher.launch(
128+
'http://example.com/',
129+
useSafariVC: false,
130+
useWebView: false,
131+
enableJavaScript: false,
132+
enableDomStorage: false,
133+
universalLinksOnly: true,
134+
headers: const <String, String>{},
135+
);
136+
expect(
137+
log,
138+
<Matcher>[
139+
isMethodCall('launch', arguments: <String, Object>{
140+
'url': 'http://example.com/',
141+
'useSafariVC': false,
142+
'useWebView': false,
143+
'enableJavaScript': false,
144+
'enableDomStorage': false,
145+
'universalLinksOnly': true,
146+
'headers': <String, String>{},
147+
})
148+
],
149+
);
150+
});
151+
152+
test('launch force WebView', () async {
153+
await launcher.launch(
154+
'http://example.com/',
155+
useSafariVC: true,
156+
useWebView: true,
157+
enableJavaScript: false,
158+
enableDomStorage: false,
159+
universalLinksOnly: false,
160+
headers: const <String, String>{},
161+
);
162+
expect(
163+
log,
164+
<Matcher>[
165+
isMethodCall('launch', arguments: <String, Object>{
166+
'url': 'http://example.com/',
167+
'useSafariVC': true,
168+
'useWebView': true,
169+
'enableJavaScript': false,
170+
'enableDomStorage': false,
171+
'universalLinksOnly': false,
172+
'headers': <String, String>{},
173+
})
174+
],
175+
);
176+
});
177+
178+
test('launch force WebView enable javascript', () async {
179+
await launcher.launch(
180+
'http://example.com/',
181+
useSafariVC: true,
182+
useWebView: true,
183+
enableJavaScript: true,
184+
enableDomStorage: false,
185+
universalLinksOnly: false,
186+
headers: const <String, String>{},
187+
);
188+
expect(
189+
log,
190+
<Matcher>[
191+
isMethodCall('launch', arguments: <String, Object>{
192+
'url': 'http://example.com/',
193+
'useSafariVC': true,
194+
'useWebView': true,
195+
'enableJavaScript': true,
196+
'enableDomStorage': false,
197+
'universalLinksOnly': false,
198+
'headers': <String, String>{},
199+
})
200+
],
201+
);
202+
});
203+
204+
test('launch force WebView enable DOM storage', () async {
205+
await launcher.launch(
206+
'http://example.com/',
207+
useSafariVC: true,
208+
useWebView: true,
209+
enableJavaScript: false,
210+
enableDomStorage: true,
211+
universalLinksOnly: false,
212+
headers: const <String, String>{},
213+
);
214+
expect(
215+
log,
216+
<Matcher>[
217+
isMethodCall('launch', arguments: <String, Object>{
218+
'url': 'http://example.com/',
219+
'useSafariVC': true,
220+
'useWebView': true,
221+
'enableJavaScript': false,
222+
'enableDomStorage': true,
223+
'universalLinksOnly': false,
224+
'headers': <String, String>{},
225+
})
226+
],
227+
);
228+
});
229+
230+
test('launch force SafariVC to false', () async {
231+
await launcher.launch(
232+
'http://example.com/',
233+
useSafariVC: false,
234+
useWebView: false,
235+
enableJavaScript: false,
236+
enableDomStorage: false,
237+
universalLinksOnly: false,
238+
headers: const <String, String>{},
239+
);
240+
expect(
241+
log,
242+
<Matcher>[
243+
isMethodCall('launch', arguments: <String, Object>{
244+
'url': 'http://example.com/',
245+
'useSafariVC': false,
246+
'useWebView': false,
247+
'enableJavaScript': false,
248+
'enableDomStorage': false,
249+
'universalLinksOnly': false,
250+
'headers': <String, String>{},
251+
})
252+
],
253+
);
254+
});
255+
256+
test('launch should return false if platform returns null', () async {
257+
final bool launched = await launcher.launch(
258+
'http://example.com/',
259+
useSafariVC: true,
260+
useWebView: false,
261+
enableJavaScript: false,
262+
enableDomStorage: false,
263+
universalLinksOnly: false,
264+
headers: const <String, String>{},
265+
);
266+
267+
expect(launched, false);
268+
});
269+
270+
test('closeWebView default behavior', () async {
271+
await launcher.closeWebView();
272+
expect(
273+
log,
274+
<Matcher>[isMethodCall('closeWebView', arguments: null)],
275+
);
276+
});
277+
});
278+
}

packages/url_launcher/url_launcher_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.15
2+
3+
* Moved away from shared method channel implementation.
4+
15
## 6.0.14
26

37
* Updates code for new analysis options.

0 commit comments

Comments
 (0)