Skip to content

Commit ad21d8d

Browse files
[webview_flutter] Replace deprecated Color.value (#10480)
Replaces the deprecated `Color.value` with the equivalent `Color.toARGB()`. For iOS, where this is not the ideal long-term solution, adds a TODO for a better replacement. Part of flutter/flutter#159739 ## 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 631e97a commit ad21d8d

File tree

13 files changed

+27
-14
lines changed

13 files changed

+27
-14
lines changed

packages/webview_flutter/webview_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.10.7
2+
3+
* Replaces use of deprecated Color.value.
4+
15
## 4.10.6
26

37
* Updates to Pigeon 26.

packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ class AndroidWebViewController extends PlatformWebViewController {
648648

649649
@override
650650
Future<void> setBackgroundColor(Color color) =>
651-
_webView.setBackgroundColor(color.value);
651+
_webView.setBackgroundColor(color.toARGB32());
652652

653653
@override
654654
Future<void> setJavaScriptMode(JavaScriptMode javaScriptMode) => _webView

packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController {
451451

452452
final Color? backgroundColor = creationParams.backgroundColor;
453453
if (backgroundColor != null) {
454-
webView.setBackgroundColor(backgroundColor.value);
454+
webView.setBackgroundColor(backgroundColor.toARGB32());
455455
}
456456

457457
addJavascriptChannels(creationParams.javascriptChannelNames);

packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SurfaceAndroidWebView extends AndroidWebView {
6767
// AndroidViewSurface. This switches the WebView to Hybrid
6868
// Composition when the background color is not 100% opaque.
6969
hybridComposition:
70-
backgroundColor != null && backgroundColor.opacity < 1.0,
70+
backgroundColor != null && backgroundColor.a < 1.0,
7171
id: params.id,
7272
viewType: 'plugins.flutter.io/webview',
7373
// WebView content is not affected by the Android view's layout direction,

packages/webview_flutter/webview_flutter_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: webview_flutter_android
22
description: A Flutter plugin that provides a WebView widget on Android.
33
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
5-
version: 4.10.6
5+
version: 4.10.7
66

77
environment:
88
sdk: ^3.9.0

packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ void main() {
18681868

18691869
await controller.setBackgroundColor(Colors.blue);
18701870

1871-
verify(mockWebView.setBackgroundColor(Colors.blue.value)).called(1);
1871+
verify(mockWebView.setBackgroundColor(Colors.blue.toARGB32())).called(1);
18721872
});
18731873

18741874
test('setJavaScriptMode', () async {

packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.23.4
2+
3+
* Replaces use of deprecated Color.value.
4+
15
## 3.23.3
26

37
* Updates to Pigeon 26.

packages/webview_flutter/webview_flutter_wkwebview/lib/src/legacy/web_kit_webview_widget.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ class WebKitWebViewPlatformController extends WebViewPlatformController {
242242

243243
if (params.backgroundColor != null) {
244244
unawaited(webView.setOpaque(false));
245-
unawaited(webView.setBackgroundColor(Colors.transparent.value));
245+
unawaited(webView.setBackgroundColor(Colors.transparent.toARGB32()));
246246
unawaited(
247-
webView.scrollView.setBackgroundColor(params.backgroundColor?.value),
247+
webView.scrollView.setBackgroundColor(
248+
params.backgroundColor?.toARGB32(),
249+
),
248250
);
249251
}
250252

packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,9 @@ class WebKitWebViewController extends PlatformWebViewController {
651651
Future<void> setBackgroundColor(Color color) {
652652
return Future.wait(<Future<void>>[
653653
_webView.setOpaque(false),
654-
_webView.setBackgroundColor(Colors.transparent.value),
654+
_webView.setBackgroundColor(Colors.transparent.toARGB32()),
655655
// This method must be called last.
656-
_webView.scrollView.setBackgroundColor(color.value),
656+
_webView.scrollView.setBackgroundColor(color.toARGB32()),
657657
]);
658658
}
659659

packages/webview_flutter/webview_flutter_wkwebview/pigeons/web_kit.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ abstract class WKWebsiteDataStore extends NSObject {
602602
)
603603
abstract class UIView extends NSObject {
604604
/// The view’s background color.
605+
// TODO(bparrishMines): Using an int here is lossy, and should be replaced
606+
// with a full color representation. See
607+
// https://github.com/flutter/flutter/issues/178870.
605608
void setBackgroundColor(int? value);
606609

607610
/// A Boolean value that determines whether the view is opaque.

0 commit comments

Comments
 (0)