Created
November 11, 2025 18:56
-
-
Save EsinShadrach/4df93c123ed94e2a5250cacf761d7705 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:playcope/lib.dart'; | |
| extension OnWidgets on Widget { | |
| Widget withPadding({ | |
| double all = 0, | |
| double right = 0, | |
| double left = 0, | |
| double top = 0, | |
| double bottom = 0, | |
| double padding = 0, | |
| double vertical = 0, | |
| double horizontal = 0, | |
| }) { | |
| EdgeInsets decidePadding() { | |
| if (all > 0) { | |
| return EdgeInsets.all(all); | |
| } | |
| if (vertical > 0 && horizontal > 0) { | |
| return EdgeInsets.symmetric(vertical: vertical, horizontal: horizontal); | |
| } | |
| if (vertical > 0) { | |
| return EdgeInsets.symmetric(vertical: vertical); | |
| } | |
| if (horizontal > 0) { | |
| return EdgeInsets.symmetric(horizontal: horizontal); | |
| } | |
| if (padding > 0) { | |
| return EdgeInsets.all(padding); | |
| } | |
| if (right > 0 || left > 0 || top > 0 || bottom > 0) { | |
| return EdgeInsets.only( | |
| left: left, | |
| top: top, | |
| right: right, | |
| bottom: bottom, | |
| ); | |
| } | |
| return EdgeInsets.symmetric( | |
| horizontal: left + right, | |
| vertical: top + bottom, | |
| ); | |
| } | |
| return Padding(padding: decidePadding(), child: this); | |
| } | |
| // withSizedBox | |
| Widget withSizedBox({double? width, double? height, double? dimension}) { | |
| if (dimension != null) { | |
| return SizedBox.square(dimension: dimension, child: this); | |
| } | |
| return SizedBox(width: width, height: height, child: this); | |
| } | |
| // withConstraints | |
| Widget withConstraints({ | |
| double maxWidth = double.infinity, | |
| double maxHeight = double.infinity, | |
| double minWidth = 0, | |
| double minHeight = 0, | |
| }) { | |
| return ConstrainedBox( | |
| constraints: BoxConstraints( | |
| maxWidth: maxWidth, | |
| maxHeight: maxHeight, | |
| minWidth: minWidth, | |
| minHeight: minHeight, | |
| ), | |
| child: this, | |
| ); | |
| } | |
| // centered | |
| Widget get centered => Center(child: this); | |
| Widget get bottom => Align(alignment: Alignment.bottomCenter, child: this); | |
| Widget get top => Align(alignment: Alignment.topCenter, child: this); | |
| Widget get left => | |
| Align(alignment: AlignmentDirectional.centerStart, child: this); | |
| Widget get right => | |
| Align(alignment: AlignmentDirectional.centerEnd, child: this); | |
| // withAnimatedSwitcher | |
| Widget withAnimatedSwitcher({ | |
| Key? key, | |
| Duration duration = const Duration(milliseconds: 300), | |
| String? transitionType = 'opacity', | |
| Curve curve = Curves.easeInOut, | |
| }) { | |
| Widget Function(Widget, Animation<double>) getTransitionBuilder() { | |
| return switch (transitionType?.toLowerCase()) { | |
| 'scale' => (Widget child, Animation<double> animation) { | |
| return ScaleTransition(scale: animation, child: child); | |
| }, | |
| _ => (Widget child, Animation<double> animation) { | |
| return FadeTransition(opacity: animation, child: child); | |
| }, | |
| }; | |
| } | |
| return AnimatedSwitcher( | |
| key: key, | |
| duration: duration, | |
| switchInCurve: curve, | |
| switchOutCurve: curve, | |
| transitionBuilder: getTransitionBuilder(), | |
| child: this, | |
| ); | |
| } | |
| // withRounded | |
| Widget withRounded({double radius = 10}) { | |
| return ClipRRect(borderRadius: BorderRadius.circular(radius), child: this); | |
| } | |
| // withOpacity | |
| Widget withOpacity({double opacity = 1}) { | |
| return Opacity(opacity: opacity, child: this); | |
| } | |
| // withSafeArea | |
| Widget withSafeArea({ | |
| bool bottom = true, | |
| bool top = true, | |
| bool left = true, | |
| bool right = true, | |
| }) { | |
| return SafeArea( | |
| bottom: bottom, | |
| top: top, | |
| left: left, | |
| right: right, | |
| child: this, | |
| ); | |
| } | |
| // InfiniteY | |
| Widget get infiniteY { | |
| return SizedBox(height: double.infinity, child: this); | |
| } | |
| Widget get infiniteX { | |
| return SizedBox(width: double.infinity, child: this); | |
| } | |
| // Positioned.fill | |
| Widget positionFill({ | |
| double left = 0.0, | |
| double top = 0.0, | |
| double right = 0.0, | |
| double bottom = 0.0, | |
| }) { | |
| return Positioned.fill( | |
| left: left, | |
| right: right, | |
| top: top, | |
| bottom: bottom, | |
| child: this, | |
| ); | |
| } | |
| // Expanded | |
| Widget get expanded => Expanded(child: this); | |
| Widget get intrinsicWidth => IntrinsicWidth(child: this); | |
| Widget get intrinsicHeight => IntrinsicHeight(child: this); | |
| // witBorder | |
| Widget withBorder({ | |
| Color color = Colors.transparent, | |
| double width = 1, | |
| BorderStyle style = BorderStyle.solid, | |
| double radius = 30, | |
| double padding = 0, | |
| }) { | |
| return Container( | |
| padding: EdgeInsets.all(padding), | |
| decoration: BoxDecoration( | |
| borderRadius: BorderRadius.circular(radius), | |
| border: Border.all(color: color, width: 1), | |
| ), | |
| child: this, | |
| ); | |
| } | |
| Widget withShimmer({Color? baseColor, Color? highlightColor}) { | |
| return Shimmer.fromColors( | |
| baseColor: baseColor ?? Colors.grey.shade800, | |
| highlightColor: highlightColor ?? Colors.grey.shade400, | |
| child: this, | |
| ); | |
| } | |
| Widget visibile({bool visible = true}) { | |
| return Visibility(visible: visible, child: this); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment