Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
banner_slider.dart
Go to the documentation of this file.
1import 'dart:async';
2import 'package:flutter/material.dart';
3import 'package:flutter_screenutil/flutter_screenutil.dart';
4import '../../../../../core/constants/assets.dart';
5
6class BannerSlider extends StatefulWidget {
7 const BannerSlider({super.key});
8
9 @override
10 State<BannerSlider> createState() => _BannerSliderState();
11}
12
13class _BannerSliderState extends State<BannerSlider> {
14 final PageController _pageController = PageController();
15 int _currentPage = 0;
16 Timer? _timer;
17
18 @override
19 void initState() {
20 super.initState();
22 }
23
24 @override
25 void dispose() {
26 _timer?.cancel();
27 _pageController.dispose();
28 super.dispose();
29 }
30
32 _timer = Timer.periodic(const Duration(seconds: 3), (timer) {
33 if (_currentPage < Assets.bannerImages.length - 1) {
35 } else {
36 _currentPage = 0;
37 }
38
39 if (_pageController.hasClients) {
40 _pageController.animateToPage(
42 duration: const Duration(milliseconds: 350),
43 curve: Curves.easeIn,
44 );
45 }
46 });
47 }
48
49 @override
50 Widget build(BuildContext context) {
51 return Column(
52 children: [
54 height: 140.sp,
55 child: Stack(
56 alignment: Alignment.bottomCenter,
57 children: [
58 PageView.builder(
59 controller: _pageController,
60 onPageChanged: (index) {
61 setState(() {
62 _currentPage = index;
63 });
64 },
65 itemCount: Assets.bannerImages.length,
66 itemBuilder: (context, index) {
67 return Padding(
68 padding: EdgeInsets.symmetric(horizontal: 20.sp),
69 child: ClipRRect(
70 borderRadius: BorderRadius.circular(12.sp),
71 child: Image.asset(
72 Assets.bannerImages[index],
73 fit: BoxFit.fill,
74 ),
75 ),
76 );
77 },
78 ),
79 Positioned(
80 bottom: 10.sp,
81 child: Row(
82 mainAxisAlignment: MainAxisAlignment.center,
83 children: List.generate(
84 Assets.bannerImages.length,
85 (index) => Container(
86 margin: EdgeInsets.symmetric(horizontal: 2.sp),
87 width: 8.sp,
88 height: 8.sp,
89 decoration: BoxDecoration(
90 shape: BoxShape.circle,
91 color: _currentPage == index
92 ? Theme.of(context).primaryColor
93 : Colors.grey.shade300,
94 ),
95 ),
96 ),
97 ),
98 ),
99 ],
100 ),
101 ),
102 ],
103 );
104 }
105}
override void initState()
override void dispose()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
Timer _timer
class BannerSlider extends StatefulWidget _pageController
void _startAutoSlide()
static const List< String > bannerImages
Definition assets.dart:25
const BannerSlider({super.key})
override State< BannerSlider > createState()
final Widget child
final EdgeInsets padding
int _currentPage
final Color color
Definition failures.dart:1
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)