Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.14.0

* Adds `PlatformWebViewController.loadFileWithParams(LoadFileParams)` to support loading local HTML files with platform-specific parameters.

## 2.13.1

* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ abstract class PlatformWebViewController extends PlatformInterface {
'loadFile is not implemented on the current platform');
}

/// Loads a local HTML file using the provided [params].
///
/// The [params.absoluteFilePath] should contain the absolute path to the file
/// on the device.
/// For example: `/Users/username/Documents/www/index.html`.
///
/// Platform-specific implementations may extend [LoadFileParams] to support
/// additional parameters, such as iOS/macOS-specific read access options.
Future<void> loadFileWithParams(
LoadFileParams params,
) {
return loadFile(params.absoluteFilePath);
}

/// Loads the Flutter asset specified in the pubspec.yaml file.
///
/// Throws an ArgumentError if [key] is not part of the specified assets
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2013 The Flutter 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 'package:flutter/material.dart';

/// Object specifying parameters for loading a local HTML file into a web view.
///
/// Platform-specific implementations can add additional fields by extending
/// this class.
///
/// This example demonstrates how to extend [LoadFileParams] to provide
/// additional platform-specific parameters.
///
/// When extending [LoadFileParams], additional parameters should always accept
/// `null` or have a default value to prevent breaking changes.
///
/// ```dart
/// class WebKitLoadFileParams extends LoadFileParams {
/// const WebKitLoadFileParams({
/// required super.absoluteFilePath,
/// required this.readAccessPath,
/// });
///
/// /// The directory to which the WebView is granted read access.
/// final String readAccessPath;
/// }
/// ```
@immutable
base class LoadFileParams {
/// Creates a new [LoadFileParams] object.
const LoadFileParams({
required this.absoluteFilePath,
});

/// The path to the local HTML file to be loaded.
final String absoluteFilePath;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export 'javascript_dialog_request.dart';
export 'javascript_log_level.dart';
export 'javascript_message.dart';
export 'javascript_mode.dart';
export 'load_file_params.dart';
export 'load_request_params.dart';
export 'navigation_decision.dart';
export 'navigation_request.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.13.1
version: 2.14.0

environment:
sdk: ^3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ void main() {
);
});

test('loadFileWithParams redirects to loadFile with correct path', () async {
final LoadFileSpyPlatformWebViewController controller =
LoadFileSpyPlatformWebViewController(
const PlatformWebViewControllerCreationParams(),
);

const String testPath = 'file:///test/index.html';
const LoadFileParams params = LoadFileParams(
absoluteFilePath: testPath,
);

await controller.loadFileWithParams(params);

expect(controller.loadFilePath, equals(testPath));
});

test(
'Default implementation of loadFlutterAsset should throw unimplemented error',
() {
Expand Down Expand Up @@ -528,6 +544,17 @@ class ExtendsPlatformWebViewController extends PlatformWebViewController {
ExtendsPlatformWebViewController(super.params) : super.implementation();
}

class LoadFileSpyPlatformWebViewController extends PlatformWebViewController {
LoadFileSpyPlatformWebViewController(super.params) : super.implementation();

String? loadFilePath;

@override
Future<void> loadFile(String absoluteFilePath) async {
loadFilePath = absoluteFilePath;
}
}

// ignore: must_be_immutable
class MockLoadRequestParamsDelegate extends Mock
with
Expand Down