carousel.dart
7.15 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import 'package:carousel_slider/carousel_slider.dart';
import 'package:like/widgets/responsive.dart';
import 'package:flutter/material.dart';
class DestinationCarousel extends StatefulWidget {
@override
_DestinationCarouselState createState() => _DestinationCarouselState();
}
class _DestinationCarouselState extends State<DestinationCarousel> {
final String imagePath = 'assets/images/';
final CarouselController _controller = CarouselController();
List _isHovering = [false, false, false, false, false, false, false];
List _isSelected = [true, false, false, false, false, false, false];
int _current = 0;
final List<String> images = [
'assets/images/asia.jpg',
'assets/images/africa.jpg',
'assets/images/europe.jpg',
'assets/images/south_america.jpg',
'assets/images/australia.jpg',
'assets/images/antarctica.jpg',
];
final List<String> places = [
'ASIA',
'AFRICA',
'EUROPE',
'SOUTH AMERICA',
'AUSTRALIA',
'ANTARCTICA',
];
List<Widget> generateImageTiles(screenSize) {
return images
.map(
(element) => ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.asset(
element,
fit: BoxFit.cover,
),
),
)
.toList();
}
@override
Widget build(BuildContext context) {
var screenSize = MediaQuery.of(context).size;
var imageSliders = generateImageTiles(screenSize);
return Stack(
children: [
CarouselSlider(
items: imageSliders,
options: CarouselOptions(
scrollPhysics: ResponsiveWidget.isSmallScreen(context)
? PageScrollPhysics()
: NeverScrollableScrollPhysics(),
enlargeCenterPage: true,
aspectRatio: 18 / 8,
autoPlay: true,
onPageChanged: (index, reason) {
setState(() {
_current = index;
for (int i = 0; i < imageSliders.length; i++) {
if (i == index) {
_isSelected[i] = true;
} else {
_isSelected[i] = false;
}
}
});
}),
carouselController: _controller,
),
AspectRatio(
aspectRatio: 18 / 8,
child: Center(
child: Text(
places[_current],
style: TextStyle(
letterSpacing: 8,
fontFamily: 'Electrolize',
fontSize: screenSize.width / 25,
color: Colors.white,
),
),
),
),
ResponsiveWidget.isSmallScreen(context)
? Container()
: AspectRatio(
aspectRatio: 17 / 8,
child: Center(
heightFactor: 1,
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(
left: screenSize.width / 8,
right: screenSize.width / 8,
),
child: Card(
elevation: 5,
child: Padding(
padding: EdgeInsets.only(
top: screenSize.height / 50,
bottom: screenSize.height / 50,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
for (int i = 0; i < places.length; i++)
Column(
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
splashColor: Colors.blueGrey,
hoverColor: Colors.transparent,
onHover: (value) {
setState(() {
value
? _isHovering[i] = true
: _isHovering[i] = false;
});
},
onTap: () {
_controller.animateToPage(i);
},
child: Padding(
padding: EdgeInsets.only(
top: screenSize.height / 80,
bottom: screenSize.height / 90),
child: Text(
places[i],
style: TextStyle(
color: _isHovering[i]
? Theme.of(context)
.primaryTextTheme
.button!
.decorationColor
: Theme.of(context)
.primaryTextTheme
.button!
.decorationColor,
),
),
),
),
Visibility(
maintainSize: true,
maintainAnimation: true,
maintainState: true,
visible: _isSelected[i],
child: AnimatedOpacity(
duration: Duration(milliseconds: 400),
opacity: _isSelected[i] ? 1 : 0,
child: Container(
height: 5,
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
width: screenSize.width / 10,
),
),
)
],
),
],
),
),
),
),
),
),
),
],
);
}
}