Skip to content

Commit b6c74bd

Browse files
[webview_flutter] Adds support to control whether to draw scrollbars (#9024)
Fixes flutter/flutter#62464 Updated version of #8174 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 58d4016 commit b6c74bd

File tree

7 files changed

+113
-9
lines changed

7 files changed

+113
-9
lines changed

packages/webview_flutter/webview_flutter/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
## NEXT
1+
## 4.12.0
22

3-
* Updates README to indicate that Andoid SDK <21 is no longer supported.
3+
* Adds support to set whether to draw the scrollbar. See
4+
`WebViewController.setVerticalScrollBarEnabled`,
5+
`WebViewController.setHorizontalScrollBarEnabled`,
6+
`WebViewController.supportsSetScrollBarsEnabled`.
7+
* Updates README to indicate that Android SDK <21 is no longer supported.
48

59
## 4.11.0
610

packages/webview_flutter/webview_flutter/example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dependencies:
1717
# The example app is bundled with the plugin so we use a path dependency on
1818
# the parent directory to use the current plugin's version.
1919
path: ../
20-
webview_flutter_android: ^4.4.0
21-
webview_flutter_wkwebview: ^3.19.0
20+
webview_flutter_android: ^4.5.0
21+
webview_flutter_wkwebview: ^3.21.0
2222

2323
dev_dependencies:
2424
build_runner: ^2.1.5
@@ -27,7 +27,7 @@ dev_dependencies:
2727
sdk: flutter
2828
integration_test:
2929
sdk: flutter
30-
webview_flutter_platform_interface: ^2.11.0
30+
webview_flutter_platform_interface: ^2.12.0
3131

3232
flutter:
3333
uses-material-design: true

packages/webview_flutter/webview_flutter/lib/src/webview_controller.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,24 @@ class WebViewController {
406406
return platform.setOnScrollPositionChange(onScrollPositionChange);
407407
}
408408

409+
/// Whether the vertical scrollbar should be drawn or not.
410+
Future<void> setVerticalScrollBarEnabled(bool enabled) {
411+
return platform.setVerticalScrollBarEnabled(enabled);
412+
}
413+
414+
/// Whether the horizontal scrollbar should be drawn or not.
415+
Future<void> setHorizontalScrollBarEnabled(bool enabled) {
416+
return platform.setHorizontalScrollBarEnabled(enabled);
417+
}
418+
419+
/// Returns true if the current platform supports setting whether scrollbars
420+
/// should be drawn or not.
421+
///
422+
/// See [setVerticalScrollBarEnabled] and [setHorizontalScrollBarEnabled].
423+
Future<bool> supportsSetScrollBarsEnabled() async {
424+
return platform.supportsSetScrollBarsEnabled();
425+
}
426+
409427
/// Sets the over-scroll mode for the WebView.
410428
///
411429
/// Default behavior is platform dependent.

packages/webview_flutter/webview_flutter/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: webview_flutter
22
description: A Flutter plugin that provides a WebView widget backed by the system webview.
33
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
5-
version: 4.11.0
5+
version: 4.12.0
66

77
environment:
88
sdk: ^3.6.0
@@ -21,9 +21,9 @@ flutter:
2121
dependencies:
2222
flutter:
2323
sdk: flutter
24-
webview_flutter_android: ^4.4.0
25-
webview_flutter_platform_interface: ^2.11.0
26-
webview_flutter_wkwebview: ^3.19.0
24+
webview_flutter_android: ^4.5.0
25+
webview_flutter_platform_interface: ^2.12.0
26+
webview_flutter_wkwebview: ^3.21.0
2727

2828
dev_dependencies:
2929
build_runner: ^2.1.5

packages/webview_flutter/webview_flutter/test/webview_controller_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,44 @@ void main() {
281281
verify(mockPlatformWebViewController.scrollBy(2, 3));
282282
});
283283

