import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:hmg_patient_app_new/extensions/int_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:shimmer/shimmer.dart'; import 'package:sizer/sizer.dart'; import 'package:smooth_corner/smooth_corner.dart'; extension WidgetExtensions on Widget { Widget onPress(VoidCallback onTap) => InkWell(onTap: onTap, child: this); Widget get expanded => Expanded(child: this); Widget get center => Center(child: this); Widget circle(double _value) => ClipRRect(borderRadius: BorderRadius.circular(_value), child: this); Widget paddingAll(double _value) => Padding(padding: EdgeInsets.all(_value), child: this); Widget paddingSymmetrical(double horizontal, double vertical) => Padding(padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical), child: this); Widget paddingOnly({double left = 0.0, double right = 0.0, double top = 0.0, double bottom = 0.0}) => Padding(padding: EdgeInsets.only(left: left, right: right, top: top, bottom: bottom), child: this); Widget toExpanded({int flex = 1}) => Expanded(flex: flex, child: this); Widget toShimmer({bool isShow = true, bool isTransparent = false}) => isShow ? Shimmer.fromColors( baseColor: Color(0xffb9bebe), highlightColor: Colors.white, child: Container( color: isTransparent ? Colors.transparent : Colors.white.withOpacity(0.3), child: this, ), ) : Container( child: this, ); Widget toShimmer2({bool isShow = true, double radius = 20, double? width, double? height}) => isShow ? Shimmer.fromColors( baseColor: const Color(0xffe8eff0), highlightColor: Colors.white, child: ClipRRect( borderRadius: BorderRadius.circular(radius), child: Container( width: width, height: height, color: Colors.white, child: this, ), ), ) : this; Widget animatedSwither() => AnimatedSwitcher( duration: const Duration(milliseconds: 500), // transitionBuilder: (Widget child, Animation animation) { // return ScaleTransition(scale: animation, child: child); // }, switchInCurve: Curves.linearToEaseOut, switchOutCurve: Curves.linearToEaseOut, child: this, ); Widget objectContainerView({String title = "", String note = "", bool disablePadding = false, double radius = 15}) { return Container( padding: disablePadding ? EdgeInsets.zero : const EdgeInsets.only(top: 15, bottom: 15, left: 14, right: 14), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(radius), boxShadow: [ BoxShadow( color: const Color(0xff000000).withOpacity(.15), blurRadius: 26, offset: const Offset(0, -3), ), ], ), alignment: Alignment.center, child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ if (title.isNotEmpty) title.toText16(), if (title.isNotEmpty) 12.height, this, if (note.isNotEmpty) note.toText11(), ], ), ); } Widget objectContainerBorderView( {String title = "", String note = "", bool disablePadding = false, double radius = 20, Color? color, Color borderColor = AppColors.buttonColor, bool disableWidth = false, bool isAlignment = false}) { return Container( padding: disablePadding ? EdgeInsets.zero : const EdgeInsets.only(top: 15, bottom: 15, left: 14, right: 14), decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(radius), ), color: color, border: Border.all( color: borderColor, width: disableWidth ? 2 : 1, ), ), alignment: isAlignment ? Alignment.center : null, child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ if (title.isNotEmpty) title.toText16(), if (title.isNotEmpty) 12.height, this, if (note.isNotEmpty) note.toText11(), ], ), ); } Widget withHorizontalPadding([double padding = 16.0]) { return Padding( padding: EdgeInsets.symmetric(horizontal: padding), child: this, ); } Widget withVerticalPadding([double padding = 16.0]) { return Padding( padding: EdgeInsets.symmetric(vertical: padding), child: this, ); } } extension SmoothContainerExtension on ShapeBorder { ShapeDecoration toSmoothCornerDecoration({ Color color = Colors.transparent, double? borderRadius, bool isDisabled = false, Color? backgroundColor, BorderSide? side, BorderRadius? customBorder, bool hasShadow = false, }) { final bgColor = backgroundColor ?? color; return ShapeDecoration( color: isDisabled ? bgColor.withOpacity(0.5) : bgColor, shape: SmoothRectangleBorder( borderRadius: customBorder ?? BorderRadius.circular(borderRadius ?? 0), smoothness: 1, side: side ?? BorderSide.none, ), shadows: hasShadow ? [ BoxShadow( color: const Color(0xff000000).withOpacity(.05), blurRadius: 32, offset: const Offset(0, 0), ) ] : [], ); } } //Height Spacers in percentages Widget heightSpacer02per() => SizedBox(height: 0.2.h); Widget heightSpacer04per() => SizedBox(height: 0.4.h); Widget heightSpacer06per() => SizedBox(height: 0.6.h); Widget heightSpacer08per() => SizedBox(height: 0.8.h); Widget heightSpacer1per() => SizedBox(height: 1.h); Widget heightSpacer2per() => SizedBox(height: 2.h); Widget heightSpacer3per() => SizedBox(height: 3.h); Widget heightSpacer4per() => SizedBox(height: 4.h); Widget heightSpacer5per() => SizedBox(height: 5.h); Widget heightSpacer8per() => SizedBox(height: 8.h); Widget heightSpacer10per() => SizedBox(height: 10.h); Widget heightSpacer15per() => SizedBox(height: 15.h); Widget heightSpacer20per() => SizedBox(height: 20.h); //Width Spacers in percentages Widget widthSpacer02perc() => SizedBox(height: 0.2.w); Widget widthSpacer04perc() => SizedBox(height: 0.4.w); Widget widthSpacer06perc() => SizedBox(height: 0.6.w); Widget widthSpacer08per() => SizedBox(height: 0.8.w); Widget widthSpacer1per() => SizedBox(height: 1.w); Widget widthSpacer2per() => SizedBox(height: 2.w); Widget widthSpacer3per() => SizedBox(height: 3.w); Widget widthSpacer4per() => SizedBox(height: 4.w); Widget widthSpacer5per() => SizedBox(height: 5.w); extension ChipTypeEnumExtension on ChipTypeEnum { Color get color { switch (this) { case ChipTypeEnum.success: return AppColors.successColor; // Replace with your actual color case ChipTypeEnum.error: return AppColors.errorColor; // Replace with your actual color case ChipTypeEnum.alert: return AppColors.alertColor; // Replace with your actual color case ChipTypeEnum.info: return AppColors.infoColor; // Replace with your actual color case ChipTypeEnum.warning: return AppColors.warningColor; // Replace with your actual color case ChipTypeEnum.lightBg: return AppColors.chipPrimaryRedBorderColor; // Replace with your actual color case ChipTypeEnum.primaryRed: return AppColors.chipSecondaryLightRedColor; // Replace with your actual color } } Color get backgroundColor { switch (this) { case ChipTypeEnum.success: return AppColors.successLightColor; // Replace with your actual color case ChipTypeEnum.error: return AppColors.errorLightColor; // Replace with your actual color case ChipTypeEnum.alert: return AppColors.alertLightColor; // Replace with your actual color case ChipTypeEnum.info: return AppColors.infoLightColor; // Replace with your actual color case ChipTypeEnum.warning: return AppColors.warningLightColor; // Replace with your actual color case ChipTypeEnum.lightBg: return AppColors.chipSecondaryLightRedColor; // Replace with your actual color case ChipTypeEnum.primaryRed: return AppColors.chipPrimaryRedBorderColor; } } }