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+
15## 2.13.1
26
37* 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 {
6161 'loadFile is not implemented on the current platform' );
6262 }
6363
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+
6478 /// Loads the Flutter asset specified in the pubspec.yaml file.
6579 ///
6680 /// 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';
99export 'javascript_log_level.dart' ;
1010export 'javascript_message.dart' ;
1111export 'javascript_mode.dart' ;
12+ export 'load_file_params.dart' ;
1213export 'load_request_params.dart' ;
1314export 'navigation_decision.dart' ;
1415export '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
44issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
55# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7- version : 2.13.1
7+ version : 2.14.0
88
99environment :
1010 sdk : ^3.6.0
Original file line number Diff line number Diff line change @@ -69,6 +69,22 @@ void main() {
6969 );
7070 });
7171
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+
7288 test (
7389 'Default implementation of loadFlutterAsset should throw unimplemented error' ,
7490 () {
@@ -528,6 +544,17 @@ class ExtendsPlatformWebViewController extends PlatformWebViewController {
528544 ExtendsPlatformWebViewController (super .params) : super .implementation ();
529545}
530546
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+
531558// ignore: must_be_immutable
532559class MockLoadRequestParamsDelegate extends Mock
533560 with
You can’t perform that action at this time.
0 commit comments