text.dart 23.1 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'dart:ui' as ui show TextHeightBehavior;

7
import 'package:flutter/rendering.dart';
8 9

import 'basic.dart';
10
import 'default_selection_style.dart';
11
import 'framework.dart';
12
import 'inherited_theme.dart';
13
import 'media_query.dart';
14
import 'selection_container.dart';
15

16
// Examples can assume:
17
// late String _name;
18
// late BuildContext context;
19

20 21
/// The text style to apply to descendant [Text] widgets which don't have an
/// explicit style.
22 23 24 25 26 27 28
///
/// See also:
///
///  * [AnimatedDefaultTextStyle], which animates changes in the text style
///    smoothly over a given duration.
///  * [DefaultTextStyleTransition], which takes a provided [Animation] to
///    animate changes in text style smoothly over time.
29
class DefaultTextStyle extends InheritedTheme {
30 31
  /// Creates a default text style for the given subtree.
  ///
32
  /// Consider using [DefaultTextStyle.merge] to inherit styling information
33
  /// from the current default text style for a given [BuildContext].
34 35 36 37 38 39 40 41
  ///
  /// The [style] and [child] arguments are required and must not be null.
  ///
  /// The [softWrap] and [overflow] arguments must not be null (though they do
  /// have default values).
  ///
  /// The [maxLines] property may be null (and indeed defaults to null), but if
  /// it is not null, it must be greater than zero.
42
  const DefaultTextStyle({
43
    super.key,
44
    required this.style,
45
    this.textAlign,
46 47
    this.softWrap = true,
    this.overflow = TextOverflow.clip,
48
    this.maxLines,
49
    this.textWidthBasis = TextWidthBasis.parent,
50
    this.textHeightBehavior,
51
    required super.child,
52 53 54
  }) : assert(style != null),
       assert(softWrap != null),
       assert(overflow != null),
55
       assert(maxLines == null || maxLines > 0),
56
       assert(child != null),
57
       assert(textWidthBasis != null);
58

59
  /// A const-constructable default text style that provides fallback values.
60 61
  ///
  /// Returned from [of] when the given [BuildContext] doesn't have an enclosing default text style.
62
  ///
63
  /// This constructor creates a [DefaultTextStyle] with an invalid [child], which
64
  /// means the constructed value cannot be incorporated into the tree.
65
  const DefaultTextStyle.fallback({ super.key })
66 67 68
    : style = const TextStyle(),
      textAlign = null,
      softWrap = true,
69
      maxLines = null,
70
      overflow = TextOverflow.clip,
71
      textWidthBasis = TextWidthBasis.parent,
72
      textHeightBehavior = null,
73
      super(child: const _NullWidget());
74

75 76
  /// Creates a default text style that overrides the text styles in scope at
  /// this point in the widget tree.
77 78
  ///
  /// The given [style] is merged with the [style] from the default text style
79 80 81
  /// for the [BuildContext] where the widget is inserted, and any of the other
  /// arguments that are not null replace the corresponding properties on that
  /// same default text style.
82 83 84 85 86 87
  ///
  /// This constructor cannot be used to override the [maxLines] property of the
  /// ancestor with the value null, since null here is used to mean "defer to
  /// ancestor". To replace a non-null [maxLines] from an ancestor with the null
  /// value (to remove the restriction on number of lines), manually obtain the
  /// ambient [DefaultTextStyle] using [DefaultTextStyle.of], then create a new
88
  /// [DefaultTextStyle] using the [DefaultTextStyle.new] constructor directly.
89 90
  /// See the source below for an example of how to do this (since that's
  /// essentially what this constructor does).
91
  static Widget merge({
92 93 94 95 96 97 98 99
    Key? key,
    TextStyle? style,
    TextAlign? textAlign,
    bool? softWrap,
    TextOverflow? overflow,
    int? maxLines,
    TextWidthBasis? textWidthBasis,
    required Widget child,
100 101
  }) {
    assert(child != null);
102
    return Builder(
103 104
      builder: (BuildContext context) {
        final DefaultTextStyle parent = DefaultTextStyle.of(context);
105
        return DefaultTextStyle(
106
          key: key,
107
          style: parent.style.merge(style),
108 109 110 111
          textAlign: textAlign ?? parent.textAlign,
          softWrap: softWrap ?? parent.softWrap,
          overflow: overflow ?? parent.overflow,
          maxLines: maxLines ?? parent.maxLines,
112
          textWidthBasis: textWidthBasis ?? parent.textWidthBasis,
113
          child: child,
114 115
        );
      },
116 117 118 119
    );
  }

