Skip to content

Instantly share code, notes, and snippets.

@collinjackson
Last active October 23, 2019 20:27
Show Gist options
  • Save collinjackson/9c3dc7457ca074b986ef97492612b5b6 to your computer and use it in GitHub Desktop.
Save collinjackson/9c3dc7457ca074b986ef97492612b5b6 to your computer and use it in GitHub Desktop.
// 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, visibleForTesting;
import 'method_channel_url_launcher.dart';
class MustExtend<T> {
MustExtend<T> verifyExtends() => this;
}
/// Provides default implementations of interface methods.
///
/// Can be mocked for testing. However, production implementations
/// should extend [UrlLauncherPlatform] instead.
@visibleForTesting
abstract class UrlLauncherPlatformInterface with MustExtend<UrlLauncherPlatformInterface> {
/// 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.');
}
}
/// The interface that implementations of url_launcher must implement.
///
/// Platform implementations should extend this class rather than
/// `UrlLauncherPlatformInterface`.
abstract class UrlLauncherPlatform extends UrlLauncherPlatformInterface {
/// 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 get instance => _instance;
static UrlLauncherPlatform _instance = MethodChannelUrlLauncher();
// TODO(amirh): Extract common platform interface logic.
// https://github.com/flutter/flutter/issues/43368
static set instance(UrlLauncherPlatform instance) {
_instance = instance.verifyExtends<UrlLauncherPlatformInterface>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment