Spacing class
A utility class for creating consistent spacing throughout your Flutter app.
It provides predefined spacing options for both vertical and horizontal spacing, including extra small (xs), small, medium, large, and extra large (xl) sizes.
You can create spacing in all directions or specify spacing only vertically or horizontally using the appropriate named constructors.
Example usage:
Spacing.small() // Creates small spacing in both vertical and horizontal directions.
Spacing.mediumVertical() // Creates medium spacing only in the vertical direction.
Spacing.xlHorizontal() // Creates extra large spacing only in the horizontal direction.
Modifying Spacing Values
If you need to adjust the predefined spacing values, you can modify the static properties directly:
Spacing.smallSpacing = 12; // Changes the small spacing to 12 pixels.
Spacing.largeSpacing = 30; // Changes the large spacing to 30 pixels.
This class makes it easier to maintain consistent spacing throughout the UI without manually specifying the width and height each time.
- Inheritance
- Available extensions
Constructors
- Spacing.large({Key? key})
- Both vertical and horizontal largeSpacing
- Spacing.largeHorizontal({Key? key})
- Horizontal largeSpacing
- Spacing.largeVertical({Key? key})
- Vertical largeSpacing
- Spacing.medium({Key? key})
- Both vertical and horizontal mediumSpacing
- Spacing.mediumHorizontal({Key? key})
- Horizontal mediumSpacing
- Spacing.mediumVertical({Key? key})
- Vertical mediumSpacing
- Spacing.small({Key? key})
- Both vertical and horizontal smallSpacing
- Spacing.smallHorizontal({Key? key})
- Horizontal smallSpacing
- Spacing.smallVertical({Key? key})
- Vertical smallSpacing
- Spacing.xl({Key? key})
- Both vertical and horizontal xlSpacing
- Spacing.xlHorizontal({Key? key})
- Horizontal xlSpacing
- Spacing.xlVertical({Key? key})
- Vertical xlSpacing
- Spacing.xs({Key? key})
- Both vertical and horizontal xsSpacing
- Spacing.xsHorizontal({Key? key})
- Horizontal xsSpacing
- Spacing.xsVertical({Key? key})
- Vertical xsSpacing
Properties
- child → Widget?
-
The widget below this widget in the tree.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
If non-null, requires the child to have exactly this height.
finalinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sliver → Widget
-
Available on Widget, provided by the WidgetSliver extension
no setter - width → double?
-
If non-null, requires the child to have exactly this width.
finalinherited
Methods
-
alignAtBottomCenter(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtBottomLeft(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtBottomRight(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtCenter(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtCenterLeft(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtCenterRight(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtLERP(
Alignment a, Alignment b, double t, {Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtTopCenter(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtTopLeft(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignAtTopRight(
{Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
alignXY(
double x, double y, {Key? key, double? heightFactor, double? widthFactor}) → Align -
Available on Widget, provided by the AlignExtensions extension
-
animate(
{Key? key, List< Effect> ? effects, AnimateCallback? onInit, AnimateCallback? onPlay, AnimateCallback? onComplete, bool? autoPlay, Duration? delay, AnimationController? controller, Adapter? adapter, double? target, double? value}) → Animate -
Available on Widget, provided by the AnimateWidgetExtensions extension
Wraps the target Widget in an Animate instance, and returns the instance for chaining calls. Ex.myWidget.animate()
is equivalent toAnimate(child: myWidget)
. -
applyShimmer(
{bool enable = true, Color? baseColor, Color? highlightColor}) → Widget -
Available on Widget, provided by the ShimmerEffect extension
-
applyShimmerThemed(
BuildContext context) → Widget - Adds themed shimmer animation to a widget.
-
bottom(
) → Widget - Aligns this widget to the bottom.
-
center(
) → Widget - Aligns this widget to the top.
-
createElement(
) → SingleChildRenderObjectElement -
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
inherited
-
createRenderObject(
BuildContext context) → RenderConstrainedBox -
Creates an instance of the RenderObject class that this
RenderObjectWidget represents, using the configuration described by this
RenderObjectWidget.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
didUnmountRenderObject(
covariant RenderObject renderObject) → void -
A render object previously associated with this widget has been removed
from the tree. The given RenderObject will be of the same type as
returned by this object's createRenderObject.
inherited
-
expanded(
{int flex = 1}) → Expanded -
Available on Widget, provided by the ExpandedExtension extension
-
flexible(
{int flex = 1}) → Flexible -
Available on Widget, provided by the FlexibleExtension extension
-
left(
) → Widget - Aligns this widget to the left.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDoubleTap(
dynamic function()) → Widget -
Available on Widget, provided by the GestureDetectorExtensions extension
-
onLongPress(
dynamic function()) → Widget -
Available on Widget, provided by the GestureDetectorExtensions extension
-
onTap(
dynamic function()) → Widget -
Available on Widget, provided by the GestureDetectorExtensions extension
-
paddingAll(
double value, {Key? key}) → Padding -
paddingFromViewPadding(
ViewPadding padding, double devicePixelRatio, {Key? key}) → Padding -
paddingLTRB(
double left, double top, double right, double bottom, {Key? key}) → Padding -
paddingOnly(
{double left = 0.0, double top = 0.0, double right = 0.0, double bottom = 0.0, Key? key}) → Padding -
paddingSTEB(
double start, double top, double end, double bottom, {Key? key}) → Padding -
paddingSymmetric(
{double vertical = 0.0, double horizontal = 0.0, Key? key}) → Padding -
positionBottom(
{Key? key, required double bottom, double? width, double? height}) → Positioned -
Available on Widget, provided by the PositionedExtensions extension
-
positionLR(
{Key? key, required double left, required double right, double? width, double? height}) → Positioned -
Available on Widget, provided by the PositionedExtensions extension
-
positionLRTB(
{Key? key, required double top, required double bottom, required double left, required double right, double? width, double? height}) → Positioned -
Available on Widget, provided by the PositionedExtensions extension
-
positionTB(
{Key? key, required double top, required double bottom, double? width, double? height}) → Positioned -
Available on Widget, provided by the PositionedExtensions extension
-
positionTop(
{Key? key, required double top, double? width, double? height}) → Positioned -
Available on Widget, provided by the PositionedExtensions extension
-
right(
) → Widget - Aligns this widget to the right.
-
setOpacity(
{required double opacity}) → Opacity -
Available on Widget, provided by the OpacityExtension extension
-
show(
AnimationStagger? stagger, {Duration duration = const Duration(milliseconds: 500), Duration delay = Duration.zero}) → Animate - Plays the default show animation for a route widget.
-
showIf(
bool condition) → Widget? -
Available on Widget, provided by the WidgetCommonExtension extension
-
stretch(
[EdgeInsets? padding]) → Widget -
Available on Widget, provided by the WidgetExt extension
Stretches this widget to fill the available horizontal space. Optionally, you can providepadding
to the stretched widget. -
toCenter(
) → Center -
Available on Widget, provided by the CenterExtension extension
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
top(
) → Widget - Aligns this widget to the top.
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
-
updateRenderObject(
BuildContext context, covariant RenderConstrainedBox renderObject) → void -
Copies the configuration described by this RenderObjectWidget to the
given RenderObject, which will be of the same type as returned by this
object's createRenderObject.
inherited
-
withTooltip(
String message, {Decoration? decoration, double? height, bool? preferBelow, EdgeInsetsGeometry? padding, TextStyle? textStyle, Duration? waitDuration, EdgeInsetsGeometry? margin}) → Widget -
Available on Widget, provided by the WidgetsExtension extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- largeSpacing ↔ double
-
Value for large spacing.
getter/setter pair
- mediumSpacing ↔ double
-
Value for medium spacing.
getter/setter pair
- smallSpacing ↔ double
-
Value for small spacing.
getter/setter pair
- xlSpacing ↔ double
-
Value for extra large spacing.
getter/setter pair
- xsSpacing ↔ double
-
Value for extra small spacing.
getter/setter pair