Skip to content

Commit 135c8f0

Browse files
authored
Merge pull request #49 from ProV1X/feature/slide-indicator-halo
Docs & Example: Slide Indicator Halo - Implementation & Usage Guide
2 parents e13b01f + bec6cdb commit 135c8f0

File tree

2 files changed

+159
-3
lines changed

2 files changed

+159
-3
lines changed

README.md

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,66 @@ Jump to the given page.
276276

277277
Animate to the given page.
278278

279-
## Custom Slide Indicators
280279

281-
The `flutter_carousel_widget` package comes with a few [predefined slide indicators](https://github.com/nixrajput/flutter_carousel_widget/tree/master/lib/src/indicators) with their own unique behaviors. This helps drastically and brings focus towards the actual implementation of your carousel widget.
280+
## Predefined Slide Indicators
281+
282+
The `flutter_carousel_widget` package comes with a few [predefined slide indicators](https://github.com/nixrajput/flutter_carousel_widget/tree/master/lib/src/indicators) each with its own distinct behavior. To customize the slide indicators, you can pass an instance of `SlideIndicatorOptions` to the indicator you're using.
283+
284+
### Slide Indicator Options Customization
285+
286+
``` dart
287+
FlutterCarousel(
288+
...
289+
options: CarouselOptions(
290+
...
291+
slideIndicator: CircularSlideIndicator(
292+
slideIndicatorOptions: SlideIndicatorOptions(
293+
/// The alignment of the indicator.
294+
alignment: Alignment.bottomCenter,
295+
296+
/// The color of the currently active item indicator.
297+
currentIndicatorColor: Colors.white,
298+
299+
/// The background color of all inactive item indicators.
300+
indicatorBackgroundColor: Colors.white.withOpacity(0.5),
301+
302+
/// The border color of all item indicators.
303+
indicatorBorderColor: Colors.white,
304+
305+
/// The border width of all item indicators.
306+
indicatorBorderWidth: 1,
307+
308+
/// The radius of all item indicators.
309+
indicatorRadius: 6,
310+
311+
/// The spacing between each item indicator.
312+
itemSpacing: 20,
313+
314+
/// The padding of the indicator.
315+
padding: const EdgeInsets.all(8.0),
316+
317+
/// The decoration of the indicator halo.
318+
haloDecoration: BoxDecoration(
319+
borderRadius: const BorderRadius.all(Radius.circular(15.0)),
320+
color: Colors.black.withOpacity(0.5)),
321+
322+
/// The padding of the indicator halo.
323+
haloPadding: const EdgeInsets.all(8.0),
324+
325+
/// Whether to enable the indicator halo.
326+
enableHalo: true,
327+
328+
/// Whether to enable the animation. Only used in [CircularStaticIndicator] and [SequentialFillIndicator].
329+
enableAnimation: true),
330+
),
331+
332+
),
333+
);
334+
```
335+
336+
## Custom Slide Indicators
282337

283-
However, there might be cases where you want to control the look or behavior of the slide indicator or implement a totally new one. You can do that by implementing the `SlideIndicator` contract.
338+
There might be cases where you want to control the look or behavior of the slide indicator or implement a totally new one. You can do that by implementing the `SlideIndicator` contract.
284339

285340
The following example implements an indicator which tells the percentage of the slide the user is on:
286341

example/lib/main.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class FlutterCarouselWidgetDemo extends StatelessWidget {
6969
'/enlarge': (ctx) => const EnlargeStrategyDemo(),
7070
'/manual': (ctx) => const ManuallyControlledSlider(),
7171
'/fullscreen': (ctx) => const FullscreenSliderDemo(),
72+
'/indicator_halo': (ctx) => const CarouselWithIndicatorHalo(),
7273
'/indicator': (ctx) => const CarouselWithIndicatorDemo(),
7374
'/multiple': (ctx) => const MultipleItemDemo(),
7475
'/expandable': (ctx) => const ExpandableCarouselDemo(),
@@ -154,6 +155,7 @@ class CarouselDemoHome extends StatelessWidget {
154155
DemoItem('Enlarge Strategy Demo', '/enlarge'),
155156
DemoItem('Manually Controlled Slider', '/manual'),
156157
DemoItem('Fullscreen Carousel Slider', '/fullscreen'),
158+
DemoItem('Carousel with Indicator Halo', '/indicator_halo'),
157159
DemoItem('Carousel with Custom Indicator Demo', '/indicator'),
158160
DemoItem('Multiple Item in One Screen Demo', '/multiple'),
159161
DemoItem('Expandable Carousel Demo', '/expandable'),
@@ -405,6 +407,105 @@ class FullscreenSliderDemo extends StatelessWidget {
405407
}
406408
}
407409

410+
class CarouselWithIndicatorHalo extends StatefulWidget {
411+
const CarouselWithIndicatorHalo({Key? key}) : super(key: key);
412+
413+
@override
414+
State<CarouselWithIndicatorHalo> createState() =>
415+
_CarouselWithIndicatorHaloState();
416+
}
417+
418+
class _CarouselWithIndicatorHaloState extends State<CarouselWithIndicatorHalo> {
419+
bool useCustomIndicatorOptions = false;
420+
421+
SlideIndicatorOptions defaultOptions = const SlideIndicatorOptions(
422+
enableHalo: true,
423+
);
424+
425+
SlideIndicatorOptions customOptions = const SlideIndicatorOptions(
426+
enableHalo: true,
427+
currentIndicatorColor: Colors.white,
428+
haloDecoration: BoxDecoration(
429+
gradient: LinearGradient(
430+
colors: [
431+
Color(0xFF9B2BFF),
432+
Color(0xFF2BFF88),
433+
],
434+
begin: Alignment.topLeft,
435+
end: Alignment.bottomRight,
436+
),
437+
borderRadius: BorderRadius.all(Radius.circular(15.0)),
438+
),
439+
);
440+
441+
@override
442+
Widget build(BuildContext context) {
443+
final deviceSize = MediaQuery.of(context).size;
444+
445+
return Scaffold(
446+
appBar: AppBar(title: const Text('Carousel with Indicator Halo')),
447+
body: Center(
448+
child: Padding(
449+
padding: const EdgeInsets.all(8.0),
450+
child: Column(
451+
children: [
452+
const Spacer(
453+
flex: 1,
454+
),
455+
Row(
456+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
457+
children: <Widget>[
458+
ElevatedButton(
459+
onPressed: () {
460+
setState(() {
461+
useCustomIndicatorOptions = false;
462+
});
463+
},
464+
child: const Text("Default Halo")),
465+
ElevatedButton(
466+
onPressed: () {
467+
setState(() {
468+
useCustomIndicatorOptions = true;
469+
});
470+
},
471+
child: const Text("Custom Halo")),
472+
],
473+
),
474+
const SizedBox(height: 20),
475+
Container(
476+
constraints: BoxConstraints(
477+
maxHeight: MediaQuery.of(context).size.width,
478+
),
479+
child: FlutterCarousel(
480+
options: CarouselOptions(
481+
autoPlay: true,
482+
autoPlayInterval: const Duration(seconds: 3),
483+
disableCenter: true,
484+
viewportFraction: deviceSize.width > 800.0 ? 0.8 : 1.0,
485+
height: deviceSize.height * 0.45,
486+
indicatorMargin: 12.0,
487+
enableInfiniteScroll: true,
488+
slideIndicator: CircularSlideIndicator(
489+
slideIndicatorOptions: useCustomIndicatorOptions
490+
? customOptions
491+
: defaultOptions,
492+
),
493+
initialPage: 2,
494+
),
495+
items: sliders,
496+
),
497+
),
498+
const Spacer(
499+
flex: 5,
500+
)
501+
],
502+
),
503+
),
504+
),
505+
);
506+
}
507+
}
508+
408509
class CarouselWithIndicatorDemo extends StatefulWidget {
409510
const CarouselWithIndicatorDemo({Key? key}) : super(key: key);
410511

0 commit comments

Comments
 (0)