From 8d2aca385fe11847566b4a99314e2bf9b8889ec2 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Tue, 9 Jan 2024 15:21:24 -0800 Subject: [PATCH] TextStyle: In copyWith, stop ignoring debugLabel when receiver has none (#141141) Fixes #141140. This ensures that if you call `.copyWith` and pass a `debugLabel`, the `debugLabel` won't be ignored, even if the receiver (the TextStyle you're calling `.copyWith` on) doesn't have a `debugLabel`. The debugLabel field was added in #12552. I skimmed the discussion there and didn't find anything indicating that the param was being ignored on purpose. I added a test case that passes with the new code and fails with the old code. --- packages/flutter/lib/src/painting/text_style.dart | 6 ++++-- packages/flutter/test/painting/text_style_test.dart | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index f85e10436d..ab01cc5e96 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -893,8 +893,10 @@ class TextStyle with Diagnosticable { assert(backgroundColor == null || background == null, _kColorBackgroundWarning); String? newDebugLabel; assert(() { - if (this.debugLabel != null) { - newDebugLabel = debugLabel ?? '(${this.debugLabel}).copyWith'; + if (debugLabel != null) { + newDebugLabel = debugLabel; + } else if (this.debugLabel != null) { + newDebugLabel = '(${this.debugLabel}).copyWith'; } return true; }()); diff --git a/packages/flutter/test/painting/text_style_test.dart b/packages/flutter/test/painting/text_style_test.dart index ffad8a3d66..09c0bf2c4a 100644 --- a/packages/flutter/test/painting/text_style_test.dart +++ b/packages/flutter/test/painting/text_style_test.dart @@ -374,6 +374,7 @@ void main() { expect(unknown.debugLabel, null); expect(unknown.toString(), 'TextStyle()'); expect(unknown.copyWith().debugLabel, null); + expect(unknown.copyWith(debugLabel: '123').debugLabel, '123'); expect(unknown.apply().debugLabel, null); expect(foo.debugLabel, 'foo');