-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathblurred_list.dart
231 lines (210 loc) · 7.48 KB
/
blurred_list.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import 'dart:ui';
import 'package:custom_widgets/utils/constants.dart';
import 'package:flutter/material.dart';
class BlurredList extends StatefulWidget {
const BlurredList({super.key});
@override
State<BlurredList> createState() => _BlurredListState();
}
class _BlurredListState extends State<BlurredList>
with TickerProviderStateMixin {
late AnimationController positionController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 250));
Constants constants = Constants();
double cardHeight = 100;
double boxHeight = 320;
double primaryBoxHeight = 380;
int next = -1;
List<Animation<double>> cardsPosition = [];
List<BlurredCard> blurredCards = [];
void updateList(double width) async {
if (blurredCards.length >= 3 &&
next < constants.blurredListComponent.length - 1) {
setState(() {
next += 1;
for (int i = 0; i < cardsPosition.length; i++) {
cardsPosition[i] = Tween<double>(
begin: i * (cardHeight + 5), end: (i - 1) * (cardHeight + 5))
.animate(positionController);
}
cardsPosition.add(Tween<double>(
begin: 3 * (cardHeight + 5), end: (3 - 1) * (cardHeight + 5))
.animate(positionController));
blurredCards.add(BlurredCard(
width: width,
cost: constants.blurredListComponent[next]["cost"].toString(),
icon: constants.blurredListComponent[next]["icon"],
ref: constants.blurredListComponent[next]["ref"],
height: cardHeight,
));
});
await positionController.forward(from: 0);
//await positionController.animateWith(springSimulation);
setState(() {
blurredCards.removeAt(0);
cardsPosition.removeAt(0);
});
} else if (next < constants.blurredListComponent.length - 1) {
setState(() {
next += 1;
cardsPosition.add(AlwaysStoppedAnimation(next * (cardHeight + 5)));
blurredCards.add(BlurredCard(
width: width,
cost: constants.blurredListComponent[next]["cost"].toString(),
icon: constants.blurredListComponent[next]["icon"],
ref: constants.blurredListComponent[next]["ref"],
height: cardHeight,
));
});
}
}
@override
void dispose() {
positionController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: const Text("Blurred List"),
),
body: AnimatedBuilder(
animation: positionController,
builder: (context, child) {
return Center(
child: SizedBox(
height: primaryBoxHeight,
width: width,
child: Stack(
children: [
...List.generate(blurredCards.length, (index) {
return Positioned(
left: width * 0.07,
top: cardsPosition[index].value,
child: blurredCards[index]);
}),
Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onTap: () {
updateList(width);
},
child: const CircleAvatar(
radius: 30,
backgroundColor: Colors.black,
child: Icon(
Icons.add,
size: 50,
color: Colors.white,
),
),
))
],
),
));
}),
);
}
}
class BlurredCard extends StatefulWidget {
const BlurredCard(
{super.key,
required this.width,
required this.height,
required this.cost,
required this.icon,
required this.ref});
final double width, height;
final String icon, cost, ref;
@override
State<BlurredCard> createState() => _BlurredCardState();
}
class _BlurredCardState extends State<BlurredCard>
with TickerProviderStateMixin {
late AnimationController blurController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 400));
late Animation<double> sigmaTween =
Tween<double>(begin: 25.0, end: 0).animate(blurController);
late Animation<double> opacityAnimation =
Tween<double>(begin: 0, end: 1).animate(blurController);
@override
void initState() {
super.initState();
blurController.animateTo(1);
}
@override
void dispose() {
blurController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: blurController,
builder: (context, child) {
return Opacity(
opacity: opacityAnimation.value,
child: SizedBox(
width: widget.width * 0.85,
height: widget.height,
child: Stack(
children: [
Positioned.fill(
child: Card(
color: Colors.white,
elevation: 0.3,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 60,
width: 60,
decoration: BoxDecoration(
color:
const Color.fromARGB(255, 246, 244, 249),
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage(widget.icon))),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"\$ ${widget.cost}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 23),
),
Text(
widget.ref,
style: const TextStyle(
color: Colors.grey, fontSize: 16),
)
],
)
],
),
),
),
),
Positioned.fill(
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: sigmaTween.value,
sigmaY: sigmaTween.value),
child: const Opacity(
opacity: 0,
)))
],
),
),
);
});
}
}