Skip to content

Commit 8d2aca3

Browse files
authored
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.
1 parent 84e1086 commit 8d2aca3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/flutter/lib/src/painting/text_style.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,10 @@ class TextStyle with Diagnosticable {
893893
assert(backgroundColor == null || background == null, _kColorBackgroundWarning);
894894
String? newDebugLabel;
895895
assert(() {
896-
if (this.debugLabel != null) {
897-
newDebugLabel = debugLabel ?? '(${this.debugLabel}).copyWith';
896+
if (debugLabel != null) {
897+
newDebugLabel = debugLabel;
898+
} else if (this.debugLabel != null) {
899+
newDebugLabel = '(${this.debugLabel}).copyWith';
898900
}
899901
return true;
900902
}());

packages/flutter/test/painting/text_style_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ void main() {
374374
expect(unknown.debugLabel, null);
375375
expect(unknown.toString(), 'TextStyle(<all styles inherited>)');
376376
expect(unknown.copyWith().debugLabel, null);
377+
expect(unknown.copyWith(debugLabel: '123').debugLabel, '123');
377378
expect(unknown.apply().debugLabel, null);
378379

379380
expect(foo.debugLabel, 'foo');

0 commit comments

Comments
 (0)