AttributedString constructor Null safety

AttributedString(
  1. String string,
  2. {List<StringAttribute> attributes = const <StringAttribute>[]}
)

Creates a attributed string.

The TextRange in the attributes must be inside the length of the string.

The attributes must not be changed after the attributed string is created.

Implementation

AttributedString(
  this.string, {
  this.attributes = const <StringAttribute>[],
}) : assert(string.isNotEmpty || attributes.isEmpty),
     assert(() {
      for (final StringAttribute attribute in attributes) {
        assert(
          string.length >= attribute.range.start &&
          string.length >= attribute.range.end,
          'The range in $attribute is outside of the string $string',
        );
      }
      return true;
    }());