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

82 lines
3.1 KiB
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, 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: 14, 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 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 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);
}