RichText constructor Null safety

RichText(
  1. {Key? key,
  2. required InlineSpan text,
  3. TextAlign textAlign = TextAlign.start,
  4. TextDirection? textDirection,
  5. bool softWrap = true,
  6. TextOverflow overflow = TextOverflow.clip,
  7. double textScaleFactor = 1.0,
  8. int? maxLines,
  9. Locale? locale,
  10. StrutStyle? strutStyle,
  11. TextWidthBasis textWidthBasis = TextWidthBasis.parent,
  12. TextHeightBehavior? textHeightBehavior,
  13. SelectionRegistrar? selectionRegistrar,
  14. Color? selectionColor}
)

Creates a paragraph of rich text.

The text, textAlign, softWrap, overflow, and textScaleFactor arguments must not be null.

The maxLines property may be null (and indeed defaults to null), but if it is not null, it must be greater than zero.

The textDirection, if null, defaults to the ambient Directionality, which in that case must not be null.

Implementation

RichText({
  super.key,
  required this.text,
  this.textAlign = TextAlign.start,
  this.textDirection,
  this.softWrap = true,
  this.overflow = TextOverflow.clip,
  this.textScaleFactor = 1.0,
  this.maxLines,
  this.locale,
  this.strutStyle,
  this.textWidthBasis = TextWidthBasis.parent,
  this.textHeightBehavior,
  this.selectionRegistrar,
  this.selectionColor,
}) : assert(text != null),
     assert(textAlign != null),
     assert(softWrap != null),
     assert(overflow != null),
     assert(textScaleFactor != null),
     assert(maxLines == null || maxLines > 0),
     assert(textWidthBasis != null),
     assert(selectionRegistrar == null || selectionColor != null),
     super(children: _extractChildren(text));