Honestly, it’s quite ez to add them here is mine:
import 'package:flutter/material.dart';
import 'package:my_utils/extensions/border_radius_extension.dart';
extension WidgetX on Widget {
Widget showIf(final bool condition) =>
condition ? this : const SizedBox.shrink();
Widget showIfNot(final bool condition) =>
!condition ? this : const SizedBox.shrink();
Widget showIfOr(final bool condition, final Widget alternative) =>
condition ? this : alternative;
Widget showIfElse(
final bool condition,
final Widget trueWidget,
final Widget falseWidget,
) => condition ? trueWidget : falseWidget;
Widget showIfNotNull<T>(final T? value) =>
value != null ? this : const SizedBox.shrink();
Widget showIfEmpty<T>(final Iterable<T> collection) =>
collection.isEmpty ? this : const SizedBox.shrink();
Widget showIfNotEmpty<T>(final Iterable<T> collection) =>
collection.isNotEmpty ? this : const SizedBox.shrink();
Widget showIfZero(final num value) =>
value == 0 ? this : const SizedBox.shrink();
Widget showIfNotZero(final num value) =>
value != 0 ? this : const SizedBox.shrink();
// Padding
Widget padding(final EdgeInsets padding) =>
Padding(padding: padding, child: this);
Widget paddingAll(final double value) =>
Padding(padding: EdgeInsets.all(value), child: this);
Widget paddingSymmetric({
final double vertical = 0.0,
final double horizontal = 0.0,
}) => Padding(
padding: EdgeInsets.symmetric(vertical: vertical, horizontal: horizontal),
child: this,
);
Widget paddingVertical(final double value) => Padding(
padding: EdgeInsets.symmetric(vertical: value),
child: this,
);
Widget paddingHorizontal(final double value) => Padding(
padding: EdgeInsets.symmetric(horizontal: value),
child: this,
);
Widget paddingStart(final double value) => Padding(
padding: EdgeInsetsDirectional.only(start: value),
child: this,
);
Widget paddingEnd(final double value) => Padding(
padding: EdgeInsetsDirectional.only(end: value),
child: this,
);
// Centering & Alignment
Widget center() => Center(child: this);
Widget align([final Alignment alignment = Alignment.center]) =>
Align(alignment: alignment, child: this);
Widget alignTopLeft() => Align(alignment: Alignment.topLeft, child: this);
Widget alignCenter() => Align(child: this);
Widget alignTopCenter() => Align(alignment: Alignment.topCenter, child: this);
Widget alignTopRight() => Align(alignment: Alignment.topRight, child: this);
Widget alignCenterLeft() =>
Align(alignment: Alignment.centerLeft, child: this);
Widget alignCenterRight() =>
Align(alignment: Alignment.centerRight, child: this);
Widget alignBottomLeft() =>
Align(alignment: Alignment.bottomLeft, child: this);
Widget alignBottomCenter() =>
Align(alignment: Alignment.bottomCenter, child: this);
Widget alignBottomRight() =>
Align(alignment: Alignment.bottomRight, child: this);
// Flex
Widget expand({final int flex = 1}) => Expanded(flex: flex, child: this);
Widget flexible({final int flex = 1, final FlexFit fit = FlexFit.loose}) =>
Flexible(flex: flex, fit: fit, child: this);
// Sizing
Widget width(final double value) => SizedBox(width: value, child: this);
Widget height(final double value) => SizedBox(height: value, child: this);
Widget size({final double? height, final double? width}) =>
SizedBox(height: height, width: width, child: this);
Widget square(final double size) =>
SizedBox(width: size, height: size, child: this);
Widget infiniteWidth() => SizedBox(width: double.infinity, child: this);
Widget infiniteHeight() => SizedBox(height: double.infinity, child: this);
// Interaction
Widget onTap(final VoidCallback onTap) =>
GestureDetector(onTap: onTap, child: this);
Widget onLongPress(final VoidCallback onLongPress) =>
GestureDetector(onLongPress: onLongPress, child: this);
// Clipping & Styling
Widget borderRadius(final BorderRadius radius) =>
ClipRRect(borderRadius: radius, child: this);
Widget circular(final double radius) => ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(radius)),
child: this,
);
Widget opacity(final double value) => Opacity(opacity: value, child: this);
Widget circle({final Clip clipBehavior = Clip.antiAlias}) =>
ClipRRect(borderRadius: BorderRadiusX.circle, child: this);
// Sliver utils
Widget toSliverBoxAdapter() => SliverToBoxAdapter(child: this);
// Visibility & Animation
Widget visible(final bool visible) =>
Visibility(visible: visible, child: this);
Widget offstage(final bool offstage) =>
Offstage(offstage: offstage, child: this);
Widget ignorePointer() => IgnorePointer(child: this);
Widget absorbPointer() => AbsorbPointer(child: this);
Widget decoration(final Decoration decoration) =>
DecoratedBox(decoration: decoration, child: this);
Widget decorated({
final Color? color,
final DecorationImage? image,
final BoxBorder? border,
final BorderRadius? borderRadius,
final List<BoxShadow>? boxShadow,
final Gradient? gradient,
final BoxShape shape = BoxShape.rectangle,
final BlendMode? backgroundBlendMode,
}) => DecoratedBox(
decoration: BoxDecoration(
color: color,
image: image,
border: border,
borderRadius: borderRadius,
boxShadow: boxShadow,
gradient: gradient,
shape: shape,
backgroundBlendMode: backgroundBlendMode,
),
child: this,
);
Widget scale(final double scale) =>
Transform.scale(scale: scale, child: this);
Widget scaleX(final double scale) =>
Transform.scale(scaleX: scale, child: this);
Widget scaleY(final double scale) =>
Transform.scale(scaleY: scale, child: this);
Widget scaleXY({
required final double scaleX,
required final double scaleY,
}) => Transform.scale(scaleX: scaleX, scaleY: scaleY, child: this);
Widget backgroundColor(final Color color) =>
ColoredBox(color: color, child: this);
}