forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[url_launcher] Add
url_launcher_platform_interface
package (flutter…
…#2217) * [url_launcher] Add overridable platform * Fix analyzer lints * Run dartfmt * Add a url_launcher_platform_interface package * Disable tests temporarily * Add license header * Fix typo in test * Add LICENSE file * Respond to review comments * Respond to review comments
- Loading branch information
Harry Terkelsen
authored
Oct 22, 2019
1 parent
fe9b559
commit f04b3c8
Showing
6 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/url_launcher/url_launcher_platform_interface/LICENSE
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 2017 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. |
26 changes: 26 additions & 0 deletions
26
packages/url_launcher/url_launcher_platform_interface/README.md
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,26 @@ | ||
# url_launcher_platform_interface | ||
|
||
A common platform interface for the [`url_launcher`][1] plugin. | ||
|
||
This interface allows platform-specific implementations of the `url_launcher` | ||
plugin, as well as the plugin itself, to ensure they are supporting the | ||
same interface. | ||
|
||
# Usage | ||
|
||
To implement a new platform-specific implementation of `url_launcher`, extend | ||
[`UrlLauncherPlatform`][2] with an implementation that performs the | ||
platform-specific behavior, and when you register your plugin, set the default | ||
`UrlLauncherPlatform` by calling | ||
`UrlLauncherPlatform.instance = MyPlatformUrlLauncher()`. | ||
|
||
# Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
on why a less-clean interface is preferable to a breaking change. | ||
|
||
[1]: ../url_launcher | ||
[2]: lib/url_launcher_platform_interface.dart |
52 changes: 52 additions & 0 deletions
52
packages/url_launcher/url_launcher_platform_interface/lib/method_channel_url_launcher.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,52 @@ | ||
// 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:meta/meta.dart' show required; | ||
|
||
import 'url_launcher_platform_interface.dart'; | ||
|
||
const MethodChannel _channel = MethodChannel('plugins.flutter.io/url_launcher'); | ||
|
||
/// An implementation of [UrlLauncherPlatform] that uses method channels. | ||
class MethodChannelUrlLauncher extends UrlLauncherPlatform { | ||
@override | ||
Future<bool> canLaunch(String url) { | ||
return _channel.invokeMethod<bool>( | ||
'canLaunch', | ||
<String, Object>{'url': url}, | ||
); | ||
} | ||
|
||
@override | ||
Future<void> closeWebView() { | ||
return _channel.invokeMethod<void>('closeWebView'); | ||
} | ||
|
||
@override | ||
Future<bool> launch( | ||
String url, { | ||
@required bool useSafariVC, | ||
@required bool useWebView, | ||
@required bool enableJavaScript, | ||
@required bool enableDomStorage, | ||
@required bool universalLinksOnly, | ||
@required Map<String, String> headers, | ||
}) { | ||
return _channel.invokeMethod<bool>( | ||
'launch', | ||
<String, Object>{ | ||
'url': url, | ||
'useSafariVC': useSafariVC, | ||
'useWebView': useWebView, | ||
'enableJavaScript': enableJavaScript, | ||
'enableDomStorage': enableDomStorage, | ||
'universalLinksOnly': universalLinksOnly, | ||
'headers': headers, | ||
}, | ||
); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ges/url_launcher/url_launcher_platform_interface/lib/url_launcher_platform_interface.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,54 @@ | ||
// 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:meta/meta.dart' show required; | ||
|
||
import 'method_channel_url_launcher.dart'; | ||
|
||
/// The interface that implementations of url_launcher must implement. | ||
/// | ||
/// Platform implementations that live in a separate package should extend this | ||
/// class rather than implement it as `url_launcher` does not consider newly | ||
/// added methods to be breaking changes. Extending this class (using `extends`) | ||
/// ensures that the subclass will get the default implementation, while | ||
/// platform implementations that `implements` this interface will be broken by | ||
/// newly added [UrlLauncherPlatform] methods. | ||
abstract class UrlLauncherPlatform { | ||
/// The default instance of [UrlLauncherPlatform] to use. | ||
/// | ||
/// Platform-specific plugins should override this with their own | ||
/// platform-specific class that extends [UrlLauncherPlatform] when they | ||
/// register themselves. | ||
/// | ||
/// Defaults to [MethodChannelUrlLauncher]. | ||
static UrlLauncherPlatform instance = MethodChannelUrlLauncher(); | ||
|
||
/// Returns `true` if this platform is able to launch [url]. | ||
Future<bool> canLaunch(String url) { | ||
throw UnimplementedError('canLaunch() has not been implemented.'); | ||
} | ||
|
||
/// Returns `true` if the given [url] was successfully launched. | ||
/// | ||
/// For documentation on the other arguments, see the `launch` documentation | ||
/// in `package:url_launcher/url_launcher.dart`. | ||
Future<bool> launch( | ||
String url, { | ||
@required bool useSafariVC, | ||
@required bool useWebView, | ||
@required bool enableJavaScript, | ||
@required bool enableDomStorage, | ||
@required bool universalLinksOnly, | ||
@required Map<String, String> headers, | ||
}) { | ||
throw UnimplementedError('launch() has not been implemented.'); | ||
} | ||
|
||
/// Closes the WebView, if one was opened earlier by [launch]. | ||
Future<void> closeWebView() { | ||
throw UnimplementedError('closeWebView() has not been implemented.'); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/url_launcher/url_launcher_platform_interface/pubspec.yaml
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,20 @@ | ||
name: url_launcher_platform_interface | ||
description: A common platform interface for the url_launcher plugin. | ||
author: Flutter Team <[email protected]> | ||
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_platform_interface | ||
# NOTE: We strongly prefer non-breaking changes, even at the expense of a | ||
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes | ||
version: 1.0.0 | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
meta: ^1.0.5 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
|
||
environment: | ||
sdk: ">=2.0.0-dev.28.0 <3.0.0" | ||
flutter: ">=1.9.1+hotfix.4 <2.0.0" |
Oops, something went wrong.