Skip to content

Commit

Permalink
create custom border
Browse files Browse the repository at this point in the history
This reverts commit 6efcf34.

create custom_border

extendable border

fix border
  • Loading branch information
tilucasoli committed Sep 23, 2024
1 parent 8f064be commit 571d46b
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions packages/mix/lib/src/attributes/border/shape_border_dto.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ignore_for_file: prefer_relative_imports, avoid-importing-entrypoint-exports

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

Check notice on line 4 in packages/mix/lib/src/attributes/border/shape_border_dto.dart

View workflow job for this annotation

GitHub Actions / Test Min SDK

The import of 'package:flutter/rendering.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/material.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unnecessary_import to learn more about this problem.

Check notice on line 4 in packages/mix/lib/src/attributes/border/shape_border_dto.dart

View workflow job for this annotation

GitHub Actions / Test

The import of 'package:flutter/rendering.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/material.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unnecessary_import to learn more about this problem.
import 'package:flutter/widgets.dart';
import 'package:mix/mix.dart';
import 'package:mix_annotations/mix_annotations.dart';
Expand Down Expand Up @@ -30,7 +32,7 @@ sealed class ShapeBorderDto<T extends ShapeBorder> extends Dto<T> {
return dto is OutlinedBorderDto
? (
side: dto.side,
borderRadius: dto._borderRadius,
borderRadius: dto.borderRadiusGetter,
boxShape: dto._toBoxShape(),
)
: (side: null, borderRadius: null, boxShape: null);
Expand All @@ -54,7 +56,7 @@ sealed class ShapeBorderDto<T extends ShapeBorder> extends Dto<T> {
}

@immutable
sealed class OutlinedBorderDto<T extends OutlinedBorder>
abstract class OutlinedBorderDto<T extends OutlinedBorder>
extends ShapeBorderDto<T> {
final BorderSideDto? side;

Expand All @@ -75,13 +77,14 @@ sealed class OutlinedBorderDto<T extends OutlinedBorder>
if (a.runtimeType == b.runtimeType) return a.merge(b) as B;

return switch (b) {
(BeveledRectangleBorderDto g) => a.toBeveled().merge(g) as B,
(RoundedRectangleBorderDto g) => a.toRoundedRectangle().merge(g) as B,
(ContinuousRectangleBorderDto g) => a.toContinuous().merge(g) as B,
(CircleBorderDto g) => a.toCircle().merge(g) as B,
(StadiumBorderDto g) => a.toStadiumBorder().merge(g) as B,
(StarBorderDto g) => a.toStar().merge(g) as B,
(LinearBorderDto g) => a.toLinear().merge(g) as B,
(BeveledRectangleBorderDto b) => a.toBeveled().merge(b) as B,
(RoundedRectangleBorderDto b) => a.toRoundedRectangle().merge(b) as B,
(ContinuousRectangleBorderDto b) => a.toContinuous().merge(b) as B,
(CircleBorderDto b) => a.toCircle().merge(b) as B,
(StadiumBorderDto b) => a.toStadiumBorder().merge(b) as B,
(StarBorderDto b) => a.toStar().merge(b) as B,
(LinearBorderDto b) => a.toLinear().merge(b) as B,
(OutlinedBorderDto b) => a.merge(b) as B,
};
}

Expand All @@ -95,7 +98,7 @@ sealed class OutlinedBorderDto<T extends OutlinedBorder>
return null;
}

BorderRadiusGeometryDto? get _borderRadius;
BorderRadiusGeometryDto? get borderRadiusGetter;

/// Tries to get borderRadius if available for [OutlineBorderDto]
Expand All @@ -106,15 +109,15 @@ sealed class OutlinedBorderDto<T extends OutlinedBorder>
}

return BeveledRectangleBorderDto(
borderRadius: _borderRadius,
borderRadius: borderRadiusGetter,
side: _side,
);
}

@override
ContinuousRectangleBorderDto toContinuous() {
return ContinuousRectangleBorderDto(
borderRadius: _borderRadius,
borderRadius: borderRadiusGetter,
side: _side,
);
}
Expand All @@ -126,7 +129,7 @@ sealed class OutlinedBorderDto<T extends OutlinedBorder>
}

