diff --git a/packages/webview_flutter/webview_flutter/CHANGELOG.md b/packages/webview_flutter/webview_flutter/CHANGELOG.md index 333296aa501..0c2d9201dfc 100644 --- a/packages/webview_flutter/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter/CHANGELOG.md @@ -1,6 +1,10 @@ -## NEXT +## 4.12.0 -* Updates README to indicate that Andoid SDK <21 is no longer supported. +* Adds support to set whether to draw the scrollbar. See + `WebViewController.setVerticalScrollBarEnabled`, + `WebViewController.setHorizontalScrollBarEnabled`, + `WebViewController.supportsSetScrollBarsEnabled`. +* Updates README to indicate that Android SDK <21 is no longer supported. ## 4.11.0 diff --git a/packages/webview_flutter/webview_flutter/example/pubspec.yaml b/packages/webview_flutter/webview_flutter/example/pubspec.yaml index 5c0fb7ecf99..6b157228134 100644 --- a/packages/webview_flutter/webview_flutter/example/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter/example/pubspec.yaml @@ -17,8 +17,8 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../ - webview_flutter_android: ^4.4.0 - webview_flutter_wkwebview: ^3.19.0 + webview_flutter_android: ^4.5.0 + webview_flutter_wkwebview: ^3.21.0 dev_dependencies: build_runner: ^2.1.5 @@ -27,7 +27,7 @@ dev_dependencies: sdk: flutter integration_test: sdk: flutter - webview_flutter_platform_interface: ^2.11.0 + webview_flutter_platform_interface: ^2.12.0 flutter: uses-material-design: true diff --git a/packages/webview_flutter/webview_flutter/lib/src/webview_controller.dart b/packages/webview_flutter/webview_flutter/lib/src/webview_controller.dart index 6b720c9c753..e5c1361bfd9 100644 --- a/packages/webview_flutter/webview_flutter/lib/src/webview_controller.dart +++ b/packages/webview_flutter/webview_flutter/lib/src/webview_controller.dart @@ -406,6 +406,24 @@ class WebViewController { return platform.setOnScrollPositionChange(onScrollPositionChange); } + /// Whether the vertical scrollbar should be drawn or not. + Future setVerticalScrollBarEnabled(bool enabled) { + return platform.setVerticalScrollBarEnabled(enabled); + } + + /// Whether the horizontal scrollbar should be drawn or not. + Future setHorizontalScrollBarEnabled(bool enabled) { + return platform.setHorizontalScrollBarEnabled(enabled); + } + + /// Returns true if the current platform supports setting whether scrollbars + /// should be drawn or not. + /// + /// See [setVerticalScrollBarEnabled] and [setHorizontalScrollBarEnabled]. + Future supportsSetScrollBarsEnabled() async { + return platform.supportsSetScrollBarsEnabled(); + } + /// Sets the over-scroll mode for the WebView. /// /// Default behavior is platform dependent. diff --git a/packages/webview_flutter/webview_flutter/pubspec.yaml b/packages/webview_flutter/webview_flutter/pubspec.yaml index c609edc11ff..33484f3cead 100644 --- a/packages/webview_flutter/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget backed by the system webview. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 4.11.0 +version: 4.12.0 environment: sdk: ^3.6.0 @@ -21,9 +21,9 @@ flutter: dependencies: flutter: sdk: flutter - webview_flutter_android: ^4.4.0 - webview_flutter_platform_interface: ^2.11.0 - webview_flutter_wkwebview: ^3.19.0 + webview_flutter_android: ^4.5.0 + webview_flutter_platform_interface: ^2.12.0 + webview_flutter_wkwebview: ^3.21.0 dev_dependencies: build_runner: ^2.1.5 diff --git a/packages/webview_flutter/webview_flutter/test/webview_controller_test.dart b/packages/webview_flutter/webview_flutter/test/webview_controller_test.dart index f0310415a85..02acaa14b5e 100644 --- a/packages/webview_flutter/webview_flutter/test/webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter/test/webview_controller_test.dart @@ -281,6 +281,44 @@ void main() { verify(mockPlatformWebViewController.scrollBy(2, 3)); }); + test('setVerticalScrollBarEnabled', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.setVerticalScrollBarEnabled(true); + verify(mockPlatformWebViewController.setVerticalScrollBarEnabled(true)); + }); + + test('setHorizontalScrollBarEnabled', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.setHorizontalScrollBarEnabled(false); + verify(mockPlatformWebViewController.setHorizontalScrollBarEnabled(false)); + }); + + test('supportsSetScrollBarsEnabled', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.supportsSetScrollBarsEnabled()) + .thenReturn(true); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + expect(await webViewController.supportsSetScrollBarsEnabled(), true); + verify(mockPlatformWebViewController.supportsSetScrollBarsEnabled()); + }); + test('getScrollPosition', () async { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); diff --git a/packages/webview_flutter/webview_flutter/test/webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter/test/webview_controller_test.mocks.dart index 0c4537103a5..9c1b7e24961 100644 --- a/packages/webview_flutter/webview_flutter/test/webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter/test/webview_controller_test.mocks.dart @@ -223,6 +223,28 @@ class MockPlatformWebViewController extends _i1.Mock returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i5.Future setVerticalScrollBarEnabled(bool? enabled) => + (super.noSuchMethod( + Invocation.method(#setVerticalScrollBarEnabled, [enabled]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setHorizontalScrollBarEnabled(bool? enabled) => + (super.noSuchMethod( + Invocation.method(#setHorizontalScrollBarEnabled, [enabled]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + bool supportsSetScrollBarsEnabled() => (super.noSuchMethod( + Invocation.method(#supportsSetScrollBarsEnabled, []), + returnValue: false, + ) as bool); + @override _i5.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod( Invocation.method(#getScrollPosition, []), diff --git a/packages/webview_flutter/webview_flutter/test/webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter/test/webview_widget_test.mocks.dart index 69e0c449c6d..691f0fdbc31 100644 --- a/packages/webview_flutter/webview_flutter/test/webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter/test/webview_widget_test.mocks.dart @@ -236,6 +236,28 @@ class MockPlatformWebViewController extends _i1.Mock returnValueForMissingStub: _i7.Future.value(), ) as _i7.Future); + @override + _i7.Future setVerticalScrollBarEnabled(bool? enabled) => + (super.noSuchMethod( + Invocation.method(#setVerticalScrollBarEnabled, [enabled]), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future setHorizontalScrollBarEnabled(bool? enabled) => + (super.noSuchMethod( + Invocation.method(#setHorizontalScrollBarEnabled, [enabled]), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + bool supportsSetScrollBarsEnabled() => (super.noSuchMethod( + Invocation.method(#supportsSetScrollBarsEnabled, []), + returnValue: false, + ) as bool); + @override _i7.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod( Invocation.method(#getScrollPosition, []),