284+
test('setVerticalScrollBarEnabled', () async {
285+
final MockPlatformWebViewController mockPlatformWebViewController =
286+
MockPlatformWebViewController();
287+
288+
final WebViewController webViewController = WebViewController.fromPlatform(
289+
mockPlatformWebViewController,
290+
);
291+
292+
await webViewController.setVerticalScrollBarEnabled(true);
293+
verify(mockPlatformWebViewController.setVerticalScrollBarEnabled(true));
294+
});
295+
296+
test('setHorizontalScrollBarEnabled', () async {
297+
final MockPlatformWebViewController mockPlatformWebViewController =
298+
MockPlatformWebViewController();
299+
300+
final WebViewController webViewController = WebViewController.fromPlatform(
301+
mockPlatformWebViewController,
302+
);
303+
304+
await webViewController.setHorizontalScrollBarEnabled(false);
305+
verify(mockPlatformWebViewController.setHorizontalScrollBarEnabled(false));
306+
});
307+
308+
test('supportsSetScrollBarsEnabled', () async {
309+
final MockPlatformWebViewController mockPlatformWebViewController =
310+
MockPlatformWebViewController();
311+
when(mockPlatformWebViewController.supportsSetScrollBarsEnabled())
312+
.thenReturn(true);
313+
314+
final WebViewController webViewController = WebViewController.fromPlatform(
315+
mockPlatformWebViewController,
316+
);
317+
318+
expect(await webViewController.supportsSetScrollBarsEnabled(), true);
319+
verify(mockPlatformWebViewController.supportsSetScrollBarsEnabled());
320+
});
321+
284322
test('getScrollPosition', () async {
285323
final MockPlatformWebViewController mockPlatformWebViewController =
286324
MockPlatformWebViewController();

packages/webview_flutter/webview_flutter/test/webview_controller_test.mocks.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,28 @@ class MockPlatformWebViewController extends _i1.Mock
223223
returnValueForMissingStub: _i5.Future<void>.value(),
224224
) as _i5.Future<void>);
225225

226+
@override
227+
_i5.Future<void> setVerticalScrollBarEnabled(bool? enabled) =>
228+
(super.noSuchMethod(
229+
Invocation.method(#setVerticalScrollBarEnabled, [enabled]),
230+
returnValue: _i5.Future<void>.value(),
231+
returnValueForMissingStub: _i5.Future<void>.value(),
232+
) as _i5.Future<void>);
233+
234+
@override
235+
_i5.Future<void> setHorizontalScrollBarEnabled(bool? enabled) =>
236+
(super.noSuchMethod(
237+
Invocation.method(#setHorizontalScrollBarEnabled, [enabled]),
238+
returnValue: _i5.Future<void>.value(),
239+
returnValueForMissingStub: _i5.Future<void>.value(),
240+
) as _i5.Future<void>);
241+
242+
@override
243+
bool supportsSetScrollBarsEnabled() => (super.noSuchMethod(
244+
Invocation.method(#supportsSetScrollBarsEnabled, []),
245+
returnValue: false,
246+
) as bool);
247+
226248
@override
227249
_i5.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod(
228250
Invocation.method(#getScrollPosition, []),

packages/webview_flutter/webview_flutter/test/webview_widget_test.mocks.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,28 @@ class MockPlatformWebViewController extends _i1.Mock
236236
returnValueForMissingStub: _i7.Future<void>.value(),
237237
) as _i7.Future<void>);
238238

239+
@override
240+
_i7.Future<void> setVerticalScrollBarEnabled(bool? enabled) =>
241+
(super.noSuchMethod(
242+
Invocation.method(#setVerticalScrollBarEnabled, [enabled]),
243+
returnValue: _i7.Future<void>.value(),
244+
returnValueForMissingStub: _i7.Future<void>.value(),
245+
) as _i7.Future<void>);
246+
247+
@override
248+
_i7.Future<void> setHorizontalScrollBarEnabled(bool? enabled) =>
249+
(super.noSuchMethod(
250+
Invocation.method(#setHorizontalScrollBarEnabled, [enabled]),
251+
returnValue: _i7.Future<void>.value(),
252+
returnValueForMissingStub: _i7.Future<void>.value(),
253+
) as _i7.Future<void>);
254+
255+
@override
256+
bool supportsSetScrollBarsEnabled() => (super.noSuchMethod(
257+
Invocation.method(#supportsSetScrollBarsEnabled, []),
258+
returnValue: false,
259+
) as bool);
260+
239261
@override
240262
_i7.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod(
241263
Invocation.method(#getScrollPosition, []),

0 commit comments

Comments
 (0)