From 2a40d20cb8c92dde17ade378a07436fe91944ebc Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 21 Apr 2025 19:27:20 -0400 Subject: [PATCH] interface impl --- .../CHANGELOG.md | 7 ++++ .../lib/src/platform_webview_controller.dart | 20 +++++++++++ .../pubspec.yaml | 2 +- .../platform_webview_controller_test.dart | 35 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md index 6f452d22a1bb..1607f5de6ff6 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.12.0 + +* Adds support to set whether to draw the scrollbar. See + `PlatformWebViewController.setVerticalScrollBarEnabled`, + `PlatformWebViewController.setHorizontalScrollBarEnabled`, + `PlatformWebViewController.supportsSetScrollBarsEnabled`. + ## 2.11.0 * Adds support to set the over-scroll mode for the WebView. See `PlatformWebViewController.setOverScrollMode`. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart index 34b68a02dfc8..97645c93cd37 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart @@ -229,6 +229,26 @@ abstract class PlatformWebViewController extends PlatformInterface { 'scrollBy is not implemented on the current platform'); } + /// Whether the vertical scrollbar should be drawn or not. + Future setVerticalScrollBarEnabled(bool enabled) { + throw UnimplementedError( + 'setVerticalScrollBarEnabled is not implemented on the current platform'); + } + + /// Whether the horizontal scrollbar should be drawn or not. + Future setHorizontalScrollBarEnabled(bool enabled) { + throw UnimplementedError( + 'setHorizontalScrollBarEnabled is not implemented on the current platform'); + } + + /// Returns true if the current platform supports setting whether scrollbars + /// should be drawn or not. + /// + /// See [setVerticalScrollBarEnabled] and [setHorizontalScrollBarEnabled]. + bool supportsSetScrollBarsEnabled() { + return false; + } + /// Return the current scroll position of this view. /// /// Scroll position is measured from the top left. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml index cdac767ba8ea..13a8d0dc5561 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml @@ -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.11.0 +version: 2.12.0 environment: sdk: ^3.4.0 diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart index 7ef8343b0d44..a0ac50026194 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart @@ -311,6 +311,41 @@ void main() { ); }); + test( + 'Default implementation of setVerticalScrollBarEnabled should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.setVerticalScrollBarEnabled(false), + throwsUnimplementedError, + ); + }); + + test( + 'Default implementation of setHorizontalScrollBarEnabled should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.setHorizontalScrollBarEnabled(false), + throwsUnimplementedError, + ); + }); + + test('Default implementation of supportsSetScrollBarsEnabled returns false', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect(controller.supportsSetScrollBarsEnabled(), isFalse); + }); + test( 'Default implementation of getScrollPosition should throw unimplemented error', () {