File tree Expand file tree Collapse file tree 6 files changed +85
-1
lines changed
packages/webview_flutter/webview_flutter_platform_interface Expand file tree Collapse file tree 6 files changed +85
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## 2.14.0
2
+
3
+ * Adds ` PlatformWebViewController.loadFileWithParams(LoadFileParams) ` to support loading local HTML files with platform-specific parameters.
4
+
1
5
## 2.13.1
2
6
3
7
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
Original file line number Diff line number Diff line change @@ -61,6 +61,20 @@ abstract class PlatformWebViewController extends PlatformInterface {
61
61
'loadFile is not implemented on the current platform' );
62
62
}
63
63
64
+ /// Loads a local HTML file using the provided [params] .
65
+ ///
66
+ /// The [params.absoluteFilePath] should contain the absolute path to the file
67
+ /// on the device.
68
+ /// For example: `/Users/username/Documents/www/index.html` .
69
+ ///
70
+ /// Platform-specific implementations may extend [LoadFileParams] to support
71
+ /// additional parameters, such as iOS/macOS-specific read access options.
72
+ Future <void > loadFileWithParams (
73
+ LoadFileParams params,
74
+ ) {
75
+ return loadFile (params.absoluteFilePath);
76
+ }
77
+
64
78
/// Loads the Flutter asset specified in the pubspec.yaml file.
65
79
///
66
80
/// Throws an ArgumentError if [key] is not part of the specified assets
Original file line number Diff line number Diff line change
1
+ // Copyright 2013 The Flutter Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import 'package:flutter/material.dart' ;
6
+
7
+ /// Object specifying parameters for loading a local HTML file into a web view.
8
+ ///
9
+ /// Platform-specific implementations can add additional fields by extending
10
+ /// this class.
11
+ ///
12
+ /// This example demonstrates how to extend [LoadFileParams] to provide
13
+ /// additional platform-specific parameters.
14
+ ///
15
+ /// When extending [LoadFileParams] , additional parameters should always accept
16
+ /// `null` or have a default value to prevent breaking changes.
17
+ ///
18
+ /// ```dart
19
+ /// class WebKitLoadFileParams extends LoadFileParams {
20
+ /// const WebKitLoadFileParams({
21
+ /// required super.absoluteFilePath,
22
+ /// required this.readAccessPath,
23
+ /// });
24
+ ///
25
+ /// /// The directory to which the WebView is granted read access.
26
+ /// final String readAccessPath;
27
+ /// }
28
+ /// ```
29
+ @immutable
30
+ base class LoadFileParams {
31
+ /// Creates a new [LoadFileParams] object.
32
+ const LoadFileParams ({
33
+ required this .absoluteFilePath,
34
+ });
35
+
36
+ /// The path to the local HTML file to be loaded.
37
+ final String absoluteFilePath;
38
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export 'javascript_dialog_request.dart';
9
9
export 'javascript_log_level.dart' ;
10
10
export 'javascript_message.dart' ;
11
11
export 'javascript_mode.dart' ;
12
+ export 'load_file_params.dart' ;
12
13
export 'load_request_params.dart' ;
13
14
export 'navigation_decision.dart' ;
14
15
export 'navigation_request.dart' ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
4
4
issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
5
5
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
6
6
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7
- version : 2.13.1
7
+ version : 2.14.0
8
8
9
9
environment :
10
10
sdk : ^3.6.0
Original file line number Diff line number Diff line change @@ -69,6 +69,22 @@ void main() {
69
69
);
70
70
});
71
71
72
+ test ('loadFileWithParams redirects to loadFile with correct path' , () async {
73
+ final LoadFileSpyPlatformWebViewController controller =
74
+ LoadFileSpyPlatformWebViewController (
75
+ const PlatformWebViewControllerCreationParams (),
76
+ );
77
+
78
+ const String testPath = 'file:///test/index.html' ;
79
+ const LoadFileParams params = LoadFileParams (
80
+ absoluteFilePath: testPath,
81
+ );
82
+
83
+ await controller.loadFileWithParams (params);
84
+
85
+ expect (controller.loadFilePath, equals (testPath));
86
+ });
87
+
72
88
test (
73
89
'Default implementation of loadFlutterAsset should throw unimplemented error' ,
74
90
() {
@@ -528,6 +544,17 @@ class ExtendsPlatformWebViewController extends PlatformWebViewController {
528
544
ExtendsPlatformWebViewController (super .params) : super .implementation ();
529
545
}
530
546
547
+ class LoadFileSpyPlatformWebViewController extends PlatformWebViewController {
548
+ LoadFileSpyPlatformWebViewController (super .params) : super .implementation ();
549
+
550
+ String ? loadFilePath;
551
+
552
+ @override
553
+ Future <void > loadFile (String absoluteFilePath) async {
554
+ loadFilePath = absoluteFilePath;
555
+ }
556
+ }
557
+
531
558
// ignore: must_be_immutable
532
559
class MockLoadRequestParamsDelegate extends Mock
533
560
with
You can’t perform that action at this time.
0 commit comments