  /// The text style to apply.
120
  final TextStyle style;
121

122
  /// How each line of text in the Text widget should be aligned horizontally.
123
  final TextAlign? textAlign;
124 125 126 127

  /// Whether the text should break at soft line breaks.
  ///
  /// If false, the glyphs in the text will be positioned as if there was unlimited horizontal space.
128 129 130
  ///
  /// This also decides the [overflow] property's behavior. If this is true or null,
  /// the glyph causing overflow, and those that follow, will not be rendered.
131 132 133
  final bool softWrap;

  /// How visual overflow should be handled.
134 135 136
  ///
  /// If [softWrap] is true or null, the glyph causing overflow, and those that follow,
  /// will not be rendered. Otherwise, it will be shown with the given overflow option.
137 138
  final TextOverflow overflow;

139 140 141
  /// An optional maximum number of lines for the text to span, wrapping if necessary.
  /// If the text exceeds the given number of lines, it will be truncated according
  /// to [overflow].
142 143 144 145 146 147
  ///
  /// If this is 1, text will not wrap. Otherwise, text will be wrapped at the
  /// edge of the box.
  ///
  /// If this is non-null, it will override even explicit null values of
  /// [Text.maxLines].
148
  final int? maxLines;
149

150
  /// The strategy to use when calculating the width of the Text.
151
  ///
152 153 154
  /// See [TextWidthBasis] for possible values and their implications.
  final TextWidthBasis textWidthBasis;

155
  /// {@macro dart.ui.textHeightBehavior}
156
  final ui.TextHeightBehavior? textHeightBehavior;
157

158 159 160 161
  /// The closest instance of this class that encloses the given context.
  ///
  /// If no such instance exists, returns an instance created by
  /// [DefaultTextStyle.fallback], which contains fallback values.
162 163 164 165 166 167
  ///
  /// Typical usage is as follows:
  ///
  /// ```dart
  /// DefaultTextStyle style = DefaultTextStyle.of(context);
  /// ```
168
  static DefaultTextStyle of(BuildContext context) {
169
    return context.dependOnInheritedWidgetOfExactType<DefaultTextStyle>() ?? const DefaultTextStyle.fallback();
170 171 172
  }

  @override
173 174 175 176 177
  bool updateShouldNotify(DefaultTextStyle oldWidget) {
    return style != oldWidget.style ||
        textAlign != oldWidget.textAlign ||
        softWrap != oldWidget.softWrap ||
        overflow != oldWidget.overflow ||
178
        maxLines != oldWidget.maxLines ||
179 180
        textWidthBasis != oldWidget.textWidthBasis ||
        textHeightBehavior != oldWidget.textHeightBehavior;
181 182 183 184
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
185
    return DefaultTextStyle(
186 187 188 189 190 191
      style: style,
      textAlign: textAlign,
      softWrap: softWrap,
      overflow: overflow,
      maxLines: maxLines,
      textWidthBasis: textWidthBasis,
192
      textHeightBehavior: textHeightBehavior,
193 194
      child: child,
    );
195
  }
196 197

  @override
198 199
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
200
    style.debugFillProperties(properties);
201 202 203 204
    properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null));
    properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true));
    properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: null));
    properties.add(IntProperty('maxLines', maxLines, defaultValue: null));
205
    properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: TextWidthBasis.parent));
206
    properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null));
207 208 209
  }
}

210 211 212 213 214 215 216 217
class _NullWidget extends StatelessWidget {
  const _NullWidget();

