-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathoffers_carousel.dart
123 lines (113 loc) · 3.15 KB
/
offers_carousel.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'dart:async';
import 'package:flutter/material.dart';
import '../../../../components/Banner/M/banner_m_style_1.dart';
import '../../../../components/Banner/M/banner_m_style_2.dart';
import '../../../../components/Banner/M/banner_m_style_3.dart';
import '../../../../components/Banner/M/banner_m_style_4.dart';
import '../../../../components/dot_indicators.dart';
import '../../../../constants.dart';
class OffersCarousel extends StatefulWidget {
const OffersCarousel({
super.key,
});
@override
State<OffersCarousel> createState() => _OffersCarouselState();
}
class _OffersCarouselState extends State<OffersCarousel> {
int _selectedIndex = 0;
late PageController _pageController;
late Timer _timer;
// Offers List
List offers = [
BannerMStyle1(
text: "New items with \nFree shipping",
press: () {},
),
BannerMStyle2(
title: "Black \nfriday",
subtitle: "Collection",
discountParcent: 50,
press: () {},
),
BannerMStyle3(
title: "Grab \nyours now",
discountParcent: 50,
press: () {},
),
BannerMStyle4(
// image: , user your image
title: "SUMMER \nSALE",
subtitle: "SPECIAL OFFER",
discountParcent: 80,
press: () {},
),
];
@override
void initState() {
_pageController = PageController(initialPage: 0);
_timer = Timer.periodic(const Duration(seconds: 4), (Timer timer) {
if (_selectedIndex < offers.length - 1) {
_selectedIndex++;
} else {
_selectedIndex = 0;
}
_pageController.animateToPage(
_selectedIndex,
duration: const Duration(milliseconds: 350),
curve: Curves.easeOutCubic,
);
});
super.initState();
}
@override
void dispose() {
_pageController.dispose();
_timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 1.87,
child: Stack(
alignment: Alignment.bottomRight,
children: [
PageView.builder(
controller: _pageController,
itemCount: offers.length,
onPageChanged: (int index) {
setState(() {
_selectedIndex = index;
});
},
itemBuilder: (context, index) => offers[index],
),
FittedBox(
child: Padding(
padding: const EdgeInsets.all(defaultPadding),
child: SizedBox(
height: 16,
child: Row(
children: List.generate(
offers.length,
(index) {
return Padding(
padding:
const EdgeInsets.only(left: defaultPadding / 4),
child: DotIndicator(
isActive: index == _selectedIndex,
activeColor: Colors.white70,
inActiveColor: Colors.white54,
),
);
},
),
),
),
),
)
],
),
);
}
}