Skip to content

Commit 4e6e61d

Browse files
Retain the toString method for subclasses of Key in profile/release mode (#149926)
toString methods are removed in AOT builds by the optimization in flutter/flutter#144763 This PR disables that for Key subclasses because some applications rely on the previous behavior. Fixes flutter/flutter#148983
1 parent 2d0a023 commit 4e6e61d

File tree

2 files changed

+9
-0
lines changed
  • dev/integration_tests/release_smoke_test/lib
  • packages/flutter/lib/src/foundation

2 files changed

+9
-0
lines changed

dev/integration_tests/release_smoke_test/lib/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Future<void> main() async {
1717
// regression test for https://github.com/flutter/flutter/issues/49601
1818
final List<int> computed = await compute(_utf8Encode, 'test');
1919
print(computed);
20+
21+
// regression test for https://github.com/flutter/flutter/issues/148983
22+
const String value = 'testValueKey';
23+
const ValueKey<String> valueKey = ValueKey<String>(value);
24+
if (!valueKey.toString().contains(value)) {
25+
throw Exception('ValueKey string does not contain the value');
26+
}
27+
2028
runApp(
2129
const Center(
2230
child: text,

packages/flutter/lib/src/foundation/key.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'diagnostics.dart';
2121
///
2222
/// * [Widget.key], which discusses how widgets use keys.
2323
@immutable
24+
@pragma('flutter:keep-to-string-in-subtypes')
2425
abstract class Key {
2526
/// Construct a [ValueKey<String>] with the given [String].
2627
///

0 commit comments

Comments
 (0)