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');