isCustomPositionRequiredForImage function

bool isCustomPositionRequiredForImage(
  1. PaintModel paint,
  2. SizeC nodeSize
)

This fixes an issue with Flutter's image aligning. Flutter can't align image with given alignment when the widget and image both have same size. This is a workaround for that. It uses a stack in that case.

Implementation

bool isCustomPositionRequiredForImage(PaintModel paint, SizeC nodeSize) {
  if (!paint.fit.supportsAlignment) return false;
  if (paint.alignment.isStandard) return false;
  if (paint.sourceWidth == null || paint.sourceHeight == null) return false;
  if (paint.isNonUniformScale) return true;
  if (paint.fit == Fit.fitWidth || paint.fit == Fit.fitHeight) {
    final diff = (paint.sourceWidth! / paint.sourceHeight!) -
        (nodeSize.width / nodeSize.height);
    if (diff.closeTo(0)) return true;
  }

  final imgX = paint.sourceWidth! / paint.scaleX.abs();
  final imgY = paint.sourceHeight! / paint.scaleY.abs();

  return imgX == nodeSize.width || imgY == nodeSize.height;
}