This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[url_launcher] Migrate url_launcher_web to the platform interface #2237
Merged
harryterkelsen
merged 3 commits into
flutter:master
from
harryterkelsen:url-launcher-web-platform
Oct 29, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # 0.0.2 | ||
|
|
||
| - Switch to using `url_launcher_platform_interface`. | ||
|
|
||
| # 0.0.1 | ||
|
|
||
| - Initial open-source release. |
61 changes: 29 additions & 32 deletions
61
packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart
This file contains hidden or 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 |
|---|---|---|
| @@ -1,49 +1,46 @@ | ||
| import 'dart:async'; | ||
| import 'dart:html' as html; | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||
| import 'package:meta/meta.dart'; | ||
| import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
|
|
||
| class UrlLauncherPlugin { | ||
| /// The web implementation of [UrlLauncherPlatform]. | ||
| /// | ||
| /// This class implements the `package:url_launcher` functionality for the web. | ||
| class UrlLauncherPlugin extends UrlLauncherPlatform { | ||
| /// Registers this class as the default instance of [UrlLauncherPlatform]. | ||
| static void registerWith(Registrar registrar) { | ||
| final MethodChannel channel = MethodChannel( | ||
| 'plugins.flutter.io/url_launcher', | ||
| const StandardMethodCodec(), | ||
| registrar.messenger); | ||
| final UrlLauncherPlugin instance = UrlLauncherPlugin(); | ||
| channel.setMethodCallHandler(instance.handleMethodCall); | ||
| UrlLauncherPlatform.instance = UrlLauncherPlugin(); | ||
| } | ||
|
|
||
| Future<dynamic> handleMethodCall(MethodCall call) async { | ||
| switch (call.method) { | ||
| case 'canLaunch': | ||
| final String url = call.arguments['url']; | ||
| return _canLaunch(url); | ||
| case 'launch': | ||
| final String url = call.arguments['url']; | ||
| return _launch(url); | ||
| default: | ||
| throw PlatformException( | ||
| code: 'Unimplemented', | ||
| details: "The url_launcher plugin for web doesn't implement " | ||
| "the method '${call.method}'"); | ||
| } | ||
| /// Opens the given [url] in a new window. | ||
| /// | ||
| /// Returns the newly created window. | ||
| @visibleForTesting | ||
| html.WindowBase openNewWindow(String url) { | ||
| return html.window.open(url, ''); | ||
| } | ||
|
|
||
| bool _canLaunch(String url) { | ||
| @override | ||
| Future<bool> canLaunch(String url) { | ||
| final Uri parsedUrl = Uri.tryParse(url); | ||
| if (parsedUrl == null) return false; | ||
|
|
||
| return parsedUrl.isScheme('http') || parsedUrl.isScheme('https'); | ||
| } | ||
| if (parsedUrl == null) return Future<bool>.value(false); | ||
|
|
||
| bool _launch(String url) { | ||
| return openNewWindow(url) != null; | ||
| return Future<bool>.value( | ||
| parsedUrl.isScheme('http') || parsedUrl.isScheme('https')); | ||
| } | ||
|
|
||
| @visibleForTesting | ||
| html.WindowBase openNewWindow(String url) { | ||
| return html.window.open(url, ''); | ||
| @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 Future<bool>.value(openNewWindow(url) != null); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.