Skip to content

Commit

Permalink
Updated utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Feb 2, 2024
1 parent 7e8287d commit aa4962a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
61 changes: 40 additions & 21 deletions lib/src/attributes/border/border_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ class BorderSideUtility<T extends StyleAttribute>
BorderStyle? style,
double? strokeAlign,
}) {
return builder(BorderSideDto(
color: color,
strokeAlign: strokeAlign,
style: style,
width: width,
));
return builder(
BorderSideDto(
color: color,
strokeAlign: strokeAlign,
style: style,
width: width,
),
);
}

/// Returns a [ColorUtility] to manipulate [Color] of the [BorderSideDto]
Expand All @@ -52,12 +54,16 @@ class BorderSideUtility<T extends StyleAttribute>
BorderStyleUtility<T> get style =>
BorderStyleUtility((style) => _only(style: style));

T as(BorderSide side) => builder(BorderSideDto.from(side));

/// Sets the width of the [BorderSideDto]
T width(double width) => call(width: width);

/// Sets the stroke align of the [BorderSideDto]
T strokeAlign(double strokeAlign) => call(strokeAlign: strokeAlign);

T none() => as(BorderSide.none);

/// Creates a [BorderSideDto] with the provided parameters and calls the [builder] function.
T call({
Color? color,
Expand All @@ -80,6 +86,7 @@ class BorderUtility<T extends StyleAttribute>
extends DtoUtility<T, BoxBorderDto, BoxBorder> {
/// Constructor for creating an instance of the class.
const BorderUtility(super.builder) : super(valueToDto: BoxBorderDto.from);

BoxBorderDto _symmetric({
BorderSideDto? vertical,
BorderSideDto? horizontal,
Expand All @@ -96,17 +103,6 @@ class BorderUtility<T extends StyleAttribute>
return BoxBorderDto(top: side, bottom: side, left: side, right: side);
}

T _only({
BorderSideDto? top,
BorderSideDto? bottom,
BorderSideDto? left,
BorderSideDto? right,
}) {
return builder(
BoxBorderDto(top: top, bottom: bottom, left: left, right: right),
);
}

BorderDirectionalUtility<T> get _directional =>
BorderDirectionalUtility((border) => builder(border));

Expand All @@ -123,22 +119,22 @@ class BorderUtility<T extends StyleAttribute>

/// Method to set the border on the bottom side.
BorderSideUtility<T> get bottom {
return BorderSideUtility((side) => _only(bottom: side));
return BorderSideUtility((side) => only(bottom: side));
}

/// Method to set the border on the top side.
BorderSideUtility<T> get top {
return BorderSideUtility((side) => _only(top: side));
return BorderSideUtility((side) => only(top: side));
}

/// Method to set the border on the left side.
BorderSideUtility<T> get left {
return BorderSideUtility((side) => _only(left: side));
return BorderSideUtility((side) => only(left: side));
}

/// Method to set the border on the right side.
BorderSideUtility<T> get right {
return BorderSideUtility((side) => _only(right: side));
return BorderSideUtility((side) => only(right: side));
}

/// Method to set the borders on the vertical sides.
Expand All @@ -153,6 +149,29 @@ class BorderUtility<T extends StyleAttribute>
);
}

/// Returns a [ColorUtility] to manipulate [Color] of the [BorderSideDto]
ColorUtility<T> get color => all.color;

BorderStyleUtility<T> get style => all.style;

T width(double width) => all.width(width);

T strokeAlign(double strokeAlign) => all.strokeAlign(strokeAlign);

T none() => all.none();

/// Method to set the border individually on each side.
T only({
BorderSideDto? top,
BorderSideDto? bottom,
BorderSideDto? left,
BorderSideDto? right,
}) {
return builder(
BoxBorderDto(top: top, bottom: bottom, left: left, right: right),
);
}

/// Creates a [BoxBorderDto] with the provided parameters and calls the [builder] function.
T call({
Color? color,
Expand Down
26 changes: 13 additions & 13 deletions lib/src/attributes/color/color_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ class ColorUtility<T extends StyleAttribute>
T _directive(ColorDirective directive) =>
builder(ColorDto.directive(directive));

T withOpacity(double opacity) => _directive(OpacityColorDirective(opacity));
T withAlpha(int alpha) => _directive(AlphaColorDirective(alpha));
T darken(int percentage) => _directive(DarkenColorDirective(percentage));
T lighten(int percentage) => _directive(LightenColorDirective(percentage));
T saturate(int percentage) => _directive(SaturateColorDirective(percentage));
T desaturate(int percentage) =>
_directive(DesaturateColorDirective(percentage));
T tint(int percentage) => _directive(TintColorDirective(percentage));
T shade(int percentage) => _directive(ShadeColorDirective(percentage));
T brighten(int percentage) => _directive(BrightenColorDirective(percentage));

T of(ColorToken ref) => _buildColor(ref());

MaterialColorUtility<T> get red => MaterialColorUtility(builder, Colors.red);
MaterialColorUtility<T> get pink =>
MaterialColorUtility(builder, Colors.pink);
Expand Down Expand Up @@ -101,6 +88,19 @@ class ColorUtility<T extends StyleAttribute>
MaterialAccentColorUtility(builder, Colors.orangeAccent);
MaterialAccentColorUtility<T> get deepOrangeAccent =>
MaterialAccentColorUtility(builder, Colors.deepOrangeAccent);
T withOpacity(double opacity) => _directive(OpacityColorDirective(opacity));
T withAlpha(int alpha) => _directive(AlphaColorDirective(alpha));
T darken(int percentage) => _directive(DarkenColorDirective(percentage));
T lighten(int percentage) => _directive(LightenColorDirective(percentage));
T saturate(int percentage) => _directive(SaturateColorDirective(percentage));
T desaturate(int percentage) =>
_directive(DesaturateColorDirective(percentage));
T tint(int percentage) => _directive(TintColorDirective(percentage));
T shade(int percentage) => _directive(ShadeColorDirective(percentage));
T brighten(int percentage) => _directive(BrightenColorDirective(percentage));

T of(ColorToken ref) => _buildColor(ref());

T transparent() => _buildColor(Colors.transparent);
T black() => _buildColor(const Color(0xFF000000));
T black87() => _buildColor(const Color(0xDD000000));
Expand Down

0 comments on commit aa4962a

Please sign in to comment.