Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ece828e

Browse files
Make main class
1 parent 1d449e2 commit ece828e

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

‎lib/main.dart

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import 'package:day18_carousel/Animation/FadeAnimation.dart';
2+
import 'package:flutter/material.dart';
3+
4+
void main() => runApp(
5+
MaterialApp(
6+
debugShowCheckedModeBanner: false,
7+
home: HomePage(),
8+
)
9+
);
10+
11+
class HomePage extends StatefulWidget {
12+
@override
13+
_HomePageState createState() => _HomePageState();
14+
}
15+
16+
class _HomePageState extends State<HomePage> {
17+
final List<List<String>> products = [
18+
[
19+
'assets/images/watch-1.jpg',
20+
'Hugo Boss Oxygen',
21+
'100 \$'
22+
],
23+
[
24+
'assets/images/watch-2.jpg',
25+
'Hugo Boss Signature',
26+
'120 \$'
27+
],
28+
[
29+
'assets/images/watch-3.jpg',
30+
'Casio G-Shock Premium',
31+
'80 \$'
32+
]
33+
];
34+
35+
int currentIndex = 0;
36+
37+
void _next() {
38+
setState(() {
39+
if (currentIndex < products.length -1) {
40+
currentIndex++;
41+
} else {
42+
currentIndex = currentIndex;
43+
}
44+
});
45+
}
46+
47+
void _preve() {
48+
setState(() {
49+
if (currentIndex > 0) {
50+
currentIndex--;
51+
} else {
52+
currentIndex = 0;
53+
}
54+
});
55+
}
56+
57+
@override
58+
Widget build(BuildContext context) {
59+
return Scaffold(
60+
body: Container(
61+
child: Column(
62+
children: <Widget>[
63+
GestureDetector(
64+
onHorizontalDragEnd: (DragEndDetails details) {
65+
if (details.velocity.pixelsPerSecond.dx > 0) {
66+
_preve();
67+
} else if (details.velocity.pixelsPerSecond.dx < 0) {
68+
_next();
69+
}
70+
},
71+
child: FadeAnimation(.8, Container(
72+
width: double.infinity,
73+
height: 550,
74+
decoration: BoxDecoration(
75+
image: DecorationImage(
76+
image: AssetImage(products[currentIndex][0]),
77+
fit: BoxFit.cover
78+
)
79+
),
80+
child: Container(
81+
decoration: BoxDecoration(
82+
gradient: LinearGradient(
83+
begin: Alignment.bottomRight,
84+
colors: [
85+
Colors.grey[700].withOpacity(.9),
86+
Colors.grey.withOpacity(.0),
87+
]
88+
)
89+
),
90+
child: Column(
91+
mainAxisAlignment: MainAxisAlignment.end,
92+
children: <Widget>[
93+
FadeAnimation(1, Container(
94+
width: 90,
95+
margin: EdgeInsets.only(bottom: 60),
96+
child: Row(
97+
children: _buildIndicator(),
98+
),
99+
))
100+
],
101+
),
102+
),
103+
)),
104+
),
105+
Expanded(
106+
child: Transform.translate(
107+
offset: Offset(0, -40),
108+
child: FadeAnimation(1, Container(
109+
width: double.infinity,
110+
padding: EdgeInsets.all(30),
111+
decoration: BoxDecoration(
112+
color: Colors.white,
113+
borderRadius: BorderRadius.only(topLeft: Radius.circular(30), topRight: Radius.circular(30))
114+
),
115+
child: Column(
116+
crossAxisAlignment: CrossAxisAlignment.start,
117+
children: <Widget>[
118+
FadeAnimation(1.3, Text(products[currentIndex][1], style: TextStyle(color: Colors.grey[800], fontSize: 40, fontWeight: FontWeight.bold),)),
119+
SizedBox(height: 15,),
120+
Row(
121+
children: <Widget>[
122+
FadeAnimation(1.4, Text(products[currentIndex][2], style: TextStyle(color: Colors.yellow[700], fontWeight: FontWeight.bold, fontSize: 20),)),
123+
SizedBox(width: 10,),
124+
FadeAnimation(1.5, Row(
125+
children: <Widget>[
126+
Icon(Icons.star, size: 18, color: Colors.yellow[700],),
127+
Icon(Icons.star, size: 18, color: Colors.yellow[700],),
128+
Icon(Icons.star, size: 18, color: Colors.yellow[700],),
129+
Icon(Icons.star, size: 18, color: Colors.yellow[700],),
130+
Icon(Icons.star_half, size: 18, color: Colors.yellow[700],),
131+
SizedBox(width: 5,),
132+
Text("(4.2/70 reviews)", style: TextStyle(color: Colors.grey, fontSize: 12),)
133+
],
134+
))
135+
],
136+
),
137+
Expanded(
138+
child: Align(
139+
alignment: Alignment.bottomCenter,
140+
child: FadeAnimation(1.7, Container(
141+
height: 45,
142+
decoration: BoxDecoration(
143+
color: Colors.yellow[700],
144+
borderRadius: BorderRadius.circular(8)
145+
),
146+
child: Center(
147+
child: Text("ADD TO CART", style: TextStyle(fontWeight: FontWeight.bold),),
148+
),
149+
)),
150+
),
151+
)
152+
],
153+
),
154+
)),
155+
),
156+
)
157+
],
158+
),
159+
),
160+
);
161+
}
162+
163+
Widget _indicator(bool isActive) {
164+
return Expanded(
165+
child: Container(
166+
height: 4,
167+
margin: EdgeInsets.only(right: 5),
168+
decoration: BoxDecoration(
169+
borderRadius: BorderRadius.circular(50),
170+
color: isActive ? Colors.grey[800] : Colors.white
171+
),
172+
),
173+
);
174+
}
175+
176+
List<Widget> _buildIndicator() {
177+
List<Widget> indicators = [];
178+
for(int i = 0; i < products.length; i++) {
179+
if (currentIndex == i) {
180+
indicators.add(_indicator(true));
181+
} else {
182+
indicators.add(_indicator(false));
183+
}
184+
}
185+
186+
return indicators;
187+
}
188+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /