From 6923792568b0b15e337880c3ed989cdc45239646 Mon Sep 17 00:00:00 2001 From: Mason <124012838+ProV1X@users.noreply.github.com> Date: Sat, 29 Jun 2024 23:26:03 -0400 Subject: [PATCH 1/5] Add feature: customizable halo for prebuilt indicators --- .../indicators/circular_slide_indicator.dart | 55 +++++++++-------- .../indicators/circular_static_indicator.dart | 59 +++++++++++-------- .../circular_wave_slide_indicator.dart | 55 +++++++++-------- .../indicators/sequential_fill_indicator.dart | 59 +++++++++++-------- 4 files changed, 128 insertions(+), 100 deletions(-) diff --git a/lib/src/indicators/circular_slide_indicator.dart b/lib/src/indicators/circular_slide_indicator.dart index b259087..7cf17e5 100644 --- a/lib/src/indicators/circular_slide_indicator.dart +++ b/lib/src/indicators/circular_slide_indicator.dart @@ -3,16 +3,17 @@ import 'package:flutter/material.dart'; import 'slide_indicator.dart'; class CircularSlideIndicator implements SlideIndicator { - const CircularSlideIndicator({ - this.itemSpacing = 20, - this.indicatorRadius = 6, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - }); + const CircularSlideIndicator( + {this.itemSpacing = 20, + this.indicatorRadius = 6, + this.indicatorBorderWidth = 1, + this.indicatorBorderColor, + this.padding, + this.alignment = Alignment.bottomCenter, + this.currentIndicatorColor, + this.indicatorBackgroundColor, + this.haloDecoration, + this.haloPadding}); final AlignmentGeometry alignment; final Color? currentIndicatorColor; @@ -22,6 +23,8 @@ class CircularSlideIndicator implements SlideIndicator { final double indicatorRadius; final double itemSpacing; final EdgeInsets? padding; + final BoxDecoration? haloDecoration; + final EdgeInsets? haloPadding; @override Widget build(int currentPage, double pageDelta, int itemCount) { @@ -37,20 +40,24 @@ class CircularSlideIndicator implements SlideIndicator { return Container( alignment: alignment, padding: padding, - child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, - child: CustomPaint( - painter: CircularIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, - indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, - currentPage: currentPage, - pageDelta: pageDelta, - itemCount: itemCount, - radius: indicatorRadius, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + child: Container( + decoration: haloDecoration, + padding: haloPadding, + child: SizedBox( + width: itemCount * itemSpacing, + height: indicatorRadius * 2, + child: CustomPaint( + painter: CircularIndicatorPainter( + currentIndicatorColor: currentIndicatorColor ?? activeColor, + indicatorBackgroundColor: + indicatorBackgroundColor ?? backgroundColor, + currentPage: currentPage, + pageDelta: pageDelta, + itemCount: itemCount, + radius: indicatorRadius, + indicatorBorderColor: indicatorBorderColor, + borderWidth: indicatorBorderWidth, + ), ), ), ), diff --git a/lib/src/indicators/circular_static_indicator.dart b/lib/src/indicators/circular_static_indicator.dart index 7c57623..68b9ae1 100644 --- a/lib/src/indicators/circular_static_indicator.dart +++ b/lib/src/indicators/circular_static_indicator.dart @@ -3,17 +3,18 @@ import 'package:flutter/material.dart'; import 'slide_indicator.dart'; class CircularStaticIndicator extends SlideIndicator { - CircularStaticIndicator({ - this.itemSpacing = 20, - this.indicatorRadius = 6, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.enableAnimation = false, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - }); + CircularStaticIndicator( + {this.itemSpacing = 20, + this.indicatorRadius = 6, + this.padding, + this.alignment = Alignment.bottomCenter, + this.currentIndicatorColor, + this.indicatorBackgroundColor, + this.enableAnimation = false, + this.indicatorBorderWidth = 1, + this.indicatorBorderColor, + this.haloDecoration, + this.haloPadding}); final AlignmentGeometry alignment; final Color? currentIndicatorColor; @@ -24,6 +25,8 @@ class CircularStaticIndicator extends SlideIndicator { final double indicatorRadius; final double itemSpacing; final EdgeInsets? padding; + final BoxDecoration? haloDecoration; + final EdgeInsets? haloPadding; @override Widget build(int currentPage, double pageDelta, int itemCount) { @@ -39,21 +42,25 @@ class CircularStaticIndicator extends SlideIndicator { return Container( alignment: alignment, padding: padding, - child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, - child: CustomPaint( - painter: CircularStaticIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, - indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, - currentPage: currentPage, - pageDelta: pageDelta, - itemCount: itemCount, - radius: indicatorRadius, - enableAnimation: enableAnimation, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + child: Container( + decoration: haloDecoration, + padding: haloPadding, + child: SizedBox( + width: itemCount * itemSpacing, + height: indicatorRadius * 2, + child: CustomPaint( + painter: CircularStaticIndicatorPainter( + currentIndicatorColor: currentIndicatorColor ?? activeColor, + indicatorBackgroundColor: + indicatorBackgroundColor ?? backgroundColor, + currentPage: currentPage, + pageDelta: pageDelta, + itemCount: itemCount, + radius: indicatorRadius, + enableAnimation: enableAnimation, + indicatorBorderColor: indicatorBorderColor, + borderWidth: indicatorBorderWidth, + ), ), ), ), diff --git a/lib/src/indicators/circular_wave_slide_indicator.dart b/lib/src/indicators/circular_wave_slide_indicator.dart index 78f9abb..00817a2 100644 --- a/lib/src/indicators/circular_wave_slide_indicator.dart +++ b/lib/src/indicators/circular_wave_slide_indicator.dart @@ -3,16 +3,17 @@ import 'package:flutter/material.dart'; import 'slide_indicator.dart'; class CircularWaveSlideIndicator implements SlideIndicator { - CircularWaveSlideIndicator({ - this.itemSpacing = 20, - this.indicatorRadius = 6, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - }); + CircularWaveSlideIndicator( + {this.itemSpacing = 20, + this.indicatorRadius = 6, + this.padding, + this.alignment = Alignment.bottomCenter, + this.currentIndicatorColor, + this.indicatorBackgroundColor, + this.indicatorBorderWidth = 1, + this.indicatorBorderColor, + this.haloDecoration, + this.haloPadding}); final AlignmentGeometry alignment; final Color? currentIndicatorColor; @@ -22,6 +23,8 @@ class CircularWaveSlideIndicator implements SlideIndicator { final double indicatorRadius; final double itemSpacing; final EdgeInsets? padding; + final BoxDecoration? haloDecoration; + final EdgeInsets? haloPadding; @override Widget build(int currentPage, double pageDelta, int itemCount) { @@ -37,20 +40,24 @@ class CircularWaveSlideIndicator implements SlideIndicator { return Container( alignment: alignment, padding: padding, - child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, - child: CustomPaint( - painter: CircularWaveIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, - indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, - currentPage: currentPage, - pageDelta: pageDelta, - itemCount: itemCount, - radius: indicatorRadius, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + child: Container( + decoration: haloDecoration, + padding: haloPadding, + child: SizedBox( + width: itemCount * itemSpacing, + height: indicatorRadius * 2, + child: CustomPaint( + painter: CircularWaveIndicatorPainter( + currentIndicatorColor: currentIndicatorColor ?? activeColor, + indicatorBackgroundColor: + indicatorBackgroundColor ?? backgroundColor, + currentPage: currentPage, + pageDelta: pageDelta, + itemCount: itemCount, + radius: indicatorRadius, + indicatorBorderColor: indicatorBorderColor, + borderWidth: indicatorBorderWidth, + ), ), ), ), diff --git a/lib/src/indicators/sequential_fill_indicator.dart b/lib/src/indicators/sequential_fill_indicator.dart index e8bd12a..08ef0ad 100644 --- a/lib/src/indicators/sequential_fill_indicator.dart +++ b/lib/src/indicators/sequential_fill_indicator.dart @@ -3,17 +3,18 @@ import 'package:flutter/material.dart'; import 'slide_indicator.dart'; class SequentialFillIndicator extends SlideIndicator { - SequentialFillIndicator({ - this.itemSpacing = 20, - this.indicatorRadius = 6, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.enableAnimation = false, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - }); + SequentialFillIndicator( + {this.itemSpacing = 20, + this.indicatorRadius = 6, + this.padding, + this.alignment = Alignment.bottomCenter, + this.currentIndicatorColor, + this.indicatorBackgroundColor, + this.enableAnimation = false, + this.indicatorBorderWidth = 1, + this.indicatorBorderColor, + this.haloDecoration, + this.haloPadding}); final AlignmentGeometry alignment; final Color? currentIndicatorColor; @@ -24,6 +25,8 @@ class SequentialFillIndicator extends SlideIndicator { final double indicatorRadius; final double itemSpacing; final EdgeInsets? padding; + final BoxDecoration? haloDecoration; + final EdgeInsets? haloPadding; @override Widget build(int currentPage, double pageDelta, int itemCount) { @@ -39,21 +42,25 @@ class SequentialFillIndicator extends SlideIndicator { return Container( alignment: alignment, padding: padding, - child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, - child: CustomPaint( - painter: SequentialFillIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, - indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, - currentPage: currentPage, - pageDelta: pageDelta, - itemCount: itemCount, - radius: indicatorRadius, - enableAnimation: enableAnimation, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + child: Container( + decoration: haloDecoration, + padding: haloPadding, + child: SizedBox( + width: itemCount * itemSpacing, + height: indicatorRadius * 2, + child: CustomPaint( + painter: SequentialFillIndicatorPainter( + currentIndicatorColor: currentIndicatorColor ?? activeColor, + indicatorBackgroundColor: + indicatorBackgroundColor ?? backgroundColor, + currentPage: currentPage, + pageDelta: pageDelta, + itemCount: itemCount, + radius: indicatorRadius, + enableAnimation: enableAnimation, + indicatorBorderColor: indicatorBorderColor, + borderWidth: indicatorBorderWidth, + ), ), ), ), From 1edc580a3bc13e8a1a66ec1faae9eac793a432f4 Mon Sep 17 00:00:00 2001 From: Mason <124012838+ProV1X@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:37:51 -0400 Subject: [PATCH 2/5] Improvement: Simplified slide indicator customization with new SlideIndicatorOptions class Refactored all slide indicator properties into a new SlideIndicatorOptions class. This centralizes configuration, improving code readability, maintainability, and future extensibility. --- lib/flutter_carousel_widget.dart | 1 + .../indicators/circular_slide_indicator.dart | 59 +++----- .../indicators/circular_static_indicator.dart | 64 +++------ .../circular_wave_slide_indicator.dart | 64 +++------ .../models/slide_indicator_options_model.dart | 127 ++++++++++++++++++ .../indicators/sequential_fill_indicator.dart | 64 +++------ 6 files changed, 204 insertions(+), 175 deletions(-) create mode 100644 lib/src/indicators/models/slide_indicator_options_model.dart diff --git a/lib/flutter_carousel_widget.dart b/lib/flutter_carousel_widget.dart index f3ff8ee..73744a1 100644 --- a/lib/flutter_carousel_widget.dart +++ b/lib/flutter_carousel_widget.dart @@ -11,5 +11,6 @@ export 'package:flutter_carousel_widget/src/helpers/flutter_expandable_carousel_ export 'package:flutter_carousel_widget/src/indicators/circular_slide_indicator.dart'; export 'package:flutter_carousel_widget/src/indicators/circular_static_indicator.dart'; export 'package:flutter_carousel_widget/src/indicators/circular_wave_slide_indicator.dart'; +export 'package:flutter_carousel_widget/src/indicators/models/slide_indicator_options_model.dart'; export 'package:flutter_carousel_widget/src/indicators/sequential_fill_indicator.dart'; export 'package:flutter_carousel_widget/src/indicators/slide_indicator.dart'; diff --git a/lib/src/indicators/circular_slide_indicator.dart b/lib/src/indicators/circular_slide_indicator.dart index 7cf17e5..5de6925 100644 --- a/lib/src/indicators/circular_slide_indicator.dart +++ b/lib/src/indicators/circular_slide_indicator.dart @@ -1,62 +1,41 @@ import 'package:flutter/material.dart'; +import 'package:flutter_carousel_widget/src/indicators/models/slide_indicator_options_model.dart'; import 'slide_indicator.dart'; class CircularSlideIndicator implements SlideIndicator { const CircularSlideIndicator( - {this.itemSpacing = 20, - this.indicatorRadius = 6, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.haloDecoration, - this.haloPadding}); + {this.slideIndicatorOptions = const SlideIndicatorOptions()}); - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final Color? indicatorBackgroundColor; - final Color? indicatorBorderColor; - final double indicatorBorderWidth; - final double indicatorRadius; - final double itemSpacing; - final EdgeInsets? padding; - final BoxDecoration? haloDecoration; - final EdgeInsets? haloPadding; + final SlideIndicatorOptions slideIndicatorOptions; @override Widget build(int currentPage, double pageDelta, int itemCount) { - var activeColor = const Color(0xFFFFFFFF); - var backgroundColor = const Color(0x66FFFFFF); - - // if (SchedulerBinding.instance.window.platformBrightness == - // Brightness.light) { - // activeColor = const Color(0xFF000000); - // backgroundColor = const Color.fromARGB(255, 163, 159, 159); - // } - return Container( - alignment: alignment, - padding: padding, + alignment: slideIndicatorOptions.alignment, + padding: slideIndicatorOptions.padding, child: Container( - decoration: haloDecoration, - padding: haloPadding, + decoration: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloDecoration + : null, + padding: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloPadding + : null, child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, + width: itemCount * slideIndicatorOptions.itemSpacing, + height: slideIndicatorOptions.indicatorRadius * 2, child: CustomPaint( painter: CircularIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, + currentIndicatorColor: + slideIndicatorOptions.currentIndicatorColor, indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, + slideIndicatorOptions.indicatorBackgroundColor, currentPage: currentPage, pageDelta: pageDelta, itemCount: itemCount, - radius: indicatorRadius, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + radius: slideIndicatorOptions.indicatorRadius, + indicatorBorderColor: slideIndicatorOptions.indicatorBorderColor, + borderWidth: slideIndicatorOptions.indicatorBorderWidth, ), ), ), diff --git a/lib/src/indicators/circular_static_indicator.dart b/lib/src/indicators/circular_static_indicator.dart index 68b9ae1..1d4f579 100644 --- a/lib/src/indicators/circular_static_indicator.dart +++ b/lib/src/indicators/circular_static_indicator.dart @@ -1,65 +1,37 @@ import 'package:flutter/material.dart'; - -import 'slide_indicator.dart'; +import 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; class CircularStaticIndicator extends SlideIndicator { - CircularStaticIndicator( - {this.itemSpacing = 20, - this.indicatorRadius = 6, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.enableAnimation = false, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - this.haloDecoration, - this.haloPadding}); + CircularStaticIndicator({ + this.slideIndicatorOptions = const SlideIndicatorOptions(), + }); - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final bool enableAnimation; - final Color? indicatorBackgroundColor; - final Color? indicatorBorderColor; - final double indicatorBorderWidth; - final double indicatorRadius; - final double itemSpacing; - final EdgeInsets? padding; - final BoxDecoration? haloDecoration; - final EdgeInsets? haloPadding; + final SlideIndicatorOptions slideIndicatorOptions; @override Widget build(int currentPage, double pageDelta, int itemCount) { - var activeColor = const Color(0xFFFFFFFF); - var backgroundColor = const Color(0x66FFFFFF); - - // if (SchedulerBinding.instance.window.platformBrightness == - // Brightness.light) { - // activeColor = const Color(0xFF000000); - // backgroundColor = const Color(0xFF878484); - // } - return Container( - alignment: alignment, - padding: padding, + alignment: slideIndicatorOptions.alignment, + padding: slideIndicatorOptions.padding, child: Container( - decoration: haloDecoration, - padding: haloPadding, + decoration: slideIndicatorOptions.haloDecoration, + padding: slideIndicatorOptions.haloPadding, child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, + width: itemCount * slideIndicatorOptions.itemSpacing, + height: slideIndicatorOptions.indicatorRadius * 2, child: CustomPaint( painter: CircularStaticIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, + currentIndicatorColor: + slideIndicatorOptions.currentIndicatorColor, indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, + slideIndicatorOptions.indicatorBackgroundColor, currentPage: currentPage, pageDelta: pageDelta, itemCount: itemCount, - radius: indicatorRadius, - enableAnimation: enableAnimation, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + radius: slideIndicatorOptions.indicatorRadius, + enableAnimation: slideIndicatorOptions.enableAnimation, + indicatorBorderColor: slideIndicatorOptions.indicatorBorderColor, + borderWidth: slideIndicatorOptions.indicatorBorderWidth, ), ), ), diff --git a/lib/src/indicators/circular_wave_slide_indicator.dart b/lib/src/indicators/circular_wave_slide_indicator.dart index 00817a2..5faa2ea 100644 --- a/lib/src/indicators/circular_wave_slide_indicator.dart +++ b/lib/src/indicators/circular_wave_slide_indicator.dart @@ -1,62 +1,40 @@ import 'package:flutter/material.dart'; - -import 'slide_indicator.dart'; +import 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; class CircularWaveSlideIndicator implements SlideIndicator { - CircularWaveSlideIndicator( - {this.itemSpacing = 20, - this.indicatorRadius = 6, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - this.haloDecoration, - this.haloPadding}); + CircularWaveSlideIndicator({ + this.slideIndicatorOptions = const SlideIndicatorOptions(), + }); - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final Color? indicatorBackgroundColor; - final Color? indicatorBorderColor; - final double indicatorBorderWidth; - final double indicatorRadius; - final double itemSpacing; - final EdgeInsets? padding; - final BoxDecoration? haloDecoration; - final EdgeInsets? haloPadding; + final SlideIndicatorOptions slideIndicatorOptions; @override Widget build(int currentPage, double pageDelta, int itemCount) { - var activeColor = const Color(0xFFFFFFFF); - var backgroundColor = const Color(0x66FFFFFF); - - // if (SchedulerBinding.instance.window.platformBrightness == - // Brightness.light) { - // activeColor = const Color(0xFF000000); - // backgroundColor = const Color(0xFF878484); - // } - return Container( - alignment: alignment, - padding: padding, + alignment: slideIndicatorOptions.alignment, + padding: slideIndicatorOptions.padding, child: Container( - decoration: haloDecoration, - padding: haloPadding, + decoration: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloDecoration + : null, + padding: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloPadding + : null, child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, + width: itemCount * slideIndicatorOptions.itemSpacing, + height: slideIndicatorOptions.indicatorRadius * 2, child: CustomPaint( painter: CircularWaveIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, + currentIndicatorColor: + slideIndicatorOptions.currentIndicatorColor, indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, + slideIndicatorOptions.indicatorBackgroundColor, currentPage: currentPage, pageDelta: pageDelta, itemCount: itemCount, - radius: indicatorRadius, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + radius: slideIndicatorOptions.indicatorRadius, + indicatorBorderColor: slideIndicatorOptions.indicatorBorderColor, + borderWidth: slideIndicatorOptions.indicatorBorderWidth, ), ), ), diff --git a/lib/src/indicators/models/slide_indicator_options_model.dart b/lib/src/indicators/models/slide_indicator_options_model.dart new file mode 100644 index 0000000..0c2e1b1 --- /dev/null +++ b/lib/src/indicators/models/slide_indicator_options_model.dart @@ -0,0 +1,127 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +/// A class that holds the options for the slide indicators. +class SlideIndicatorOptions { + const SlideIndicatorOptions({ + this.alignment = Alignment.bottomCenter, + this.currentIndicatorColor = const Color(0xFFFFFFFF), + this.indicatorBackgroundColor = const Color(0x66FFFFFF), + this.indicatorBorderColor, + this.indicatorBorderWidth = 1, + this.indicatorRadius = 6, + this.itemSpacing = 20, + this.padding, + this.haloDecoration = const BoxDecoration( + color: Color(0x33000000), + borderRadius: BorderRadius.all(Radius.circular(15.0)), + ), + this.haloPadding = const EdgeInsets.all(8.0), + this.enableHalo = false, + this.enableAnimation = false, + }) : assert(indicatorRadius > 0), + assert(itemSpacing >= 0), + assert(indicatorBorderWidth >= 0); + + /// The alignment of the indicator. + final AlignmentGeometry alignment; + + /// The color of the currently active item indicator. + final Color currentIndicatorColor; + + /// The background color of all inactive item indicators. + final Color indicatorBackgroundColor; + + /// The border color of all item indicators. + final Color? indicatorBorderColor; + + /// The border width of all item indicators. + final double indicatorBorderWidth; + + /// The radius of all item indicators. + final double indicatorRadius; + + /// The spacing between each item indicator. + final double itemSpacing; + + /// The padding of the indicator. + final EdgeInsets? padding; + + /// The decoration of the indicator halo. + final BoxDecoration haloDecoration; + + /// The padding of the indicator halo. + final EdgeInsets haloPadding; + + /// Whether to enable the indicator halo. + final bool enableHalo; + + /// Whether to enable the animation. Only used in [CircularStaticIndicator] and [andSequentialFillIndicator]. + final bool enableAnimation; + + /// Returns a copy of this [SlideIndicatorOptions] but with the given fields replaced with the new values. + SlideIndicatorOptions copyWith({ + AlignmentGeometry? alignment, + Color? currentIndicatorColor, + Color? indicatorBackgroundColor, + Color? indicatorBorderColor, + double? indicatorBorderWidth, + double? indicatorRadius, + double? itemSpacing, + EdgeInsets? padding, + BoxDecoration? haloDecoration, + EdgeInsets? haloPadding, + bool? enableHalo, + }) { + return SlideIndicatorOptions( + alignment: alignment ?? this.alignment, + currentIndicatorColor: + currentIndicatorColor ?? this.currentIndicatorColor, + indicatorBackgroundColor: + indicatorBackgroundColor ?? this.indicatorBackgroundColor, + indicatorBorderColor: indicatorBorderColor ?? this.indicatorBorderColor, + indicatorBorderWidth: indicatorBorderWidth ?? this.indicatorBorderWidth, + indicatorRadius: indicatorRadius ?? this.indicatorRadius, + itemSpacing: itemSpacing ?? this.itemSpacing, + padding: padding ?? this.padding, + haloDecoration: haloDecoration ?? this.haloDecoration, + haloPadding: haloPadding ?? this.haloPadding, + enableHalo: enableHalo ?? this.enableHalo, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is SlideIndicatorOptions && + other.alignment == alignment && + other.currentIndicatorColor == currentIndicatorColor && + other.indicatorBackgroundColor == indicatorBackgroundColor && + other.indicatorBorderColor == indicatorBorderColor && + other.indicatorBorderWidth == indicatorBorderWidth && + other.indicatorRadius == indicatorRadius && + other.itemSpacing == itemSpacing && + other.padding == padding && + other.haloDecoration == haloDecoration && + other.haloPadding == haloPadding && + other.enableHalo == enableHalo; + } + + @override + int get hashCode { + return Object.hash( + alignment, + currentIndicatorColor, + indicatorBackgroundColor, + indicatorBorderColor, + indicatorBorderWidth, + indicatorRadius, + itemSpacing, + padding, + haloDecoration, + haloPadding, + enableHalo, + ); + } +} diff --git a/lib/src/indicators/sequential_fill_indicator.dart b/lib/src/indicators/sequential_fill_indicator.dart index 08ef0ad..cbfe2f0 100644 --- a/lib/src/indicators/sequential_fill_indicator.dart +++ b/lib/src/indicators/sequential_fill_indicator.dart @@ -1,65 +1,37 @@ import 'package:flutter/material.dart'; - -import 'slide_indicator.dart'; +import 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; class SequentialFillIndicator extends SlideIndicator { - SequentialFillIndicator( - {this.itemSpacing = 20, - this.indicatorRadius = 6, - this.padding, - this.alignment = Alignment.bottomCenter, - this.currentIndicatorColor, - this.indicatorBackgroundColor, - this.enableAnimation = false, - this.indicatorBorderWidth = 1, - this.indicatorBorderColor, - this.haloDecoration, - this.haloPadding}); + SequentialFillIndicator({ + this.slideIndicatorOptions = const SlideIndicatorOptions(), + }); - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final bool enableAnimation; - final Color? indicatorBackgroundColor; - final Color? indicatorBorderColor; - final double indicatorBorderWidth; - final double indicatorRadius; - final double itemSpacing; - final EdgeInsets? padding; - final BoxDecoration? haloDecoration; - final EdgeInsets? haloPadding; + final SlideIndicatorOptions slideIndicatorOptions; @override Widget build(int currentPage, double pageDelta, int itemCount) { - var activeColor = const Color(0xFFFFFFFF); - var backgroundColor = const Color(0x66FFFFFF); - - // if (SchedulerBinding.instance.window.platformBrightness == - // Brightness.light) { - // activeColor = const Color(0xFF000000); - // backgroundColor = const Color(0xFF878484); - // } - return Container( - alignment: alignment, - padding: padding, + alignment: slideIndicatorOptions.alignment, + padding: slideIndicatorOptions.padding, child: Container( - decoration: haloDecoration, - padding: haloPadding, + decoration: slideIndicatorOptions.haloDecoration, + padding: slideIndicatorOptions.haloPadding, child: SizedBox( - width: itemCount * itemSpacing, - height: indicatorRadius * 2, + width: itemCount * slideIndicatorOptions.itemSpacing, + height: slideIndicatorOptions.indicatorRadius * 2, child: CustomPaint( painter: SequentialFillIndicatorPainter( - currentIndicatorColor: currentIndicatorColor ?? activeColor, + currentIndicatorColor: + slideIndicatorOptions.currentIndicatorColor, indicatorBackgroundColor: - indicatorBackgroundColor ?? backgroundColor, + slideIndicatorOptions.indicatorBackgroundColor, currentPage: currentPage, pageDelta: pageDelta, itemCount: itemCount, - radius: indicatorRadius, - enableAnimation: enableAnimation, - indicatorBorderColor: indicatorBorderColor, - borderWidth: indicatorBorderWidth, + radius: slideIndicatorOptions.indicatorRadius, + enableAnimation: slideIndicatorOptions.enableAnimation, + indicatorBorderColor: slideIndicatorOptions.indicatorBorderColor, + borderWidth: slideIndicatorOptions.indicatorBorderWidth, ), ), ), From d33df35002fde5471eda9bc3bd5937c4104c0030 Mon Sep 17 00:00:00 2001 From: Mason <124012838+ProV1X@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:41:18 -0400 Subject: [PATCH 3/5] Update to version 2.4.0 --- CHANGELOG.md | 7 +++++++ pubspec.yaml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e8889f..9a945ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog + +## 2.4.0 + +* **Breaking Change**: All slide indicator properties have been consolidated into the `SlideIndicatorOptions` class. +* **Enhancement**: `issue #44` Added optional halo effect for slide indicators, customizable via `SlideIndicatorOptions` properties (`enableHalo`, `haloPadding`, `haloDecoration`). +* **Chore**: Removed dead code. + ## 2.2.0 * **New Feature**: Support for custom slide indicators added. diff --git a/pubspec.yaml b/pubspec.yaml index b5c561f..eaa96d3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_carousel_widget description: A customizable carousel slider widget for Flutter, offering features such as infinite scrolling, auto-scrolling, custom child widgets, custom animations, pre-built indicators, expandable carousel widgets, and auto-sized child support. -version: 2.3.0 +version: 2.4.0 homepage: https://pub.dev/packages/flutter_carousel_widget repository: https://github.com/nixrajput/flutter_carousel_widget From ffe0b65c2bf0dda0f2ab5c2acc372bcc9d49d73e Mon Sep 17 00:00:00 2001 From: Mason <124012838+ProV1X@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:46:31 -0400 Subject: [PATCH 4/5] Fix indicators not respecting slideIndicatorOptions.enableHalo --- lib/src/indicators/circular_static_indicator.dart | 8 ++++++-- lib/src/indicators/sequential_fill_indicator.dart | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/indicators/circular_static_indicator.dart b/lib/src/indicators/circular_static_indicator.dart index 1d4f579..ec86cd5 100644 --- a/lib/src/indicators/circular_static_indicator.dart +++ b/lib/src/indicators/circular_static_indicator.dart @@ -14,8 +14,12 @@ class CircularStaticIndicator extends SlideIndicator { alignment: slideIndicatorOptions.alignment, padding: slideIndicatorOptions.padding, child: Container( - decoration: slideIndicatorOptions.haloDecoration, - padding: slideIndicatorOptions.haloPadding, + decoration: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloDecoration + : null, + padding: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloPadding + : null, child: SizedBox( width: itemCount * slideIndicatorOptions.itemSpacing, height: slideIndicatorOptions.indicatorRadius * 2, diff --git a/lib/src/indicators/sequential_fill_indicator.dart b/lib/src/indicators/sequential_fill_indicator.dart index cbfe2f0..27fe21e 100644 --- a/lib/src/indicators/sequential_fill_indicator.dart +++ b/lib/src/indicators/sequential_fill_indicator.dart @@ -14,8 +14,12 @@ class SequentialFillIndicator extends SlideIndicator { alignment: slideIndicatorOptions.alignment, padding: slideIndicatorOptions.padding, child: Container( - decoration: slideIndicatorOptions.haloDecoration, - padding: slideIndicatorOptions.haloPadding, + decoration: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloDecoration + : null, + padding: slideIndicatorOptions.enableHalo + ? slideIndicatorOptions.haloPadding + : null, child: SizedBox( width: itemCount * slideIndicatorOptions.itemSpacing, height: slideIndicatorOptions.indicatorRadius * 2, From 0fdce7e459fc3f92f168e04a60cabf8e72b87166 Mon Sep 17 00:00:00 2001 From: Mason <124012838+ProV1X@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:44:58 -0400 Subject: [PATCH 5/5] Fixed typo --- lib/src/indicators/models/slide_indicator_options_model.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/indicators/models/slide_indicator_options_model.dart b/lib/src/indicators/models/slide_indicator_options_model.dart index 0c2e1b1..59a0b58 100644 --- a/lib/src/indicators/models/slide_indicator_options_model.dart +++ b/lib/src/indicators/models/slide_indicator_options_model.dart @@ -56,7 +56,7 @@ class SlideIndicatorOptions { /// Whether to enable the indicator halo. final bool enableHalo; - /// Whether to enable the animation. Only used in [CircularStaticIndicator] and [andSequentialFillIndicator]. + /// Whether to enable the animation. Only used in [CircularStaticIndicator] and [SequentialFillIndicator]. final bool enableAnimation; /// Returns a copy of this [SlideIndicatorOptions] but with the given fields replaced with the new values.