  @override
  Widget build(BuildContext context) {
    throw FlutterError(
      'A DefaultTextStyle constructed with DefaultTextStyle.fallback cannot be incorporated into the widget tree, '
      'it is meant only to provide a fallback value returned by DefaultTextStyle.of() '
218
      'when no enclosing default text style is present in a BuildContext.',
219 220 221 222
    );
  }
}

223 224
/// The [TextHeightBehavior] that will apply to descendant [Text] and [EditableText]
/// widgets which have not explicitly set [Text.textHeightBehavior].
225 226 227 228 229 230 231 232 233 234 235 236 237 238
///
/// If there is a [DefaultTextStyle] with a non-null [DefaultTextStyle.textHeightBehavior]
/// below this widget, the [DefaultTextStyle.textHeightBehavior] will be used
/// over this widget's [TextHeightBehavior].
///
/// See also:
///
///  * [DefaultTextStyle], which defines a [TextStyle] to apply to descendant
///    [Text] widgets.
class DefaultTextHeightBehavior extends InheritedTheme {
  /// Creates a default text height behavior for the given subtree.
  ///
  /// The [textHeightBehavior] and [child] arguments are required and must not be null.
  const DefaultTextHeightBehavior({
239
    super.key,
240
    required this.textHeightBehavior,
241
    required super.child,
242
  }) :  assert(textHeightBehavior != null),
243
        assert(child != null);
244

245
  /// {@macro dart.ui.textHeightBehavior}
246 247 248 249 250 251 252 253 254
  final TextHeightBehavior textHeightBehavior;

  /// The closest instance of this class that encloses the given context.
  ///
  /// If no such instance exists, this method will return `null`.
  ///
  /// Typical usage is as follows:
  ///
  /// ```dart
255
  /// TextHeightBehavior defaultTextHeightBehavior = DefaultTextHeightBehavior.of(context)!;
256
  /// ```
257
  static TextHeightBehavior? of(BuildContext context) {
258 259 260 261 262 263 264 265 266 267
    return context.dependOnInheritedWidgetOfExactType<DefaultTextHeightBehavior>()?.textHeightBehavior;
  }

  @override
  bool updateShouldNotify(DefaultTextHeightBehavior oldWidget) {
    return textHeightBehavior != oldWidget.textHeightBehavior;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
268
    return DefaultTextHeightBehavior(
269 270 271 272 273 274 275 276 277 278 279 280
      textHeightBehavior: textHeightBehavior,
      child: child,
    );
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null));
  }
}

