forked from flutter/plugins
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[url_launcher_linux] Add Linux url_launcher plugin (flutter#2857)
Adds url_launcher_linux, the federated implementation of url_launcher. Not yet endorsed by url_launcher Part of flutter/flutter#41721
- Loading branch information
1 parent
ac80d80
commit 0f4a0b3
Showing
29 changed files
with
953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.packages | ||
.flutter-plugins | ||
pubspec.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 4b12050112afd581ddf53df848275fa681f908f3 | ||
channel: master | ||
|
||
project_type: plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 0.0.1 | ||
* The initial implementation of url_launcher for Linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# url_launcher_linux | ||
|
||
The Linux implementation of [`url_launcher`][1]. | ||
|
||
## Usage | ||
|
||
### Import the package | ||
|
||
This package is an unendorsed Linux implementation of `url_launcher`. | ||
|
||
In order to use this now, you'll need to depend on `url_launcher_linux`. | ||
When this package is endorsed it will be automatically used by the `url_launcher` package and you can switch to that API. | ||
|
||
```yaml | ||
... | ||
dependencies: | ||
... | ||
url_launcher_linux: ^0.0.1 | ||
... | ||
``` | ||
|
||
[1]: ../ |
44 changes: 44 additions & 0 deletions
44
packages/url_launcher/url_launcher_linux/example/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Exceptions to above rules. | ||
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages |
10 changes: 10 additions & 0 deletions
10
packages/url_launcher/url_launcher_linux/example/.metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 4b12050112afd581ddf53df848275fa681f908f3 | ||
channel: master | ||
|
||
project_type: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# url_launcher_example | ||
|
||
Demonstrates how to use the url_launcher plugin. | ||
|
||
## Getting Started | ||
|
||
For help getting started with Flutter, view our online | ||
[documentation](http://flutter.io/). |
194 changes: 194 additions & 0 deletions
194
packages/url_launcher/url_launcher_linux/example/lib/main.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// ignore_for_file: public_member_api_docs | ||
|
||
import 'dart:async'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'URL Launcher', | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
home: MyHomePage(title: 'URL Launcher'), | ||
); | ||
} | ||
} | ||
|
||
class MyHomePage extends StatefulWidget { | ||
MyHomePage({Key key, this.title}) : super(key: key); | ||
final String title; | ||
|
||
@override | ||
_MyHomePageState createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
Future<void> _launched; | ||
String _phone = ''; | ||
|
||
Future<void> _launchInBrowser(String url) async { | ||
if (await canLaunch(url)) { | ||
await launch( | ||
url, | ||
forceSafariVC: false, | ||
forceWebView: false, | ||
headers: <String, String>{'my_header_key': 'my_header_value'}, | ||
); | ||
} else { | ||
throw 'Could not launch $url'; | ||
} | ||
} | ||
|
||
Future<void> _launchInWebViewOrVC(String url) async { | ||
if (await canLaunch(url)) { | ||
await launch( | ||
url, | ||
forceSafariVC: true, | ||
forceWebView: true, | ||
headers: <String, String>{'my_header_key': 'my_header_value'}, | ||
); | ||
} else { | ||
throw 'Could not launch $url'; | ||
} | ||
} | ||
|
||
Future<void> _launchInWebViewWithJavaScript(String url) async { | ||
if (await canLaunch(url)) { | ||
await launch( | ||
url, | ||
forceSafariVC: true, | ||
forceWebView: true, | ||
enableJavaScript: true, | ||
); | ||
} else { | ||
throw 'Could not launch $url'; | ||
} | ||
} | ||
|
||
Future<void> _launchInWebViewWithDomStorage(String url) async { | ||
if (await canLaunch(url)) { | ||
await launch( | ||
url, | ||
forceSafariVC: true, | ||
forceWebView: true, | ||
enableDomStorage: true, | ||
); | ||
} else { | ||
throw 'Could not launch $url'; | ||
} | ||
} | ||
|
||
Future<void> _launchUniversalLinkIos(String url) async { | ||
if (await canLaunch(url)) { | ||
final bool nativeAppLaunchSucceeded = await launch( | ||
url, | ||
forceSafariVC: false, | ||
universalLinksOnly: true, | ||
); | ||
if (!nativeAppLaunchSucceeded) { | ||
await launch( | ||
url, | ||
forceSafariVC: true, | ||
); | ||
} | ||
} | ||
} | ||
|
||
Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) { | ||
if (snapshot.hasError) { | ||
return Text('Error: ${snapshot.error}'); | ||
} else { | ||
return const Text(''); | ||
} | ||
} | ||
|
||
Future<void> _makePhoneCall(String url) async { | ||
if (await canLaunch(url)) { | ||
await launch(url); | ||
} else { | ||
throw 'Could not launch $url'; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
const String toLaunch = 'https://www.cylog.org/headers/'; | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.title), | ||
), | ||
body: ListView( | ||
children: <Widget>[ | ||
Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: TextField( | ||
onChanged: (String text) => _phone = text, | ||
decoration: const InputDecoration( | ||
hintText: 'Input the phone number to launch')), | ||
), | ||
RaisedButton( | ||
onPressed: () => setState(() { | ||
_launched = _makePhoneCall('tel:$_phone'); | ||
}), | ||
child: const Text('Make phone call'), | ||
), | ||
const Padding( | ||
padding: EdgeInsets.all(16.0), | ||
child: Text(toLaunch), | ||
), | ||
RaisedButton( | ||
onPressed: () => setState(() { | ||
_launched = _launchInBrowser(toLaunch); | ||
}), | ||
child: const Text('Launch in browser'), | ||
), | ||
const Padding(padding: EdgeInsets.all(16.0)), | ||
RaisedButton( | ||
onPressed: () => setState(() { | ||
_launched = _launchInWebViewOrVC(toLaunch); | ||
}), | ||
child: const Text('Launch in app'), | ||
), | ||
RaisedButton( | ||
onPressed: () => setState(() { | ||
_launched = _launchInWebViewWithJavaScript(toLaunch); | ||
}), | ||
child: const Text('Launch in app(JavaScript ON)'), | ||
), | ||
RaisedButton( | ||
onPressed: () => setState(() { | ||
_launched = _launchInWebViewWithDomStorage(toLaunch); | ||
}), | ||
child: const Text('Launch in app(DOM storage ON)'), | ||
), | ||
const Padding(padding: EdgeInsets.all(16.0)), | ||
RaisedButton( | ||
onPressed: () => setState(() { | ||
_launched = _launchUniversalLinkIos(toLaunch); | ||
}), | ||
child: const Text( | ||
'Launch a universal link in a native app, fallback to Safari.(Youtube)'), | ||
), | ||
const Padding(padding: EdgeInsets.all(16.0)), | ||
FutureBuilder<void>(future: _launched, builder: _launchStatus), | ||
], | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/url_launcher/url_launcher_linux/example/linux/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flutter/ephemeral |
Oops, something went wrong.