1+ import 'package:flutter/widgets.dart' ;
2+
3+ /// An enumerable class for specifying preference of indicator in [ImageCarousel] .
4+ ///
5+ /// It inherited by two classes with custom definitions of [style]
6+ /// to satisify apperences which namely [DotPageIndication]
7+ /// and [TextPageIndication] . Then, assign one of them into
8+ /// [ImageCarouselPreferences.pageIndication] .
9+ @immutable
10+ sealed class ImageCarouselPageIndication <
11+ T extends ImageCarouselPageIndicationStyle
12+ > {
13+ /// Style preference of applied indication widgets.
14+ ///
15+ /// Generic parameter [T] must be extended from [ImageCarouselPageIndicationStyle] .
16+ final T style;
17+
18+ const ImageCarouselPageIndication ._(this .style);
19+ }
20+
21+ /// Specify styles apperences for specific [ImageCarouselPageIndication] .
22+ ///
23+ /// It only comes with two nullable [Color] properties
24+ /// depending on applied preferences according to
25+ /// child classes documentations.
26+ @immutable
27+ abstract final class ImageCarouselPageIndicationStyle {
28+ /// A [Color] used for indicating activated or foreground colour.
29+ final Color ? primaryColour;
30+
31+ /// A [Color] used for indicating inactive or background colour.
32+ final Color ? secondaryColour;
33+
34+ /// Construct foundation preferences themeing for [ImageCarouselPageIndication] .
35+ const ImageCarouselPageIndicationStyle ({
36+ this .primaryColour,
37+ this .secondaryColour,
38+ });
39+ }
40+
41+ /// One of the [ImageCarouselPageIndication] preference which display pages
42+ /// indication as dot view.
43+ ///
44+ /// When it assigned into [ImageCarouselPreferences.pageIndication] ,
45+ /// the indicator which rendered at the bottom of [ImageCarousel]
46+ /// will be adopted by [PageViewDotIndicator] .
47+ final class DotPageIndication
48+ extends ImageCarouselPageIndication <DotPageIndicationStyle > {
49+ /// Specify [ImageCarousel] to render page indicator with
50+ /// [PageViewDotIndicator] with applied [style] .
51+ ///
52+ /// For applied [Color] in given [style] , [DotPageIndicationStyle.primaryColour]
53+ /// uses as [PageViewDotIndicator.selectedColor] and
54+ /// [DotPageIndicationStyle.secondaryColour] uses as [PageViewDotIndicator.unselectedColor]
55+ /// respectedly.
56+ const DotPageIndication ({
57+ DotPageIndicationStyle style = const DotPageIndicationStyle (),
58+ }) : super ._(style);
59+ }
60+
61+ /// Style preference for [DotPageIndication] which applied from
62+ /// [PageViewDotIndicator] .
63+ final class DotPageIndicationStyle extends ImageCarouselPageIndicationStyle {
64+ static const Size _DEFAULT_SIZE = Size (12 , 12 );
65+
66+ /// Set [Size] of indicator when reaching current index.
67+ ///
68+ /// Default value is `12*12` .
69+ final Size size;
70+
71+ /// Apply theme preference in [DotPageIndication] .
72+ const DotPageIndicationStyle ({
73+ super .primaryColour,
74+ super .secondaryColour,
75+ this .size = _DEFAULT_SIZE
76+ });
77+ }
78+
79+ /// One of the [ImageCarouselPageIndication] preference which display pages
80+ /// indication as dot view.
81+ ///
82+ /// When it assigned into [ImageCarouselPreferences.pageIndication] ,
83+ /// the indicator which rendered at the bottom of [ImageCarousel]
84+ /// will be adopted by [Text] which wrapped by [Container] for
85+ /// additional theme preferences.
86+ final class TextPageIndication
87+ extends ImageCarouselPageIndication <TextPageIndicationStyle > {
88+ /// Specify [ImageCarousel] to render page indicator with
89+ /// [Text] and [Container] with applied [style] .
90+ ///
91+ /// For applied [Color] in given [style] , [TextPageIndicationStyle.primaryColour]
92+ /// uses as [TextStyle.color] of the [Text] and
93+ /// [DotPageIndicationStyle.secondaryColour] uses as
94+ /// background colour of [Container] .
95+ const TextPageIndication ({
96+ TextPageIndicationStyle style = const TextPageIndicationStyle (),
97+ }) : super ._(style);
98+ }
99+
100+ /// Style preference for [TextPageIndication] which applied from
101+ /// [PageViewDotIndicator] .
102+ final class TextPageIndicationStyle extends ImageCarouselPageIndicationStyle {
103+ /// Determine size of the font.
104+ ///
105+ /// Default value is `10` .
106+ final double fontSize;
107+
108+ /// Specify weight of the font.
109+ ///
110+ /// Default value is [FontWeight.w300] .
111+ final FontWeight fontWeight;
112+
113+ /// Opacity of [Container] .
114+ ///
115+ /// If the original [Color] applied [Color.withValues] already,
116+ /// it will be overridden to [opacity] value.
117+ ///
118+ /// Default value is `0.7` .
119+ final double opacity;
120+
121+ /// Specify padding of [Text] inside the [Container] .
122+ final EdgeInsetsGeometry padding;
123+
124+ /// Apply theme preference in [TextPageIndication] .
125+ const TextPageIndicationStyle ({
126+ super .primaryColour,
127+ super .secondaryColour,
128+ this .fontSize = 10 ,
129+ this .fontWeight = FontWeight .w300,
130+ this .opacity = 0.7 ,
131+ this .padding = const EdgeInsets .symmetric (horizontal: 18 , vertical: 4 ),
132+ });
133+ }
134+
135+ /// Define preferences for visualizing [ImageCarousel] .
136+ @immutable
137+ class ImageCarouselPreferences {
138+ /// Define size of control icon for changing pages.
139+ ///
140+ /// Default value is `18` .
141+ final double controlIconSize;
142+
143+ /// Specify spaces of control buttons from nearest sides.
144+ ///
145+ /// Default defines as `5` .
146+ final double controlButtonsSpacing;
147+
148+ /// Specify [Duration] of animating page changes when event
149+ /// triggered.
150+ ///
151+ /// Default value is `500 ms` .
152+ final Duration pageChangeDuration;
153+
154+ /// Define animation behaviour during [pageChangeDuration] .
155+ ///
156+ /// By default, it uses [Curves.easeInOut] .
157+ final Curve pageChangeCurve;
158+
159+ /// Override a [Color] for displaying control icons if applied.
160+ final Color ? controlIconColour;
161+
162+ /// Set [Duration] for perform animations to show or hide
163+ /// control widgets.
164+ ///
165+ /// Default value is 250 miliseconds.
166+ final Duration showControlDuration;
167+
168+ /// Determine [Curve] of fading control widgets.
169+ ///
170+ /// Default value is [Curves.easeOutSine] .
171+ final Curve showControlCurve;
172+
173+ /// Determine visible [Duration] of control widgets if
174+ /// it triggered by tapping [ImageCarousel] area.
175+ ///
176+ /// Default value is 5 seconds.
177+ final Duration controlVisibleDuration;
178+
179+ /// Determine which widget used for displaying
180+ /// page indication.
181+ ///
182+ /// The possible value is either [DotPageIndication] (as default)
183+ /// or [TextPageIndication] .
184+ final ImageCarouselPageIndication pageIndication;
185+
186+ /// Create preference of visualizing [ImageCarousel] .
187+ const ImageCarouselPreferences ({
188+ this .controlIconSize = 18 ,
189+ this .controlButtonsSpacing = 5 ,
190+ this .pageChangeDuration = const Duration (milliseconds: 500 ),
191+ this .pageChangeCurve = Curves .easeInOut,
192+ this .showControlDuration = const Duration (milliseconds: 250 ),
193+ this .showControlCurve = Curves .easeOutSine,
194+ this .controlVisibleDuration = const Duration (seconds: 5 ),
195+ this .pageIndication = const DotPageIndication (),
196+ this .controlIconColour,
197+ });
198+ }
0 commit comments