281 282 283 284 285 286 287 288
/// A run of text with a single style.
///
/// The [Text] widget displays a string of text with single style. The string
/// might break across multiple lines or might all be displayed on the same line
/// depending on the layout constraints.
///
/// The [style] argument is optional. When omitted, the text will use the style
/// from the closest enclosing [DefaultTextStyle]. If the given style's
289 290 291 292
/// [TextStyle.inherit] property is true (the default), the given style will
/// be merged with the closest enclosing [DefaultTextStyle]. This merging
/// behavior is useful, for example, to make the text bold while using the
/// default font family and size.
293
///
294
/// {@tool snippet}
295
///
296 297
/// This example shows how to display text using the [Text] widget with the
/// [overflow] set to [TextOverflow.ellipsis].
298
///
299
/// ![If the text is shorter than the available space, it is displayed in full without an ellipsis.](https://flutter.github.io/assets-for-api-docs/assets/widgets/text.png)
300
///
301
/// ![If the text overflows, the Text widget displays an ellipsis to trim the overflowing text](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_ellipsis.png)
302
///
303
/// ```dart
304
/// Text(
305
///   'Hello, $_name! How are you?',
306 307
///   textAlign: TextAlign.center,
///   overflow: TextOverflow.ellipsis,
308
///   style: const TextStyle(fontWeight: FontWeight.bold),
309 310
/// )
/// ```
311
/// {@end-tool}
312
///
313 314 315 316 317
/// Using the [Text.rich] constructor, the [Text] widget can
/// display a paragraph with differently styled [TextSpan]s. The sample
/// that follows displays "Hello beautiful world" with different styles
/// for each word.
///
318
/// {@tool snippet}
319
///
320
/// ![The word "Hello" is shown with the default text styles. The word "beautiful" is italicized. The word "world" is bold.](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_rich.png)
321
///
322 323
/// ```dart
/// const Text.rich(
324
///   TextSpan(
325
///     text: 'Hello', // default text style
326 327 328
///     children: <TextSpan>[
///       TextSpan(text: ' beautiful ', style: TextStyle(fontStyle: FontStyle.italic)),
///       TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)),
329 330
///     ],
///   ),
331
/// )
332
/// ```
333
/// {@end-tool}
334
///
335 336 337 338 339
/// ## Interactivity
///
/// To make [Text] react to touch events, wrap it in a [GestureDetector] widget
/// with a [GestureDetector.onTap] handler.
///
340
/// In a Material Design application, consider using a [TextButton] instead, or
341 342 343 344 345 346 347
/// if that isn't appropriate, at least using an [InkWell] instead of
/// [GestureDetector].
///
/// To make sections of the text interactive, use [RichText] and specify a
/// [TapGestureRecognizer] as the [TextSpan.recognizer] of the relevant part of
/// the text.
///
348 349 350 351 352 353 354 355 356 357 358
/// ## Selection
///
/// [Text] is not selectable by default. To make a [Text] selectable, one can
/// wrap a subtree with a [SelectionArea] widget. To exclude a part of a subtree
/// under [SelectionArea] from selection, once can also wrap that part of the
/// subtree with [SelectionContainer.disabled].
///
/// {@tool dartpad}
/// This sample demonstrates how to disable selection for a Text under a
/// SelectionArea.
///
359
/// ** See code in examples/api/lib/material/selection_container/selection_container_disabled.0.dart **
360 361
/// {@end-tool}
///
362 363
/// See also:
///
364 365
///  * [RichText], which gives you more control over the text styles.
///  * [DefaultTextStyle], which sets default styles for [Text] widgets.
366
///  * [SelectableRegion], which provides an overview of the selection system.
367 368 369 370 371
class Text extends StatelessWidget {
  /// Creates a text widget.
  ///
  /// If the [style] argument is null, the text will use the style from the
  /// closest enclosing [DefaultTextStyle].
372 373
  ///
  /// The [data] parameter must not be null.
374 375
  ///
  /// The [overflow] property's behavior is affected by the [softWrap] argument.
376 377 378
  /// If the [softWrap] is true or null, the glyph causing overflow, and those
  /// that follow, will not be rendered. Otherwise, it will be shown with the
  /// given overflow option.
379
  const Text(
380
    String this.data, {
381
    super.key,
382
    this.style,
383
    this.strutStyle,
384
    this.textAlign,
Ian Hickson's avatar
Ian Hickson committed
385
    this.textDirection,
386
    this.locale,
387 388
    this.softWrap,
    this.overflow,
389 390
    this.textScaleFactor,
    this.maxLines,
391
    this.semanticsLabel,
392
    this.textWidthBasis,
393
    this.textHeightBehavior,
394
    this.selectionColor,
395 396 397 398
  }) : assert(
         data != null,
         'A non-null String must be provided to a Text widget.',
       ),
399
       textSpan = null;
400

401 402 403 404 405 406
  /// Creates a text widget with a [InlineSpan].
  ///
  /// The following subclasses of [InlineSpan] may be used to build rich text:
  ///
  /// * [TextSpan]s define text and children [InlineSpan]s.
  /// * [WidgetSpan]s define embedded inline widgets.
407 408
  ///
  /// The [textSpan] parameter must not be null.
409 410
  ///
  /// See [RichText] which provides a lower-level way to draw text.
411
  const Text.rich(
412
    InlineSpan this.textSpan, {
413
    super.key,
414
    this.style,
415
    this.strutStyle,
416 417
    this.textAlign,
    this.textDirection,
418
    this.locale,
419 420 421 422
    this.softWrap,
    this.overflow,
    this.textScaleFactor,
    this.maxLines,
423
    this.semanticsLabel,
424
    this.textWidthBasis,
425
    this.textHeightBehavior,
426
    this.selectionColor,
427 428 429 430
  }) : assert(
         textSpan != null,
         'A non-null TextSpan must be provided to a Text.rich widget.',
       ),
431
       data = null;
432

433
  /// The text to display.
434 435
  ///
  /// This will be null if a [textSpan] is provided instead.
436
  final String? data;
437

438
  /// The text to display as a [InlineSpan].
439 440
  ///
  /// This will be null if [data] is provided instead.
441
  final InlineSpan? textSpan;
442

443 444 445 446 447
  /// If non-null, the style to use for this text.
  ///
  /// If the style's "inherit" property is true, the style will be merged with
  /// the closest enclosing [DefaultTextStyle]. Otherwise, the style will
  /// replace the closest enclosing [DefaultTextStyle].
448
  final TextStyle? style;
449

450
  /// {@macro flutter.painting.textPainter.strutStyle}
451
  final StrutStyle? strutStyle;
452

453
  /// How the text should be aligned horizontally.
454
  final TextAlign? textAlign;
455

Ian Hickson's avatar
Ian Hickson committed
456 457 458 459 460 461 462 463 464
  /// The directionality of the text.
  ///
  /// This decides how [textAlign] values like [TextAlign.start] and
  /// [TextAlign.end] are interpreted.
  ///
  /// This is also used to disambiguate how to render bidirectional text. For
  /// example, if the [data] is an English phrase followed by a Hebrew phrase,
  /// in a [TextDirection.ltr] context the English phrase will be on the left
  /// and the Hebrew phrase to its right, while in a [TextDirection.rtl]
465
  /// context, the English phrase will be on the right and the Hebrew phrase on
Ian Hickson's avatar
Ian Hickson committed
466 467 468
  /// its left.
  ///
  /// Defaults to the ambient [Directionality], if any.
469
  final TextDirection? textDirection;
Ian Hickson's avatar
Ian Hickson committed
470

471 472 473 474 475 476 477
  /// Used to select a font when the same Unicode character can
  /// be rendered differently, depending on the locale.
  ///
  /// It's rarely necessary to set this property. By default its value
  /// is inherited from the enclosing app with `Localizations.localeOf(context)`.
  ///
  /// See [RenderParagraph.locale] for more information.
478
  final Locale? locale;
479

480 481 482
  /// Whether the text should break at soft line breaks.
  ///
  /// If false, the glyphs in the text will be positioned as if there was unlimited horizontal space.
483
  final bool? softWrap;
484 485

