@@ -8,6 +8,8 @@ import 'package:flutter/foundation.dart';
88
99import 'basic_types.dart' ;
1010
11+ const String _kDefaultDebugLabel = 'unknown' ;
12+
1113/// An immutable style in which paint text.
1214///
1315/// ## Sample code
@@ -230,10 +232,13 @@ class TextStyle extends Diagnosticable {
230232 this .decoration,
231233 this .decorationColor,
232234 this .decorationStyle,
235+ String debugLabel,
233236 String fontFamily,
234237 String package,
235238 }) : fontFamily = package == null ? fontFamily : 'packages/$package /$fontFamily ' ,
236- assert (inherit != null );
239+ debugLabel = debugLabel == null ? _kDefaultDebugLabel : debugLabel,
240+ assert (inherit != null ),
241+ assert (debugLabel == null || debugLabel.length <= 100 );
237242
238243
239244 /// Whether null values are replaced with their value in an ancestor text
@@ -302,6 +307,12 @@ class TextStyle extends Diagnosticable {
302307 /// The style in which to paint the text decorations (e.g., dashed).
303308 final TextDecorationStyle decorationStyle;
304309
310+ /// A human-readable description of this text style.
311+ ///
312+ /// This property is not considered when comparing text styles using `==` or
313+ /// [compareTo] , and it does not affect [hashCode] .
314+ final String debugLabel;
315+
305316 /// Creates a copy of this text style but with the given fields replaced with
306317 /// the new values.
307318 TextStyle copyWith ({
@@ -317,7 +328,14 @@ class TextStyle extends Diagnosticable {
317328 TextDecoration decoration,
318329 Color decorationColor,
319330 TextDecorationStyle decorationStyle,
331+ String debugLabel,
320332 }) {
333+ String newDebugLabel;
334+ assert (() {
335+ if (this .debugLabel != _kDefaultDebugLabel)
336+ newDebugLabel = _capDebugLabelLength (debugLabel ?? 'copy of ${this .debugLabel }' );
337+ return true ;
338+ }());
321339 return new TextStyle (
322340 inherit: inherit,
323341 color: color ?? this .color,
@@ -332,9 +350,18 @@ class TextStyle extends Diagnosticable {
332350 decoration: decoration ?? this .decoration,
333351 decorationColor: decorationColor ?? this .decorationColor,
334352 decorationStyle: decorationStyle ?? this .decorationStyle,
353+ debugLabel: newDebugLabel,
335354 );
336355 }
337356
357+ static String _capDebugLabelLength (String label) {
358+ const int maxLabelLength = 100 ;
359+ if (label.length > maxLabelLength) {
360+ return '${label .substring (0 , maxLabelLength - 3 )}...' ;
361+ }
362+ return label;
363+ }
364+
338365 /// Creates a copy of this text style replacing or altering the specified
339366 /// properties.
340367 ///
@@ -386,6 +413,14 @@ class TextStyle extends Diagnosticable {
386413 assert (heightFactor != null );
387414 assert (heightDelta != null );
388415 assert (heightFactor != null || (heightFactor == 1.0 && heightDelta == 0.0 ));
416+
417+ String modifiedDebugLabel;
418+ assert (() {
419+ if (debugLabel != _kDefaultDebugLabel)
420+ modifiedDebugLabel = _capDebugLabelLength ('modified $debugLabel ' );
421+ return true ;
422+ }());
423+
389424 return new TextStyle (
390425 inherit: inherit,
391426 color: color ?? this .color,
@@ -400,6 +435,7 @@ class TextStyle extends Diagnosticable {
400435 decoration: decoration ?? this .decoration,
401436 decorationColor: decorationColor ?? this .decorationColor,
402437 decorationStyle: decorationStyle ?? this .decorationStyle,
438+ debugLabel: modifiedDebugLabel,
403439 );
404440 }
405441
@@ -422,6 +458,13 @@ class TextStyle extends Diagnosticable {
422458 return this ;
423459 if (! other.inherit)
424460 return other;
461+
462+ String mergedDebugLabel;
463+ assert (() {
464+ mergedDebugLabel = _capDebugLabelLength ('${other .debugLabel } < $debugLabel ' );
465+ return true ;
466+ }());
467+
425468 return copyWith (
426469 color: other.color,
427470 fontFamily: other.fontFamily,
@@ -434,7 +477,8 @@ class TextStyle extends Diagnosticable {
434477 height: other.height,
435478 decoration: other.decoration,
436479 decorationColor: other.decorationColor,
437- decorationStyle: other.decorationStyle
480+ decorationStyle: other.decorationStyle,
481+ debugLabel: mergedDebugLabel,
438482 );
439483 }
440484
@@ -443,6 +487,13 @@ class TextStyle extends Diagnosticable {
443487 /// This will not work well if the styles don't set the same fields.
444488 static TextStyle lerp (TextStyle begin, TextStyle end, double t) {
445489 assert (begin.inherit == end.inherit);
490+
491+ String lerpDebugLabel;
492+ assert (() {
493+ lerpDebugLabel = _capDebugLabelLength ('lerp(${begin .debugLabel }, ${end .debugLabel })' );
494+ return true ;
495+ }());
496+
446497 return new TextStyle (
447498 inherit: end.inherit,
448499 color: Color .lerp (begin.color, end.color, t),
@@ -456,7 +507,8 @@ class TextStyle extends Diagnosticable {
456507 height: ui.lerpDouble (begin.height ?? end.height, end.height ?? begin.height, t),
457508 decoration: t < 0.5 ? begin.decoration : end.decoration,
458509 decorationColor: Color .lerp (begin.decorationColor, end.decorationColor, t),
459- decorationStyle: t < 0.5 ? begin.decorationStyle : end.decorationStyle
510+ decorationStyle: t < 0.5 ? begin.decorationStyle : end.decorationStyle,
511+ debugLabel: lerpDebugLabel,
460512 );
461513 }
462514
@@ -583,6 +635,8 @@ class TextStyle extends Diagnosticable {
583635 @override
584636 void debugFillProperties (DiagnosticPropertiesBuilder properties, { String prefix: '' }) {
585637 super .debugFillProperties (properties);
638+ if (debugLabel != _kDefaultDebugLabel)
639+ properties.add (new StringProperty ('${prefix }debugLabel' , debugLabel, defaultValue: null ));
586640 final List <DiagnosticsNode > styles = < DiagnosticsNode > [];
587641 styles.add (new DiagnosticsProperty <Color >('${prefix }color' , color, defaultValue: null ));
588642 styles.add (new StringProperty ('${prefix }family' , fontFamily, defaultValue: null , quoted: false ));
0 commit comments