Skip to content

Commit cac6b5b

Browse files
authored
Create caraousel.dart
1 parent a233c75 commit cac6b5b

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

caraousel.dart

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
class ImageSliderDemo extends StatefulWidget {
2+
@override
3+
_ImageSliderDemoState createState() => _ImageSliderDemoState();
4+
}
5+
int _current = 0;
6+
final CarouselController _controller = CarouselController();
7+
class _ImageSliderDemoState extends State<ImageSliderDemo> {
8+
final List<String> imgList = [
9+
'https://images.unsplash.com/photo-1610438235354-a6ae5528385c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=334&q=80',
10+
'https://images.unsplash.com/photo-1517336714731-489689fd1ca8?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=626&q=80'
11+
'https://images.unsplash.com/photo-1606220588913-b3aacb4d2f46?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80',
12+
'https://images.unsplash.com/photo-1585298723682-7115561c51b7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=400&q=80',
13+
'https://images.unsplash.com/photo-1546868871-7041f2a55e12?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1yZWxhdGVkfDEyfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60',
14+
'https://images.unsplash.com/photo-1569429594806-192f16855a0e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1yZWxhdGVkfDd8fHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60',
15+
'https://images.unsplash.com/photo-1548484352-ea579e5233a8?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80'
16+
'https://images.unsplash.com/photo-1517336714731-489689fd1ca8?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=626&q=80'
17+
];
18+
19+
20+
@override
21+
Widget build(BuildContext context) {
22+
23+
return Column(
24+
children: [
25+
Container(
26+
child: CarouselSlider(
27+
options: CarouselOptions(
28+
enlargeCenterPage: true,
29+
enableInfiniteScroll: true,
30+
onPageChanged: (index, reason) {
31+
setState(() {
32+
_current = index;
33+
});
34+
}
35+
),
36+
items: imgList
37+
.map((item) => Container(
38+
child: Center(
39+
child: Stack(
40+
children: [
41+
Container(
42+
width: 1200,
43+
decoration:BoxDecoration(
44+
borderRadius: BorderRadius.circular(30),
45+
image: DecorationImage(
46+
image: NetworkImage(item),
47+
fit: BoxFit.cover,)),
48+
),
49+
//: Image.network(item, fit: BoxFit.cover, width: 1200)),
50+
Align(
51+
alignment: Alignment.bottomRight,
52+
child: Padding(
53+
padding: const EdgeInsets.only(right: 10,bottom: 6),
54+
child: ClipRect(
55+
56+
child: BackdropFilter(
57+
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
58+
child: Container(
59+
width: 120,
60+
height: 30,
61+
decoration: BoxDecoration(
62+
borderRadius: BorderRadius.circular(20),
63+
color: Colors.grey.withOpacity(0.5),
64+
),
65+
child: Row(
66+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
67+
children: [
68+
Text('Shop Now',style: TextStyle(color: Colors.white,fontFamily: 'Ubuntu',letterSpacing: 2,fontWeight: FontWeight.w600),),
69+
Icon(Icons.arrow_forward_ios,color: Colors.white,size: 15,),
70+
],
71+
),
72+
),
73+
74+
),
75+
),
76+
),
77+
)
78+
],
79+
)),
80+
))
81+
.toList(),
82+
)),
83+
Row(
84+
mainAxisAlignment: MainAxisAlignment.center,
85+
children: imgList.asMap().entries.map((entry) {
86+
return GestureDetector(
87+
onTap: () => _controller.animateToPage(entry.key),
88+
child: Container(
89+
width: 6.0,
90+
height: 6.0,
91+
margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),
92+
decoration: BoxDecoration(
93+
shape: BoxShape.circle,
94+
color: (Theme.of(context).brightness == Brightness.dark
95+
? Colors.white
96+
: Colors.black)
97+
.withOpacity(_current == entry.key ? 0.9 : 0.4)),
98+
),
99+
);
100+
}).toList(),
101+
),
102+
],
103+
104+
);
105+
}
106+
}

0 commit comments

Comments
 (0)