You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/extensions/widget_extensions.dart

116 lines
4.7 KiB
Dart

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 '../new_views/app_style/app_color.dart';
extension WidgetExtensions on Widget {
Widget onPress(VoidCallback onTap) => InkWell(onTap: onTap, child: this, highlightColor: Colors.transparent, splashColor: Colors.transparent);
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 indicatorWidget({double height,double width,Color color})=> Container(
width: height??40.toScreenWidth,
height: width??5.toScreenHeight,
decoration: BoxDecoration(color:color?? AppColor.white50, borderRadius: BorderRadius.circular(30)),
child: this,
);
Widget flushBar({@required BuildContext context,String title,String message,double duration,Color backgroundColor})=>Flushbar(
flushbarPosition: FlushbarPosition.TOP,
backgroundColor:backgroundColor?? AppColor.green70,
title: title ?? "Hey Ninja",
message: message ?? "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
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,
),
),
)..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 toShimmer({bool isShow = true, double radius = 20}) => isShow
? Shimmer.fromColors(
baseColor: const Color(0xffe8eff0),
highlightColor: Colors.white,
child: ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: Container(
color: Colors.white,
child: this,
),
),
)
: this;
Widget toRequestShimmer(BuildContext context, bool isShow) => isShow
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(width: 250, height: 24).toShimmer(isShow: isShow),
8.height,
const SizedBox(width: 160, height: 16).toShimmer(isShow: isShow),
8.height,
const SizedBox(width: 120, height: 18).toShimmer(isShow: isShow).toShimmer(isShow: isShow),
],
).toShadowContainer(context)
: this;
Widget toShadowContainer(BuildContext context, {bool showShadow = true, double padding = 16}) => showShadow
? Container(
padding: EdgeInsets.all(padding),
width: double.infinity,
decoration: ShapeDecoration(
color: AppColor.background(context),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
shadows: [boxShadowR14],
),
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),
borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
),
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight),
child: 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);
}