mirror of
https://github.com/flutter/flutter
synced 2024-09-13 05:11:45 +00:00
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.
This commit is contained in:
parent
84e1086c4e
commit
8d2aca385f
|
@ -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;
|
||||
}());
|
||||
|
|
|
@ -374,6 +374,7 @@ void main() {
|
|||
expect(unknown.debugLabel, null);
|
||||
expect(unknown.toString(), 'TextStyle(<all styles inherited>)');
|
||||
expect(unknown.copyWith().debugLabel, null);
|
||||
expect(unknown.copyWith(debugLabel: '123').debugLabel, '123');
|
||||
expect(unknown.apply().debugLabel, null);
|
||||
|
||||
expect(foo.debugLabel, 'foo');
|
||||
|
|
Loading…
Reference in a new issue