updateModel method

void updateModel(
  1. dynamic model, {
  2. int? flag,
  3. Size imageSize = const Size(52, 20),
  4. double textScaleFactor = 1,
  5. dynamic layoutChildren(
    1. List<PlaceholderSpan>
    )?,
})

Implementation

void updateModel(
  model, {
  int? flag,
  ui.Size imageSize = const Size(52, 20),
  double textScaleFactor = 1,
  Function(List<PlaceholderSpan>)? layoutChildren,
}) {
  _model = model;
  if (flag != null) {
    this.flag = flag;
  }
  _isImage = imageAsset != null;
  var padding = _model.padding;
  if (isImage) {
    size = imageSize + Offset(padding.horizontal, padding.vertical);
  } else {
    span = _model.spans.isEmpty
        ? WidgetSpan(
            child: StrokeTextWidget(
              _model.text,
              textStyle: _model.textStyle,
              opacity: _model.opacity,
              textScaleFactor: textScaleFactor,
              strokeWidth: _model.strokeWidth,
            ),
          )
        : TextSpan(children: _model.spans, style: _model.textStyle);
    var placeholderDimensions = (layoutChildren ?? _defaultLayoutChildren)
        .call(_extractPlaceholderSpans(span!));
    textPainter = TextPainter(textDirection: TextDirection.ltr)
      ..text = span
      ..setPlaceholderDimensions(placeholderDimensions)
      ..textScaleFactor = textScaleFactor;
    textPainter!.layout();

    var textStyle = span!.style;
    if (textStyle != null) {
      var textStrokeSpanStyle = textStyle.copyWith(
          foreground: Paint()
            ..style = PaintingStyle.stroke
            ..strokeWidth = _model.strokeWidth * 2
            ..color = Colors.black);
      textStrokeSpan = _model.spans.isEmpty
          ? TextSpan(text: _model.text, style: textStrokeSpanStyle)
          : TextSpan(children: _model.spans, style: textStrokeSpanStyle);

      textStrokePainter = TextPainter(textDirection: TextDirection.ltr)
        ..text = textStrokeSpan
        ..setPlaceholderDimensions(placeholderDimensions)
        ..textScaleFactor = textScaleFactor;
      textStrokePainter!.layout();
    }
    final double width = textPainter!.width + padding.horizontal;
    final double height = textPainter!.height + padding.vertical;
    size = Size(width, height);
  }

  configuration = ImageConfiguration(size: size);
}