  /// How visual overflow should be handled.
486
  ///
487 488
  /// If this is null [TextStyle.overflow] will be used, otherwise the value
  /// from the nearest [DefaultTextStyle] ancestor will be used.
489
  final TextOverflow? overflow;
490 491 492 493 494 495

  /// The number of font pixels for each logical pixel.
  ///
  /// For example, if the text scale factor is 1.5, text will be 50% larger than
  /// the specified font size.
  ///
496
  /// The value given to the constructor as textScaleFactor. If null, will
497
  /// use the [MediaQueryData.textScaleFactor] obtained from the ambient
498
  /// [MediaQuery], or 1.0 if there is no [MediaQuery] in scope.
499
  final double? textScaleFactor;
500

501
  /// An optional maximum number of lines for the text to span, wrapping if necessary.
502 503
  /// If the text exceeds the given number of lines, it will be truncated according
  /// to [overflow].
504 505 506 507 508 509 510 511
  ///
  /// If this is 1, text will not wrap. Otherwise, text will be wrapped at the
  /// edge of the box.
  ///
  /// If this is null, but there is an ambient [DefaultTextStyle] that specifies
  /// an explicit number for its [DefaultTextStyle.maxLines], then the
  /// [DefaultTextStyle] value will take precedence. You can use a [RichText]
  /// widget directly to entirely override the [DefaultTextStyle].
512
  final int? maxLines;
513

514
  /// {@template flutter.widgets.Text.semanticsLabel}
515 516 517
  /// An alternative semantics label for this text.
  ///
  /// If present, the semantics of this widget will contain this value instead
518 519
  /// of the actual text. This will overwrite any of the semantics labels applied
  /// directly to the [TextSpan]s.
520
  ///
521
  /// This is useful for replacing abbreviations or shorthands with the full
522 523 524
  /// text value:
  ///
  /// ```dart
525
  /// const Text(r'$$', semanticsLabel: 'Double dollars')
526
  /// ```
527
  /// {@endtemplate}
528
  final String? semanticsLabel;
529

530
  /// {@macro flutter.painting.textPainter.textWidthBasis}
531
  final TextWidthBasis? textWidthBasis;
532

533
  /// {@macro dart.ui.textHeightBehavior}
534
  final ui.TextHeightBehavior? textHeightBehavior;
535

536
  /// The color to use when painting the selection.
537 538 539 540 541 542 543
  ///
  /// This is ignored if [SelectionContainer.maybeOf] returns null
  /// in the [BuildContext] of the [Text] widget.
  ///
  /// If null, the ambient [DefaultSelectionStyle] is used (if any); failing
  /// that, the selection color defaults to [DefaultSelectionStyle.defaultColor]
  /// (semi-transparent grey).
544 545
  final Color? selectionColor;

546 547
  @override
  Widget build(BuildContext context) {
548
    final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context);
549
    TextStyle? effectiveTextStyle = style;
550
    if (style == null || style!.inherit) {
551
      effectiveTextStyle = defaultTextStyle.style.merge(style);
552 553
    }
    if (MediaQuery.boldTextOverride(context)) {
554
      effectiveTextStyle = effectiveTextStyle!.merge(const TextStyle(fontWeight: FontWeight.bold));
555
    }
556
    final SelectionRegistrar? registrar = SelectionContainer.maybeOf(context);
557
    Widget result = RichText(
Ian Hickson's avatar
Ian Hickson committed
558 559
      textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
      textDirection: textDirection, // RichText uses Directionality.of to obtain a default if this is null.
560
      locale: locale, // RichText uses Localizations.localeOf to obtain a default if this is null
561
      softWrap: softWrap ?? defaultTextStyle.softWrap,
562
      overflow: overflow ?? effectiveTextStyle?.overflow ?? defaultTextStyle.overflow,
563
      textScaleFactor: textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
564
      maxLines: maxLines ?? defaultTextStyle.maxLines,
565
      strutStyle: strutStyle,
566
      textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis,
567
      textHeightBehavior: textHeightBehavior ?? defaultTextStyle.textHeightBehavior ?? DefaultTextHeightBehavior.of(context),
568
      selectionRegistrar: registrar,
569
      selectionColor: selectionColor ?? DefaultSelectionStyle.of(context).selectionColor ?? DefaultSelectionStyle.defaultColor,
570
      text: TextSpan(
571
        style: effectiveTextStyle,
572
        text: data,
573
        children: textSpan != null ? <InlineSpan>[textSpan!] : null,
574
      ),
575
    );
576 577 578 579 580 581
    if (registrar != null) {
      result = MouseRegion(
        cursor: SystemMouseCursors.text,
        child: result,
      );
    }
582
    if (semanticsLabel != null) {
583
      result = Semantics(
584 585
        textDirection: textDirection,
        label: semanticsLabel,
586
        child: ExcludeSemantics(
587
          child: result,
588
        ),
589 590 591
      );
    }
    return result;
592 593 594
  }

  @override
595 596
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
597
    properties.add(StringProperty('data', data, showName: false));
598
    if (textSpan != null) {
599
      properties.add(textSpan!.toDiagnosticsNode(name: 'textSpan', style: DiagnosticsTreeStyle.transition));
600
    }
601
    style?.debugFillProperties(properties);
602 603 604 605 606 607 608
    properties.add(EnumProperty<TextAlign>('textAlign', textAlign, defaultValue: null));
    properties.add(EnumProperty<TextDirection>('textDirection', textDirection, defaultValue: null));
    properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null));
    properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true));
    properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: null));
    properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: null));
    properties.add(IntProperty('maxLines', maxLines, defaultValue: null));
609 610
    properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: null));
    properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null));
611
    if (semanticsLabel != null) {
612
      properties.add(StringProperty('semanticsLabel', semanticsLabel));
613
    }
614 615
  }
}