From 4e6e61dfd5a1433bf6300784a7b67946427aa57a Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 10 Jun 2024 09:06:02 -0700 Subject: [PATCH] Retain the toString method for subclasses of Key in profile/release mode (#149926) toString methods are removed in AOT builds by the optimization in https://github.com/flutter/flutter/pull/144763 This PR disables that for Key subclasses because some applications rely on the previous behavior. Fixes https://github.com/flutter/flutter/issues/148983 --- dev/integration_tests/release_smoke_test/lib/main.dart | 8 ++++++++ packages/flutter/lib/src/foundation/key.dart | 1 + 2 files changed, 9 insertions(+) diff --git a/dev/integration_tests/release_smoke_test/lib/main.dart b/dev/integration_tests/release_smoke_test/lib/main.dart index fefb9400900..7160c30b793 100644 --- a/dev/integration_tests/release_smoke_test/lib/main.dart +++ b/dev/integration_tests/release_smoke_test/lib/main.dart @@ -17,6 +17,14 @@ Future main() async { // regression test for https://github.com/flutter/flutter/issues/49601 final List computed = await compute(_utf8Encode, 'test'); print(computed); + + // regression test for https://github.com/flutter/flutter/issues/148983 + const String value = 'testValueKey'; + const ValueKey valueKey = ValueKey(value); + if (!valueKey.toString().contains(value)) { + throw Exception('ValueKey string does not contain the value'); + } + runApp( const Center( child: text, diff --git a/packages/flutter/lib/src/foundation/key.dart b/packages/flutter/lib/src/foundation/key.dart index a14dff9d574..0940e80ac2a 100644 --- a/packages/flutter/lib/src/foundation/key.dart +++ b/packages/flutter/lib/src/foundation/key.dart @@ -21,6 +21,7 @@ import 'diagnostics.dart'; /// /// * [Widget.key], which discusses how widgets use keys. @immutable +@pragma('flutter:keep-to-string-in-subtypes') abstract class Key { /// Construct a [ValueKey] with the given [String]. ///