scaleToMaxWidth method

Widget scaleToMaxWidth({
  1. required BuildContext context,
  2. double maxWidth = 400,
  3. double factor = 1.0,
})

Scales the widget conditionally based on a maximum width.

Implementation

Widget scaleToMaxWidth({
  required BuildContext context,
  double maxWidth = 400,
  double factor = 1.0,
}) {
  final screenWidth = MediaQuery.of(context).size.width;
  final scale = screenWidth < maxWidth ? (screenWidth / maxWidth) * factor : factor;
  return Transform.scale(
    scale: scale,
    child: this,
  );
}