return RoundedRectangleBorderDto(
borderRadius: _borderRadius,
borderRadius: borderRadiusGetter,
side: _side,
);
}
Expand Down Expand Up @@ -172,9 +175,12 @@ final class RoundedRectangleBorderDto
with _$RoundedRectangleBorderDto {
@MixableProperty(dto: MixableFieldDto(type: BorderRadiusGeometryDto))
final BorderRadiusGeometryDto? borderRadius;

const RoundedRectangleBorderDto({this.borderRadius, super.side});

@override
BorderRadiusGeometryDto? get _borderRadius => borderRadius;
BorderRadiusGeometryDto? get borderRadiusGetter => borderRadius;

@override
RoundedRectangleBorder get defaultValue => const RoundedRectangleBorder();
}
Expand All @@ -184,9 +190,12 @@ final class BeveledRectangleBorderDto
extends OutlinedBorderDto<BeveledRectangleBorder>
with _$BeveledRectangleBorderDto {
final BorderRadiusGeometryDto? borderRadius;

const BeveledRectangleBorderDto({this.borderRadius, super.side});

@override
BorderRadiusGeometryDto? get _borderRadius => borderRadius;
BorderRadiusGeometryDto? get borderRadiusGetter => borderRadius;

@override
BeveledRectangleBorder get defaultValue => const BeveledRectangleBorder();
}
Expand All @@ -196,10 +205,11 @@ final class ContinuousRectangleBorderDto
extends OutlinedBorderDto<ContinuousRectangleBorder>
with _$ContinuousRectangleBorderDto {
final BorderRadiusGeometryDto? borderRadius;

const ContinuousRectangleBorderDto({this.borderRadius, super.side});

@override
BorderRadiusGeometryDto? get _borderRadius => borderRadius;
BorderRadiusGeometryDto? get borderRadiusGetter => borderRadius;
@override
ContinuousRectangleBorder get defaultValue =>
const ContinuousRectangleBorder();
Expand All @@ -212,7 +222,7 @@ final class CircleBorderDto extends OutlinedBorderDto<CircleBorder>

const CircleBorderDto({super.side, this.eccentricity});
@override
BorderRadiusGeometryDto? get _borderRadius => null;
BorderRadiusGeometryDto? get borderRadiusGetter => null;
@override
CircleBorder get defaultValue => const CircleBorder();
}
Expand All @@ -237,7 +247,7 @@ final class StarBorderDto extends OutlinedBorderDto<StarBorder>
this.squash,
});
@override
BorderRadiusGeometryDto? get _borderRadius => null;
BorderRadiusGeometryDto? get borderRadiusGetter => null;
@override
StarBorder get defaultValue => const StarBorder();
}
Expand All @@ -258,7 +268,7 @@ final class LinearBorderDto extends OutlinedBorderDto<LinearBorder>
this.bottom,
});
@override
BorderRadiusGeometryDto? get _borderRadius => null;
BorderRadiusGeometryDto? get borderRadiusGetter => null;
@override
LinearBorder get defaultValue => const LinearBorder();
}
Expand All @@ -281,11 +291,17 @@ final class StadiumBorderDto extends OutlinedBorderDto<StadiumBorder>
const StadiumBorderDto({super.side});

@override
BorderRadiusGeometryDto? get _borderRadius => null;
BorderRadiusGeometryDto? get borderRadiusGetter => null;
@override
StadiumBorder get defaultValue => const StadiumBorder();
}

abstract class CustomOutlinedBorder<T extends OutlinedBorderDto>
extends OutlinedBorder {
const CustomOutlinedBorder({super.side = BorderSide.none});
T toDto();
}

extension ShapeBorderExt on ShapeBorder {
ShapeBorderDto toDto() {
final self = this;
Expand All @@ -296,6 +312,7 @@ extension ShapeBorderExt on ShapeBorder {
if (self is RoundedRectangleBorder) return (self).toDto();
if (self is StadiumBorder) return (self).toDto();
if (self is StarBorder) return (self).toDto();
if (self is CustomOutlinedBorder) return (self).toDto();

throw ArgumentError.value(
this,
Expand All @@ -305,7 +322,7 @@ extension ShapeBorderExt on ShapeBorder {
}
}

final class ShapeBorderUtility<T extends Attribute>
class ShapeBorderUtility<T extends Attribute>
extends MixUtility<T, ShapeBorderDto> {
late final beveledRectangle = BeveledRectangleBorderUtility(builder);

Expand All @@ -322,4 +339,6 @@ final class ShapeBorderUtility<T extends Attribute>
late final star = StarBorderUtility(builder);

ShapeBorderUtility(super.builder);

T call(OutlinedBorder value) => builder(value.toDto());
}

0 comments on commit 571d46b

Please sign in to comment.