From 87056611b3a32731804bcd3713194f2104c5ac84 Mon Sep 17 00:00:00 2001 From: Ajil Oommen Date: Wed, 19 Jun 2024 23:21:40 +0530 Subject: [PATCH] Use sealed class for DottedBorderOptions --- lib/dotted_border.dart | 14 ++++++++------ lib/src/dotted_border_options.dart | 14 +++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/dotted_border.dart b/lib/dotted_border.dart index 2a25cfb..660703b 100644 --- a/lib/dotted_border.dart +++ b/lib/dotted_border.dart @@ -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, diff --git a/lib/src/dotted_border_options.dart b/lib/src/dotted_border_options.dart index e17166f..c40f386 100644 --- a/lib/src/dotted_border_options.dart +++ b/lib/src/dotted_border_options.dart @@ -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), @@ -38,10 +45,11 @@ abstract base class DottedBorderOptions { /// `[1, 1]` will draw a dash and a gap of 1 unit each. final List 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