MorphTargetSpec.dialog constructor

MorphTargetSpec.dialog({
  1. double width = 440,
  2. double height = 360,
  3. double margin = 24,
  4. MorphSurfaceSpec? surface,
  5. ShapeBorder? shape,
  6. Color? surfaceColor,
})

A centered dialog of at most width x height.

Implementation

factory MorphTargetSpec.dialog({
  double width = 440,
  double height = 360,
  double margin = 24,
  MorphSurfaceSpec? surface,
  ShapeBorder? shape,
  Color? surfaceColor,
}) {
  return MorphTargetSpec(
    surface: surface,
    shape:
        shape ??
        const RoundedRectangleBorder(borderRadius: .all(.circular(24))),
    surfaceColor: surfaceColor,
    rectFor: (Size size, EdgeInsets padding) {
      final double w = math.max(0, math.min(width, size.width - margin * 2));
      final double h = math.max(
        0,
        math.min(height, size.height - margin * 2),
      );
      return Rect.fromCenter(
        center: Offset(
          size.width / 2,
          (size.height + padding.top - padding.bottom) / 2,
        ),
        width: w,
        height: h,
      );
    },
  );
}