hussam

feat: add useful extensions and RPadding Widget

add r Extension to EdgeInsets, BorderRadius and Radius
  1 +import 'package:flutter/material.dart';
  2 +import 'package:flutter/rendering.dart';
  3 +import 'package:flutter_screenutil/src/size_extension.dart';
  4 +
  5 +import 'size_extension.dart';
  6 +
  7 +class RPadding extends SingleChildRenderObjectWidget {
  8 + /// Creates a adapt widget that insets its child.
  9 + ///
  10 + /// The [padding] argument must not be null.
  11 + const RPadding({
  12 + Key? key,
  13 + required Widget child,
  14 + required this.padding,
  15 + }) : super(key: key, child: child);
  16 +
  17 + /// The amount of space by which to inset the child.
  18 + final EdgeInsets padding;
  19 +
  20 + @override
  21 + RenderPadding createRenderObject(BuildContext context) {
  22 + return RenderPadding(
  23 + padding: padding is REdgeInsets ? padding : padding.r,
  24 + textDirection: Directionality.maybeOf(context),
  25 + );
  26 + }
  27 +}
  28 +
  29 +class REdgeInsets extends EdgeInsets {
  30 + /// Creates adapt insets from offsets from the left, top, right, and bottom.
  31 + REdgeInsets.fromLTRB(double left, double top, double right, double bottom)
  32 + : super.fromLTRB(left.r, top.r, right.r, bottom.r);
  33 +
  34 + /// Creates adapt insets where all the offsets are `value`.
  35 + ///
  36 + /// {@tool snippet}
  37 + ///
  38 + /// Adapt height-pixel margin on all sides:
  39 + ///
  40 + /// ```dart
  41 + /// const REdgeInsets.all(8.0)
  42 + /// ```
  43 + /// {@end-tool}
  44 + REdgeInsets.all(double value) : super.all(value.r);
  45 +
  46 + /// Creates adapt insets with symmetrical vertical and horizontal offsets.
  47 + ///
  48 + /// {@tool snippet}
  49 + ///
  50 + /// Adapt Eight pixel margin above and below, no horizontal margins:
  51 + ///
  52 + /// ```dart
  53 + /// const REdgeInsets.symmetric(vertical: 8.0)
  54 + /// ```
  55 + /// {@end-tool}
  56 + REdgeInsets.symmetric({
  57 + double vertical = 0,
  58 + double horizontal = 0,
  59 + }) : super.symmetric(vertical: vertical.r, horizontal: horizontal.r);
  60 +
  61 + /// Creates adapt insets with only the given values non-zero.
  62 + ///
  63 + /// {@tool snippet}
  64 + ///
  65 + /// Adapt left margin indent of 40 pixels:
  66 + ///
  67 + /// ```dart
  68 + /// const REdgeInsets.only(left: 40.0)
  69 + /// ```
  70 + /// {@end-tool}
  71 + REdgeInsets.only({
  72 + double bottom = 0,
  73 + double right = 0,
  74 + double left = 0,
  75 + double top = 0,
  76 + }) : super.only(
  77 + bottom: bottom.r,
  78 + right: right.r,
  79 + left: left.r,
  80 + top: top.r,
  81 + );
  82 +}
@@ -48,3 +48,30 @@ extension SizeExtension on num { @@ -48,3 +48,30 @@ extension SizeExtension on num {
48 Widget get verticalSpacingRadius => 48 Widget get verticalSpacingRadius =>
49 ScreenUtil().setVerticalSpacingRadius(this); 49 ScreenUtil().setVerticalSpacingRadius(this);
50 } 50 }
  51 +
  52 +extension EdgeInsetsExtension on EdgeInsets {
  53 + /// Creates adapt insets using r [SizeExtension].
  54 + EdgeInsets get r => copyWith(
  55 + top: top.r,
  56 + bottom: bottom.r,
  57 + right: right.r,
  58 + left: left.r,
  59 + );
  60 +}
  61 +
  62 +extension BorderRaduisExtension on BorderRadius {
  63 + /// Creates adapt BorderRadius using r [SizeExtension].
  64 + BorderRadius get r => copyWith(
  65 + bottomLeft: bottomLeft.r,
  66 + bottomRight: bottomLeft.r,
  67 + topLeft: topLeft.r,
  68 + topRight: topRight.r,
  69 + );
  70 +}
  71 +
  72 +extension RaduisExtension on Radius {
  73 + /// Creates adapt Radius using r [SizeExtension].
  74 + Radius get r => this
  75 + ..x.r
  76 + ..y.r;
  77 +}