responsive method
Adds a card-like decoration
Example:
Text('Hello').card(elevation: 4)
Makes widget responsive based on screen size
Example:
Text('Hello').responsive(
mobile: (child) => child.paddingAll(8),
tablet: (child) => child.paddingAll(16),
desktop: (child) => child.paddingAll(24),
)
Implementation
// Widget card({
// double elevation = 2,
// Color? color,
// BorderRadius? borderRadius,
// }) {
// return Container(
// decoration: BoxDecoration(
// color: color ?? Colors.white,
// borderRadius: borderRadius ?? AppSizes.radiusMd.radius,
// boxShadow: [
// BoxShadow(
// color: Colors.black.withAlpha((0.1 * 255).toInt()),
// blurRadius: elevation,
// offset: Offset(0, elevation / 2),
// ),
// ],
// ),
// child: this,
// );
// }
/// Makes widget responsive based on screen size
///
/// Example:
/// ```dart
/// Text('Hello').responsive(
/// mobile: (child) => child.paddingAll(8),
/// tablet: (child) => child.paddingAll(16),
/// desktop: (child) => child.paddingAll(24),
/// )
/// ```
Widget responsive(
BuildContext context, {
Widget Function(Widget)? mobile,
Widget Function(Widget)? tablet,
Widget Function(Widget)? desktop,
}) {
final deviceType = ResponsiveHelper.getDeviceType(context);
switch (deviceType) {
case DeviceType.desktop:
return desktop?.call(this) ?? tablet?.call(this) ?? mobile?.call(this) ?? this;
case DeviceType.tablet:
return tablet?.call(this) ?? mobile?.call(this) ?? this;
case DeviceType.mobile:
return mobile?.call(this) ?? this;
}
}