Skip to content

Commit

Permalink
Use sealed class for DottedBorderOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ajilo297 committed Jun 19, 2024
1 parent 987d57f commit 8705661
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/dotted_border.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ class DottedBorder extends StatelessWidget {

@override
Widget build(BuildContext context) {
final radius = options is RoundedRectDottedBorderOptions
? (options as RoundedRectDottedBorderOptions).radius
: Radius.zero;
final radius = switch (options) {
RoundedRectDottedBorderOptions options => options.radius,
_ => Radius.zero,
};

final customPath = options is CustomPathDottedBorderOptions
? (options as CustomPathDottedBorderOptions).customPath
: null;
final customPath = switch (options) {
CustomPathDottedBorderOptions options => options.customPath,
_ => null,
};

return Stack(
fit: options.stackFit,
Expand Down
14 changes: 11 additions & 3 deletions lib/src/dotted_border_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import 'enums.dart';
typedef PathBuilder = Path Function(Size size);

/// Provides options for customising the dotted border.
abstract base class DottedBorderOptions {
///
/// Allowed border options:
/// - [CustomPathDottedBorderOptions]
/// - [RoundedRectDottedBorderOptions]
/// - [RectDottedBorderOptions]
/// - [CircularDottedBorderOptions]
/// - [OvalDottedBorderOptions]
sealed class DottedBorderOptions {
const DottedBorderOptions({
required this.borderType,
this.padding = const EdgeInsets.all(2),
Expand Down Expand Up @@ -38,10 +45,11 @@ abstract base class DottedBorderOptions {
/// `[1, 1]` will draw a dash and a gap of 1 unit each.
final List<double> dashPattern;

/// The stroke cap of the dotted border
/// The [strokeCap] will determine the shape of the line endings for the
/// border
final StrokeCap strokeCap;

/// The fit provided to the containing [Stack]
/// The fit provided to the parent stack
final StackFit stackFit;

/// The type of border to be drawn
Expand Down

0 comments on commit 8705661

Please sign in to comment.