From b2bbb52ee1b70393134b643aa5fcb95147bb90af Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Fri, 14 Mar 2025 15:33:08 -0700 Subject: [PATCH] Add remaining dart fixes for Color deprecations when importing painting.dart (#162609) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Towards https://github.com/flutter/flutter/issues/160617 Noticed the `opacity` and `withOpacity` deprecations were supported by dart fix, but not the others. Adding them here. But strange too given `dart:ui` does not support dart fix (https://github.com/dart-lang/sdk/issues/59764).. --- We think since `painting.dart` exports `dart:ui`, this is somewhat of a workaround. If a user has this atop their file: ```dart import 'package:flutter/painting.dart'; // 👍 dart fix will work here ``` If instead ```dart import 'dart:ui'; // ❌ dart fix will not work here ``` Will continue to follow up on dart fix support for `dart:X` libraries, for now hopefully this will help! ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- engine/src/flutter/lib/ui/painting.dart | 8 ++++---- packages/flutter/lib/fix_data/fix_painting.yaml | 13 +++++++++++++ packages/flutter/test_fixes/painting/painting.dart | 1 + .../test_fixes/painting/painting.dart.expect | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index ddda85d2752..45d62600a84 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -263,7 +263,7 @@ class Color { /// /// A value of 0 means this color is fully transparent. A value of 255 means /// this color is fully opaque. - @Deprecated('Use .a.') + @Deprecated('Use (*.a * 255.0).round() & 0xff') int get alpha => (0xff000000 & value) >> 24; /// The alpha channel of this color as a double. @@ -274,15 +274,15 @@ class Color { double get opacity => alpha / 0xFF; /// The red channel of this color in an 8 bit value. - @Deprecated('Use .r.') + @Deprecated('Use (*.r * 255.0).round() & 0xff') int get red => (0x00ff0000 & value) >> 16; /// The green channel of this color in an 8 bit value. - @Deprecated('Use .g.') + @Deprecated('Use (*.g * 255.0).round() & 0xff') int get green => (0x0000ff00 & value) >> 8; /// The blue channel of this color in an 8 bit value. - @Deprecated('Use .b.') + @Deprecated('Use (*.b * 255.0).round() & 0xff') int get blue => (0x000000ff & value) >> 0; /// Returns a new color with the provided components updated. diff --git a/packages/flutter/lib/fix_data/fix_painting.yaml b/packages/flutter/lib/fix_data/fix_painting.yaml index 0ce947676cb..ea94b3c13fd 100644 --- a/packages/flutter/lib/fix_data/fix_painting.yaml +++ b/packages/flutter/lib/fix_data/fix_painting.yaml @@ -127,6 +127,19 @@ transforms: - kind: 'rename' newName: 'a' + - title: "Replace 'value' with 'toARGB32()'" + date: 2025-02-03 + element: + uris: [ 'painting.dart' ] + method: 'value' + inClass: 'Color' + changes: + - kind: 'replacedBy' + newElement: + uris: [ 'painting.dart' ] + method: 'toARGB32' + inClass: 'Color' + - title: "Rename 'withOpacity'" date: 2024-09-10 element: diff --git a/packages/flutter/test_fixes/painting/painting.dart b/packages/flutter/test_fixes/painting/painting.dart index 1bddb16ff18..efa2246e199 100644 --- a/packages/flutter/test_fixes/painting/painting.dart +++ b/packages/flutter/test_fixes/painting/painting.dart @@ -22,5 +22,6 @@ void main() { Color color = Color.from(alpha: 1, red: 0, green: 1, blue: 0); print(color.opacity); + print(color.value); color = color.withOpacity(0.55); } diff --git a/packages/flutter/test_fixes/painting/painting.dart.expect b/packages/flutter/test_fixes/painting/painting.dart.expect index 33a8f37dcea..816ff5b7915 100644 --- a/packages/flutter/test_fixes/painting/painting.dart.expect +++ b/packages/flutter/test_fixes/painting/painting.dart.expect @@ -21,5 +21,6 @@ void main() { Color color = Color.from(alpha: 1, red: 0, green: 1, blue: 0); print(color.a); + print(color.toARGB32()); color = color.withValues(alpha: 0.55); }