Skip to content

Commit feb06e2

Browse files
committed
Added indicator halo example
1 parent e13b01f commit feb06e2

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

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)