Added CustomPathHandler class to be able to implement Android custom path handlers for WebViewAssetLoader
This commit is contained in:
parent
c3c0a45929
commit
ed450ad678
|
@ -1,3 +1,8 @@
|
|||
## 6.0.0-rc.2
|
||||
|
||||
- Updated minimum platform interface and implementation versions
|
||||
- Added `CustomPathHandler` class to be able to implement Android custom path handlers for `WebViewAssetLoader`
|
||||
|
||||
## 6.0.0-rc.1
|
||||
|
||||
- Updated minimum platform interface and implementation versions
|
||||
|
|
|
@ -14,8 +14,7 @@ import 'package:pointer_interceptor/pointer_interceptor.dart';
|
|||
// import 'package:path_provider/path_provider.dart';
|
||||
// import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
InAppLocalhostServer localhostServer =
|
||||
InAppLocalhostServer(documentRoot: 'assets');
|
||||
final localhostServer = InAppLocalhostServer(documentRoot: 'assets');
|
||||
|
||||
Future main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
|
|
@ -27,6 +27,7 @@ dependencies:
|
|||
permission_handler: 10.2.0
|
||||
url_launcher: 6.1.11
|
||||
pointer_interceptor: ^0.9.3+4
|
||||
# mime: ^1.0.4
|
||||
# connectivity: ^0.4.5+6
|
||||
flutter_inappwebview:
|
||||
path: ../
|
||||
|
|
|
@ -106,3 +106,27 @@ class InternalStoragePathHandler extends PathHandler {
|
|||
|
||||
String get directory => platform.directory;
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformCustomPathHandler}
|
||||
abstract class CustomPathHandler extends PathHandler {
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformCustomPathHandler}
|
||||
CustomPathHandler({required String path})
|
||||
: this.fromPlatformCreationParams(
|
||||
params: PlatformCustomPathHandlerCreationParams(
|
||||
PlatformPathHandlerCreationParams(path: path)));
|
||||
|
||||
/// Constructs a [CustomPathHandler].
|
||||
///
|
||||
/// See [CustomPathHandler.fromPlatformCreationParams] for setting parameters for
|
||||
/// a specific platform.
|
||||
CustomPathHandler.fromPlatformCreationParams({
|
||||
required PlatformCustomPathHandlerCreationParams params,
|
||||
}) : this.fromPlatform(platform: PlatformCustomPathHandler(params));
|
||||
|
||||
/// Constructs a [CustomPathHandler] from a specific platform implementation.
|
||||
CustomPathHandler.fromPlatform({required this.platform})
|
||||
: super.fromPlatform(platform: platform);
|
||||
|
||||
/// Implementation of [PlatformCustomPathHandler] for the current platform.
|
||||
final PlatformCustomPathHandler platform;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview
|
||||
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
|
||||
version: 6.0.0-rc.1
|
||||
version: 6.0.0-rc.2
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
@ -18,11 +18,11 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_inappwebview_platform_interface: ^1.0.7
|
||||
flutter_inappwebview_android: ^1.0.9
|
||||
flutter_inappwebview_ios: ^1.0.10
|
||||
flutter_inappwebview_macos: ^1.0.8
|
||||
flutter_inappwebview_web: ^1.0.5
|
||||
flutter_inappwebview_platform_interface: ^1.0.8
|
||||
flutter_inappwebview_android: ^1.0.10
|
||||
flutter_inappwebview_ios: ^1.0.11
|
||||
flutter_inappwebview_macos: ^1.0.9
|
||||
flutter_inappwebview_web: ^1.0.6
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
## 1.0.10
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.8`
|
||||
- Implemented `PlatformCustomPathHandler` class
|
||||
|
||||
## 1.0.9
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
|
||||
|
|
|
@ -93,10 +93,9 @@ packages:
|
|||
flutter_inappwebview_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_platform_interface
|
||||
sha256: b4db31621880c4f4a60c9ddfc01d2b9f0133bf7776ddbd3a1d34062c076afec7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "../../flutter_inappwebview_platform_interface"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.7"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
|
|
|
@ -313,6 +313,17 @@ class AndroidInAppWebViewPlatform extends InAppWebViewPlatform {
|
|||
return AndroidInternalStoragePathHandler(params);
|
||||
}
|
||||
|
||||
/// Creates a new [AndroidCustomPathHandler].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [CustomPathHandler] in `flutter_inappwebview` instead.
|
||||
@override
|
||||
AndroidCustomPathHandler createPlatformCustomPathHandler(
|
||||
PlatformCustomPathHandlerCreationParams params,
|
||||
) {
|
||||
return AndroidCustomPathHandler(params);
|
||||
}
|
||||
|
||||
/// Creates a new [wv.AndroidWebViewFeature].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
|
|
|
@ -198,3 +198,40 @@ class AndroidInternalStoragePathHandler
|
|||
return {...toMap(), 'directory': directory};
|
||||
}
|
||||
}
|
||||
|
||||
/// Object specifying creation parameters for creating a [AndroidCustomPathHandler].
|
||||
///
|
||||
/// When adding additional fields make sure they can be null or have a default
|
||||
/// value to avoid breaking changes. See [PlatformCustomPathHandlerCreationParams] for
|
||||
/// more information.
|
||||
@immutable
|
||||
class AndroidCustomPathHandlerCreationParams
|
||||
extends PlatformCustomPathHandlerCreationParams {
|
||||
/// Creates a new [AndroidCustomPathHandlerCreationParams] instance.
|
||||
AndroidCustomPathHandlerCreationParams(
|
||||
// This parameter prevents breaking changes later.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformCustomPathHandlerCreationParams params,
|
||||
) : super(params);
|
||||
|
||||
/// Creates a [AndroidCustomPathHandlerCreationParams] instance based on [PlatformCustomPathHandlerCreationParams].
|
||||
factory AndroidCustomPathHandlerCreationParams.fromPlatformCustomPathHandlerCreationParams(
|
||||
PlatformCustomPathHandlerCreationParams params) {
|
||||
return AndroidCustomPathHandlerCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformCustomPathHandler}
|
||||
class AndroidCustomPathHandler extends PlatformCustomPathHandler
|
||||
with AndroidPathHandler, ChannelController {
|
||||
/// Constructs a [AndroidCustomPathHandler].
|
||||
AndroidCustomPathHandler(PlatformCustomPathHandlerCreationParams params)
|
||||
: super.implementation(
|
||||
params is AndroidCustomPathHandlerCreationParams
|
||||
? params
|
||||
: AndroidCustomPathHandlerCreationParams
|
||||
.fromPlatformCustomPathHandlerCreationParams(params),
|
||||
) {
|
||||
_init(params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview_android
|
||||
description: Android implementation of the flutter_inappwebview plugin.
|
||||
version: 1.0.9
|
||||
version: 1.0.10
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
@ -18,7 +18,7 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_inappwebview_platform_interface: ^1.0.7
|
||||
flutter_inappwebview_platform_interface: ^1.0.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
## 1.0.11
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.8`
|
||||
|
||||
## 1.0.10
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview_ios
|
||||
description: iOS implementation of the flutter_inappwebview plugin.
|
||||
version: 1.0.10
|
||||
version: 1.0.11
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_ios
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
@ -18,7 +18,7 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_inappwebview_platform_interface: ^1.0.7
|
||||
flutter_inappwebview_platform_interface: ^1.0.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
## 1.0.9
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.8`
|
||||
|
||||
## 1.0.8
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview_macos
|
||||
description: macOS implementation of the flutter_inappwebview plugin.
|
||||
version: 1.0.8
|
||||
version: 1.0.9
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_macos
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
@ -18,7 +18,7 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_inappwebview_platform_interface: ^1.0.7
|
||||
flutter_inappwebview_platform_interface: ^1.0.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
## 1.0.8
|
||||
|
||||
- Added `PlatformCustomPathHandler` class to be able to implement custom path handlers for `WebViewAssetLoader`
|
||||
|
||||
## 1.0.7
|
||||
|
||||
- Added `InAppBrowser.onMainWindowWillClose` event
|
||||
|
|
|
@ -371,6 +371,17 @@ abstract class InAppWebViewPlatform extends PlatformInterface {
|
|||
'createPlatformInternalStoragePathHandler is not implemented on the current platform.');
|
||||
}
|
||||
|
||||
/// Creates a new [PlatformCustomPathHandler].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
/// Look at using [CustomPathHandler] in `flutter_inappwebview` instead.
|
||||
PlatformCustomPathHandler createPlatformCustomPathHandler(
|
||||
PlatformCustomPathHandlerCreationParams params,
|
||||
) {
|
||||
throw UnimplementedError(
|
||||
'createPlatformCustomPathHandler is not implemented on the current platform.');
|
||||
}
|
||||
|
||||
/// Creates a new [PlatformWebViewFeature].
|
||||
///
|
||||
/// This function should only be called by the app-facing package.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
|
||||
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'inappwebview_platform.dart';
|
||||
|
@ -122,7 +123,7 @@ class PlatformAssetsPathHandlerCreationParams
|
|||
PlatformPathHandlerCreationParams params,
|
||||
) : super(path: params.path);
|
||||
|
||||
/// Creates a [AndroidCookieManagerCreationParams] instance based on [PlatformCookieManagerCreationParams].
|
||||
/// Creates a [PlatformAssetsPathHandlerCreationParams] instance based on [PlatformPathHandlerCreationParams].
|
||||
factory PlatformAssetsPathHandlerCreationParams.fromPlatformPathHandlerCreationParams(
|
||||
PlatformPathHandlerCreationParams params) {
|
||||
return PlatformAssetsPathHandlerCreationParams(params);
|
||||
|
@ -195,7 +196,7 @@ class PlatformResourcesPathHandlerCreationParams
|
|||
PlatformPathHandlerCreationParams params,
|
||||
) : super(path: params.path);
|
||||
|
||||
/// Creates a [AndroidCookieManagerCreationParams] instance based on [PlatformCookieManagerCreationParams].
|
||||
/// Creates a [PlatformResourcesPathHandlerCreationParams] instance based on [PlatformPathHandlerCreationParams].
|
||||
factory PlatformResourcesPathHandlerCreationParams.fromPlatformPathHandlerCreationParams(
|
||||
PlatformPathHandlerCreationParams params) {
|
||||
return PlatformResourcesPathHandlerCreationParams(params);
|
||||
|
@ -271,7 +272,7 @@ class PlatformInternalStoragePathHandlerCreationParams
|
|||
{required this.directory})
|
||||
: super(path: params.path);
|
||||
|
||||
/// Creates a [AndroidCookieManagerCreationParams] instance based on [PlatformCookieManagerCreationParams].
|
||||
/// Creates a [PlatformInternalStoragePathHandlerCreationParams] instance based on [PlatformPathHandlerCreationParams].
|
||||
factory PlatformInternalStoragePathHandlerCreationParams.fromPlatformPathHandlerCreationParams(
|
||||
PlatformPathHandlerCreationParams params,
|
||||
{required String directory}) {
|
||||
|
@ -342,3 +343,74 @@ abstract class PlatformInternalStoragePathHandler extends PlatformInterface
|
|||
|
||||
String get directory => params.directory;
|
||||
}
|
||||
|
||||
/// Object specifying creation parameters for creating a [PlatformCustomPathHandler].
|
||||
///
|
||||
/// Platform specific implementations can add additional fields by extending
|
||||
/// this class.
|
||||
@immutable
|
||||
class PlatformCustomPathHandlerCreationParams
|
||||
extends PlatformPathHandlerCreationParams {
|
||||
/// Used by the platform implementation to create a new [PlatformCustomPathHandler].
|
||||
PlatformCustomPathHandlerCreationParams(
|
||||
// This parameter prevents breaking changes later.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
PlatformPathHandlerCreationParams params,
|
||||
) : super(path: params.path);
|
||||
|
||||
/// Creates a [PlatformCustomPathHandlerCreationParams] instance based on [PlatformPathHandlerCreationParams].
|
||||
factory PlatformCustomPathHandlerCreationParams.fromPlatformPathHandlerCreationParams(
|
||||
PlatformPathHandlerCreationParams params) {
|
||||
return PlatformCustomPathHandlerCreationParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
///{@template flutter_inappwebview_platform_interface.PlatformCustomPathHandler}
|
||||
///Custom handler class used to implement a custom logic to open a file.
|
||||
///
|
||||
///The matched prefix path used shouldn't be a prefix of a real web path.
|
||||
///Thus, if the requested file cannot be found a [WebResourceResponse] object with a `null` data will be returned instead of `null`.
|
||||
///This saves the time of falling back to network and trying to resolve a path that doesn't exist.
|
||||
///A [WebResourceResponse] with `null` data will be received as an HTTP response with status code `404` and no body.
|
||||
///
|
||||
///The MIME type for the file will be determined from the file's extension using
|
||||
///[guessContentTypeFromName](https://developer.android.com/reference/java/net/URLConnection.html#guessContentTypeFromName-java.lang.String-).
|
||||
///Developers should ensure that asset files are named using standard file extensions.
|
||||
///If the file does not have a recognised extension, `text/plain` will be used by default.
|
||||
///{@endtemplate}
|
||||
abstract class PlatformCustomPathHandler extends PlatformInterface
|
||||
implements PlatformPathHandler {
|
||||
/// Creates a new [PlatformCustomPathHandler]
|
||||
factory PlatformCustomPathHandler(
|
||||
PlatformCustomPathHandlerCreationParams params) {
|
||||
assert(
|
||||
InAppWebViewPlatform.instance != null,
|
||||
'A platform implementation for `flutter_inappwebview` has not been set. Please '
|
||||
'ensure that an implementation of `InAppWebViewPlatform` has been set to '
|
||||
'`InAppWebViewPlatform.instance` before use. For unit testing, '
|
||||
'`InAppWebViewPlatform.instance` can be set with your own test implementation.',
|
||||
);
|
||||
final PlatformCustomPathHandler customPathHandler =
|
||||
InAppWebViewPlatform.instance!.createPlatformCustomPathHandler(params);
|
||||
PlatformInterface.verify(customPathHandler, _token);
|
||||
return customPathHandler;
|
||||
}
|
||||
|
||||
/// Used by the platform implementation to create a new [PlatformCustomPathHandler].
|
||||
///
|
||||
/// Should only be used by platform implementations because they can't extend
|
||||
/// a class that only contains a factory constructor.
|
||||
@protected
|
||||
PlatformCustomPathHandler.implementation(this.params) : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
/// The parameters used to initialize the [PlatformCustomPathHandler].
|
||||
final PlatformCustomPathHandlerCreationParams params;
|
||||
|
||||
@override
|
||||
String get type => 'CustomPathHandler';
|
||||
|
||||
@override
|
||||
String get path => params.path;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview_platform_interface
|
||||
description: A common platform interface for the flutter_inappwebview plugin.
|
||||
version: 1.0.7
|
||||
version: 1.0.8
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_platform_interface
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
## 1.0.6
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.8`
|
||||
|
||||
## 1.0.5
|
||||
|
||||
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview_web
|
||||
description: Web implementation of the flutter_inappwebview plugin.
|
||||
version: 1.0.5
|
||||
version: 1.0.6
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_web
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
@ -21,7 +21,7 @@ dependencies:
|
|||
flutter_web_plugins:
|
||||
sdk: flutter
|
||||
js: ^0.6.4
|
||||
flutter_inappwebview_platform_interface: ^1.0.7
|
||||
flutter_inappwebview_platform_interface: ^1.0.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue