import 'package:another_flushbar/flushbar.dart'; import 'package:flutter/material.dart'; import 'package:shimmer/shimmer.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/new_views/swipe_module/dialoge/acknowledge_work_dialog.dart'; import '../new_views/app_style/app_color.dart'; extension WidgetExtensions on Widget { Widget onPress(VoidCallback? onTap) => InkWell(onTap: onTap, highlightColor: Colors.transparent, splashColor: Colors.transparent, child: this); Widget get expanded => Expanded(child: this); Widget get center => Center(child: this); BoxShadow get boxShadowR14 => BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 5, offset: const Offset(0, 0), spreadRadius: 0); Widget circle(double value) => ClipRRect(borderRadius: BorderRadius.circular(value), child: this); Widget paddingAll(double value) => Padding(padding: EdgeInsets.all(value), child: this); Widget get bottomSafeArea => SafeArea(bottom: true, top: false, right: false, left: false, child: this); Widget indicatorWidget({double? height, double? width, Color? color}) => Container( width: height ?? 50.toScreenWidth, height: width ?? 5.toScreenHeight, decoration: BoxDecoration(color: color ?? AppColor.white50, borderRadius: BorderRadius.circular(30)), child: this, ); Widget flushBar({required BuildContext context, required String title, required String message, int? duration, Color? backgroundColor}) => Flushbar( flushbarPosition: FlushbarPosition.TOP, backgroundColor: backgroundColor ?? AppColor.green70, title: title, messageText: Text( message, style: AppTextStyles.heading6.copyWith(color: AppColor.white10), ), duration: Duration(seconds: duration ?? 3), flushbarStyle: FlushbarStyle.GROUNDED, reverseAnimationCurve: Curves.easeInOut, mainButton: IconButton( onPressed: () { Navigator.pop(context); }, icon: const Icon( Icons.close, color: AppColor.white20, ).paddingOnly(top: 25), ), )..show(context); Widget paddingOnly({int start = 0, int end = 0, int top = 0, int bottom = 0}) => Padding(padding: EdgeInsetsDirectional.only(start: start.toScreenWidth, end: end.toScreenWidth, top: top.toScreenHeight, bottom: bottom.toScreenHeight), child: this); Widget toExpanded({int flex = 1}) => Expanded(flex: flex, child: this); Widget handlePopScope({required BuildContext cxt, required VoidCallback onSave, bool? showPopUp = true}) { return showPopUp! ? PopScope( canPop: false, onPopInvokedWithResult: (didPop, result) { if (didPop) { return; } showDialog( context: cxt, builder: (BuildContext cxt) => AcknowledgeWorkDialog( onSave: () => onSave(), onDiscard: () { Navigator.of(cxt).pop(); }, ), ); }, child: this) : this; } Widget toShimmer({bool isShow = true, double radius = 20, required BuildContext context}) => isShow ? Shimmer.fromColors( baseColor: context.isDark ? AppColor.backgroundDark : const Color(0xffe8eff0), highlightColor: AppColor.background(context), child: ClipRRect( borderRadius: BorderRadius.circular(radius), child: Container( color: AppColor.background(context), child: this, ), ), ) : this; Widget toRequestShimmer(BuildContext context, bool isShow) => isShow ? Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(width: 250, height: 24).toShimmer(isShow: isShow, context: context), 8.height, const SizedBox(width: 160, height: 16).toShimmer(isShow: isShow, context: context), 8.height, const SizedBox(width: 120, height: 18).toShimmer(isShow: isShow, context: context).toShimmer(isShow: isShow, context: context), ], ).toShadowContainer(context) : this; Widget toShadowContainer( BuildContext context, { bool showShadow = true, double borderRadius = 14, bool withShadow = true, Color? backgroundColor, Color borderColor = Colors.transparent, double padding = 16, EdgeInsets? paddingObject, EdgeInsets? margin, }) => withShadow ? Container( padding: paddingObject ?? EdgeInsets.all(padding), margin: margin, width: double.infinity, decoration: ShapeDecoration( color: backgroundColor ?? AppColor.background(context), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(borderRadius), side: BorderSide(color: borderColor)), shadows: showShadow ? [boxShadowR14] : null, ), child: this, ) : this; Widget bottomSheetContainer(BuildContext context, {EdgeInsets? padding}) => Container( clipBehavior: Clip.antiAlias, margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), decoration: BoxDecoration( // color: AppColor.background(context), color: Theme.of(context).scaffoldBackgroundColor, borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), ), padding: padding ?? EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), child: this, ); Widget bottomSheetContainerNew(BuildContext context, {EdgeInsets? padding, String? title}) => Container( clipBehavior: Clip.antiAlias, margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), decoration: BoxDecoration( color: AppColor.background(context), borderRadius: const BorderRadius.only(topRight: Radius.circular(30), topLeft: Radius.circular(30)), ), padding: padding ?? EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 12.toScreenHeight), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 50.toScreenWidth, height: 6.toScreenHeight, decoration: BoxDecoration(color: AppColor.white50, borderRadius: BorderRadius.circular(30)), ).center, 16.height, if (title != null) ...[ title.bottomSheetHeadingTextStyle(context), 16.height, ], this ], ), ); Widget toShadowCircleContainer(BuildContext context, {bool showShadow = true, double padding = 16}) => showShadow ? Container( padding: EdgeInsets.all(padding), decoration: BoxDecoration( color: AppColor.background(context), shape: BoxShape.circle, boxShadow: [boxShadowR14], ), child: this, ) : this; } extension DividerExtension on Divider { Divider defaultStyle(BuildContext context) => Divider(thickness: 1, color: context.isDark ? AppColor.neutral20 : AppColor.neutral30); }