Skip to content

Commit c762839

Browse files
authored
[url_launcher] Add url_launcher_tizen package (#6)
1 parent 0b12c25 commit c762839

18 files changed

+685
-0
lines changed

packages/url_launcher/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Initial release.

packages/url_launcher/LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
2+
Copyright (c) 2017 The Chromium Authors. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the names of the copyright holders nor the names of the
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/url_launcher/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# url_launcher_tizen
2+
3+
The Tizen implementation of [`url_launcher`](https://github.com/flutter/plugins/tree/master/packages/url_launcher).
4+
5+
## Usage
6+
7+
This package is not an _endorsed_ implementation of `url_launcher`. Therefore, you have to include `url_launcher_tizen` alongside `url_launcher` as dependencies in your `pubspec.yaml` file.
8+
9+
```yaml
10+
dependencies:
11+
url_launcher: ^5.7.5
12+
url_launcher_tizen: ^1.0.0
13+
```
14+
15+
Then you can import `url_launcher` in your Dart code:
16+
17+
```dart
18+
import 'package:url_launcher/url_launcher.dart';
19+
```
20+
21+
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher#usage.
22+
23+
An `AppControlException` is raised if no application on the device can launch the requested URL.
24+
25+
## Required privileges
26+
27+
To use this plugin in a Tizen application, the application manager privilege is required. Add below lines under the `<manifest>` section in your `tizen-manifest.xml` file.
28+
29+
```xml
30+
<privileges>
31+
<privilege>http://tizen.org/privilege/appmanager.launch</privilege>
32+
</privileges>
33+
```
34+
35+
For details, see [Security and API Privileges](https://docs.tizen.org/application/dotnet/tutorials/sec-privileges).
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# url_launcher_tizen_example
2+
3+
Demonstrates how to use the url_launcher_tizen plugin.
4+
5+
## Getting Started
6+
7+
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2019 the Chromium project 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:io' show Platform;
6+
7+
import 'package:flutter/foundation.dart' show kIsWeb;
8+
import 'package:flutter_test/flutter_test.dart';
9+
import 'package:integration_test/integration_test.dart';
10+
import 'package:url_launcher/url_launcher.dart';
11+
12+
void main() {
13+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
14+
15+
test('canLaunch', () async {
16+
expect(await canLaunch('randomstring'), false);
17+
18+
// Generally all devices should have some default browser.
19+
expect(await canLaunch('http://flutter.dev'), true);
20+
21+
// SMS handling is available by default on most platforms.
22+
if (kIsWeb || !(Platform.isLinux || Platform.isWindows)) {
23+
expect(await canLaunch('sms:5555555555'), true);
24+
}
25+
26+
// tel: and mailto: links may not be openable on every device. iOS
27+
// simulators notably can't open these link types.
28+
});
29+
}
+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// Copyright 2017 The Chromium 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+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:async';
8+
9+
import 'package:flutter/material.dart';
10+
import 'package:url_launcher/url_launcher.dart';
11+
12+
void main() {
13+
runApp(MyApp());
14+
}
15+
16+
class MyApp extends StatelessWidget {
17+
@override
18+
Widget build(BuildContext context) {
19+
return MaterialApp(
20+
title: 'URL Launcher',
21+
theme: ThemeData(
22+
primarySwatch: Colors.blue,
23+
),
24+
home: MyHomePage(title: 'URL Launcher'),
25+
);
26+
}
27+
}
28+
29+
class MyHomePage extends StatefulWidget {
30+
MyHomePage({Key key, this.title}) : super(key: key);
31+
final String title;
32+
33+
@override
34+
_MyHomePageState createState() => _MyHomePageState();
35+
}
36+
37+
class _MyHomePageState extends State<MyHomePage> {
38+
Future<void> _launched;
39+
String _phone = '';
40+
41+
Future<void> _launchInBrowser(String url) async {
42+
if (await canLaunch(url)) {
43+
await launch(
44+
url,
45+
forceSafariVC: false,
46+
forceWebView: false,
47+
headers: <String, String>{'my_header_key': 'my_header_value'},
48+
);
49+
} else {
50+
throw 'Could not launch $url';
51+
}
52+
}
53+
54+
Future<void> _launchInWebViewOrVC(String url) async {
55+
if (await canLaunch(url)) {
56+
await launch(
57+
url,
58+
forceSafariVC: true,
59+
forceWebView: true,
60+
headers: <String, String>{'my_header_key': 'my_header_value'},
61+
);
62+
} else {
63+
throw 'Could not launch $url';
64+
}
65+
}
66+
67+
Future<void> _launchInWebViewWithJavaScript(String url) async {
68+
if (await canLaunch(url)) {
69+
await launch(
70+
url,
71+
forceSafariVC: true,
72+
forceWebView: true,
73+
enableJavaScript: true,
74+
);
75+
} else {
76+
throw 'Could not launch $url';
77+
}
78+
}
79+
80+
Future<void> _launchInWebViewWithDomStorage(String url) async {
81+
if (await canLaunch(url)) {
82+
await launch(
83+
url,
84+
forceSafariVC: true,
85+
forceWebView: true,
86+
enableDomStorage: true,
87+
);
88+
} else {
89+
throw 'Could not launch $url';
90+
}
91+
}
92+
93+
Future<void> _launchUniversalLinkIos(String url) async {
94+
if (await canLaunch(url)) {
95+
final bool nativeAppLaunchSucceeded = await launch(
96+
url,
97+
forceSafariVC: false,
98+
universalLinksOnly: true,
99+
);
100+
if (!nativeAppLaunchSucceeded) {
101+
await launch(
102+
url,
103+
forceSafariVC: true,
104+
);
105+
}
106+
}
107+
}
108+
109+
Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) {
110+
if (snapshot.hasError) {
111+
return Text('Error: ${snapshot.error}');
112+
} else {
113+
return const Text('');
114+
}
115+
}
116+
117+
Future<void> _makePhoneCall(String url) async {
118+
if (await canLaunch(url)) {
119+
await launch(url);
120+
} else {
121+
throw 'Could not launch $url';
122+
}
123+
}
124+
125+
@override
126+
Widget build(BuildContext context) {
127+
const String toLaunch = 'https://www.cylog.org/headers/';
128+
return Scaffold(
129+
appBar: AppBar(
130+
title: Text(widget.title),
131+
),
132+
body: ListView(
133+
children: <Widget>[
134+
Column(
135+
mainAxisAlignment: MainAxisAlignment.center,
136+
children: <Widget>[
137+
Padding(
138+
padding: const EdgeInsets.all(16.0),
139+
child: TextField(
140+
onChanged: (String text) => _phone = text,
141+
decoration: const InputDecoration(
142+
hintText: 'Input the phone number to launch')),
143+
),
144+
RaisedButton(
145+
onPressed: () => setState(() {
146+
_launched = _makePhoneCall('tel:$_phone');
147+
}),
148+
child: const Text('Make phone call'),
149+
),
150+
const Padding(
151+
padding: EdgeInsets.all(16.0),
152+
child: Text(toLaunch),
153+
),
154+
RaisedButton(
155+
onPressed: () => setState(() {
156+
_launched = _launchInBrowser(toLaunch);
157+
}),
158+
child: const Text('Launch in browser'),
159+
),
160+
const Padding(padding: EdgeInsets.all(16.0)),
161+
RaisedButton(
162+
onPressed: () => setState(() {
163+
_launched = _launchInWebViewOrVC(toLaunch);
164+
}),
165+
child: const Text('Launch in app'),
166+
),
167+
RaisedButton(
168+
onPressed: () => setState(() {
169+
_launched = _launchInWebViewWithJavaScript(toLaunch);
170+
}),
171+
child: const Text('Launch in app(JavaScript ON)'),
172+
),
173+
RaisedButton(
174+
onPressed: () => setState(() {
175+
_launched = _launchInWebViewWithDomStorage(toLaunch);
176+
}),
177+
child: const Text('Launch in app(DOM storage ON)'),
178+
),
179+
const Padding(padding: EdgeInsets.all(16.0)),
180+
RaisedButton(
181+
onPressed: () => setState(() {
182+
_launched = _launchUniversalLinkIos(toLaunch);
183+
}),
184+
child: const Text(
185+
'Launch a universal link in a native app, fallback to Safari.(Youtube)'),
186+
),
187+
const Padding(padding: EdgeInsets.all(16.0)),
188+
RaisedButton(
189+
onPressed: () => setState(() {
190+
_launched = _launchInWebViewOrVC(toLaunch);
191+
Timer(const Duration(seconds: 5), () {
192+
print('Closing WebView after 5 seconds...');
193+
closeWebView();
194+
});
195+
}),
196+
child: const Text('Launch in app + close after 5 seconds'),
197+
),
198+
const Padding(padding: EdgeInsets.all(16.0)),
199+
FutureBuilder<void>(future: _launched, builder: _launchStatus),
200+
],
201+
),
202+
],
203+
),
204+
);
205+
}
206+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: url_launcher_example
2+
description: Demonstrates how to use the url_launcher_tizen plugin.
3+
4+
dependencies:
5+
flutter:
6+
sdk: flutter
7+
url_launcher: ^5.7.5
8+
url_launcher_tizen:
9+
path: ../
10+
11+
dev_dependencies:
12+
integration_test: ^0.9.2
13+
integration_test_tizen:
14+
path: ../../integration_test/
15+
flutter_driver:
16+
sdk: flutter
17+
pedantic: ^1.8.0
18+
plugin_platform_interface: ^1.0.0
19+
20+
flutter:
21+
uses-material-design: true
22+
23+
environment:
24+
sdk: ">=2.1.0 <3.0.0"
25+
flutter: ">=1.12.13+hotfix.5 <2.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import 'package:integration_test/integration_test_driver.dart';
2+
3+
Future<void> main() => integrationDriver();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
flutter/
2+
.vs/
3+
*.user
4+
bin/
5+
obj/

0 commit comments

Comments
 (0)