paintDecoration method

void paintDecoration(
  1. PaintingContext context,
  2. Offset offset,
  3. PaintingContextCallback callback
)

Implementation

void paintDecoration(
    PaintingContext context, Offset offset, PaintingContextCallback callback) {
  CSSBoxDecoration? decoration = renderStyle.decoration;
  DecorationPosition decorationPosition = renderStyle.decorationPosition;
  ImageConfiguration imageConfiguration = renderStyle.imageConfiguration;

  if (decoration == null) return callback(context, offset);

  EdgeInsets? padding = renderStyle.padding.resolve(TextDirection.ltr);
  _painter ??=
      BoxDecorationPainter(padding, renderStyle, markNeedsPaint);

  final ImageConfiguration filledConfiguration =
      imageConfiguration.copyWith(size: size);
  if (decorationPosition == DecorationPosition.background) {
    int? debugSaveCount;
    assert(() {
      debugSaveCount = context.canvas.getSaveCount();
      return true;
    }());

    _painter!.paint(context.canvas, offset, filledConfiguration);
    assert(() {
      if (debugSaveCount != context.canvas.getSaveCount()) {
        throw FlutterError.fromParts(<DiagnosticsNode>[
          ErrorSummary(
              '${decoration.runtimeType} painter had mismatching save and restore calls.'),
          ErrorDescription(
              'Before painting the decoration, the canvas save count was $debugSaveCount. '
              'After painting it, the canvas save count was ${context.canvas.getSaveCount()}. '
              'Every call to save() or saveLayer() must be matched by a call to restore().'),
          DiagnosticsProperty<Decoration>('The decoration was', decoration,
              style: DiagnosticsTreeStyle.errorProperty),
          DiagnosticsProperty<BoxPainter>('The painter was', _painter,
              style: DiagnosticsTreeStyle.errorProperty),
        ]);
      }
      return true;
    }());
    if (decoration.isComplex) context.setIsComplexHint();
  }
  Offset contentOffset;
  EdgeInsets borderEdge = renderStyle.border;
  contentOffset = offset.translate(borderEdge.left, borderEdge.top);
  super.paint(context, contentOffset);
  if (decorationPosition == DecorationPosition.foreground) {
    _painter!.paint(context.canvas, offset, filledConfiguration);
    if (decoration.isComplex) context.setIsComplexHint();
  }

  callback(context, offset);
}