Skip to content

Commit d254cba

Browse files
swift-kimbwikbs
authored andcommitted
[url_launcher] Reimplement based on tizen_app_control (flutter-tizen#288)
1 parent 871e39e commit d254cba

File tree

12 files changed

+93
-223
lines changed

12 files changed

+93
-223
lines changed

packages/url_launcher/CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414

1515
## 1.0.3
1616

17-
* Use `PlatformException` instead of a plugin-specific exception type
18-
(`AppControlException`).
17+
* Use `PlatformException` instead of a plugin-specific exception type.
1918
* Move `app_control.dart` to `src` directory.
2019

2120
## 2.0.0
2221

2322
* Increase Dart and Flutter SDK constraints to 2.12.0 and 2.0.0.
2423
* Update Flutter copyright information.
25-
* Update example and integration_test.
26-
* Update platform interface to 2.0.2.
24+
* Update the example app and integration_test.
25+
* Update url_launcher_platform_interface to 2.0.2.
2726
* Organize dev_dependencies.
2827
* Migrate to ffi 1.0.0.
2928
* Migrate to null safety.
@@ -34,6 +33,13 @@
3433
* Use `get_error_message()` for error message conversion.
3534
* Use more typedefs.
3635
* Update url_launcher to 6.0.9.
37-
* Update platform interface to 2.0.4.
36+
* Update url_launcher_platform_interface to 2.0.4.
3837
* Remove `@dart=2.9` from test files.
3938
* Sync the example code.
39+
40+
## 2.1.0
41+
42+
* Update url_launcher to 6.0.17.
43+
* Add tizen_app_control dependency and remove the FFI-based implementation.
44+
* Switch to new analysis options.
45+
* Update the example app.

packages/url_launcher/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This package is not an _endorsed_ implementation of `url_launcher`. Therefore, y
1010

1111
```yaml
1212
dependencies:
13-
url_launcher: ^6.0.9
14-
url_launcher_tizen: ^2.0.1
13+
url_launcher: ^6.0.17
14+
url_launcher_tizen: ^2.1.0
1515
```
1616
1717
Then you can import `url_launcher` in your Dart code:

packages/url_launcher/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/url_launcher/example/integration_test/url_launcher_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void main() {
1717

1818
// Generally all devices should have some default browser.
1919
expect(await canLaunch('http://flutter.dev'), true);
20+
expect(await canLaunch('https://www.google.com/404'), true);
2021

2122
// SMS handling is available by default on most platforms.
2223
if (kIsWeb || !(Platform.isLinux || Platform.isWindows)) {

packages/url_launcher/example/lib/main.dart

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,88 +22,90 @@ class MyApp extends StatelessWidget {
2222
theme: ThemeData(
2323
primarySwatch: Colors.blue,
2424
),
25-
home: MyHomePage(title: 'URL Launcher'),
25+
home: const MyHomePage(title: 'URL Launcher'),
2626
);
2727
}
2828
}
2929

3030
class MyHomePage extends StatefulWidget {
31-
MyHomePage({Key? key, required this.title}) : super(key: key);
31+
const MyHomePage({Key? key, required this.title}) : super(key: key);
3232
final String title;
3333

3434
@override
3535
_MyHomePageState createState() => _MyHomePageState();
3636
}
3737

3838
class _MyHomePageState extends State<MyHomePage> {
39+
bool _hasCallSupport = false;
3940
Future<void>? _launched;
4041
String _phone = '';
4142

43+
@override
44+
void initState() {
45+
super.initState();
46+
// Check for phone call support.
47+
canLaunch('tel:123').then((bool result) {
48+
setState(() {
49+
_hasCallSupport = result;
50+
});
51+
});
52+
}
53+
4254
Future<void> _launchInBrowser(String url) async {
43-
if (await canLaunch(url)) {
44-
await launch(
45-
url,
46-
forceSafariVC: false,
47-
forceWebView: false,
48-
headers: <String, String>{'my_header_key': 'my_header_value'},
49-
);
50-
} else {
55+
if (!await launch(
56+
url,
57+
forceSafariVC: false,
58+
forceWebView: false,
59+
headers: <String, String>{'my_header_key': 'my_header_value'},
60+
)) {
5161
throw 'Could not launch $url';
5262
}
5363
}
5464

5565
Future<void> _launchInWebViewOrVC(String url) async {
56-
if (await canLaunch(url)) {
57-
await launch(
58-
url,
59-
forceSafariVC: true,
60-
forceWebView: true,
61-
headers: <String, String>{'my_header_key': 'my_header_value'},
62-
);
63-
} else {
66+
if (!await launch(
67+
url,
68+
forceSafariVC: true,
69+
forceWebView: true,
70+
headers: <String, String>{'my_header_key': 'my_header_value'},
71+
)) {
6472
throw 'Could not launch $url';
6573
}
6674
}
6775

6876
Future<void> _launchInWebViewWithJavaScript(String url) async {
69-
if (await canLaunch(url)) {
70-
await launch(
71-
url,
72-
forceSafariVC: true,
73-
forceWebView: true,
74-
enableJavaScript: true,
75-
);
76-
} else {
77+
if (!await launch(
78+
url,
79+
forceSafariVC: true,
80+
forceWebView: true,
81+
enableJavaScript: true,
82+
)) {
7783
throw 'Could not launch $url';
7884
}
7985
}
8086

8187
Future<void> _launchInWebViewWithDomStorage(String url) async {
82-
if (await canLaunch(url)) {
83-
await launch(
84-
url,
85-
forceSafariVC: true,
86-
forceWebView: true,
87-
enableDomStorage: true,
88-
);
89-
} else {
88+
if (!await launch(
89+
url,
90+
forceSafariVC: true,
91+
forceWebView: true,
92+
enableDomStorage: true,
93+
)) {
9094
throw 'Could not launch $url';
9195
}
9296
}
9397

9498
Future<void> _launchUniversalLinkIos(String url) async {
95-
if (await canLaunch(url)) {
96-
final bool nativeAppLaunchSucceeded = await launch(
99+
final bool nativeAppLaunchSucceeded = await launch(
100+
url,
101+
forceSafariVC: false,
102+
universalLinksOnly: true,
103+
);
104+
if (!nativeAppLaunchSucceeded) {
105+
await launch(
97106
url,
98-
forceSafariVC: false,
99-
universalLinksOnly: true,
107+
forceSafariVC: true,
100108
);
101-
if (!nativeAppLaunchSucceeded) {
102-
await launch(
103-
url,
104-
forceSafariVC: true,
105-
);
106-
}
107109
}
108110
}
109111

@@ -115,16 +117,22 @@ class _MyHomePageState extends State<MyHomePage> {
115117
}
116118
}
117119

118-
Future<void> _makePhoneCall(String url) async {
119-
if (await canLaunch(url)) {
120-
await launch(url);
121-
} else {
122-
throw 'Could not launch $url';
123-
}
120+
Future<void> _makePhoneCall(String phoneNumber) async {
121+
// Use `Uri` to ensure that `phoneNumber` is properly URL-encoded.
122+
// Just using 'tel:$phoneNumber' would create invalid URLs in some cases,
123+
// such as spaces in the input, which would cause `launch` to fail on some
124+
// platforms.
125+
final Uri launchUri = Uri(
126+
scheme: 'tel',
127+
path: phoneNumber,
128+
);
129+
await launch(launchUri.toString());
124130
}
125131

126132
@override
127133
Widget build(BuildContext context) {
134+
// onPressed calls using this URL are not gated on a 'canLaunch' check
135+
// because the assumption is that every device can launch a web URL.
128136
const String toLaunch = 'https://www.cylog.org/headers/';
129137
return Scaffold(
130138
appBar: AppBar(
@@ -143,10 +151,14 @@ class _MyHomePageState extends State<MyHomePage> {
143151
hintText: 'Input the phone number to launch')),
144152
),
145153
ElevatedButton(
146-
onPressed: () => setState(() {
147-
_launched = _makePhoneCall('tel:$_phone');
148-
}),
149-
child: const Text('Make phone call'),
154+
onPressed: _hasCallSupport
155+
? () => setState(() {
156+
_launched = _makePhoneCall(_phone);
157+
})
158+
: null,
159+
child: _hasCallSupport
160+
? const Text('Make phone call')
161+
: const Text('Calling not supported'),
150162
),
151163
const Padding(
152164
padding: EdgeInsets.all(16.0),
@@ -201,11 +213,11 @@ class _MyHomePageState extends State<MyHomePage> {
201213
uri: Uri.parse(
202214
'https://pub.dev/documentation/url_launcher/latest/link/link-library.html'),
203215
target: LinkTarget.blank,
204-
builder: (ctx, openLink) {
216+
builder: (BuildContext ctx, FollowLink? openLink) {
205217
return TextButton.icon(
206218
onPressed: openLink,
207-
label: Text('Link Widget documentation'),
208-
icon: Icon(Icons.read_more),
219+
label: const Text('Link Widget documentation'),
220+
icon: const Icon(Icons.read_more),
209221
);
210222
},
211223
),

packages/url_launcher/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ publish_to: "none"
55
dependencies:
66
flutter:
77
sdk: flutter
8-
url_launcher: ^6.0.9
8+
url_launcher: ^6.0.17
99
url_launcher_tizen:
1010
path: ../
1111

packages/url_launcher/example/tizen/Runner.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Tizen.NET.Sdk/1.1.5">
1+
<Project Sdk="Tizen.NET.Sdk/1.1.7">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>

packages/url_launcher/example/tizen/tizen-manifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest package="org.tizen.url_launcher_example" version="1.0.0" api-version="4.0" xmlns="http://tizen.org/ns/packages">
33
<profile name="common"/>
4-
<ui-application appid="org.tizen.url_launcher_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4" launch_mode="single">
4+
<ui-application appid="org.tizen.url_launcher_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4">
55
<label>url_launcher_example</label>
66
<icon>ic_launcher.png</icon>
77
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true"/>
8-
<metadata key="http://tizen.org/metadata/direct-launch" value="yes"/>
98
</ui-application>
109
<feature name="http://tizen.org/feature/screen.size.all"/>
1110
<privileges>

packages/url_launcher/lib/src/app_control.dart

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)