responsivePadding method
Add padding with responsive values based on screen size
Implementation
Widget responsivePadding(BuildContext context, {
double? all,
double? horizontal,
double? vertical,
double? left,
double? top,
double? right,
double? bottom,
}) {
final screenWidth = MediaQuery.of(context).size.width;
final scaleFactor = screenWidth / 375.0; // Base width for scaling (iPhone X)
EdgeInsetsGeometry paddingValue;
if (all != null) {
paddingValue = EdgeInsets.all(all * scaleFactor);
} else if (horizontal != null || vertical != null) {
paddingValue = EdgeInsets.symmetric(
horizontal: (horizontal ?? 0) * scaleFactor,
vertical: (vertical ?? 0) * scaleFactor,
);
} else {
paddingValue = EdgeInsets.only(
left: (left ?? 0) * scaleFactor,
top: (top ?? 0) * scaleFactor,
right: (right ?? 0) * scaleFactor,
bottom: (bottom ?? 0) * scaleFactor,
);
}
return Padding(padding: paddingValue, child: this);
}