-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdigital_wallet_view.dart
More file actions
270 lines (251 loc) · 7.72 KB
/
digital_wallet_view.dart
File metadata and controls
270 lines (251 loc) · 7.72 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import 'package:flutter/material.dart';
import 'package:flutter_custom_carousel/flutter_custom_carousel.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'demo_chrome.dart';
/// Example showing a swipable carousel of digital wallet accounts.
///
/// Demonstrates:
/// - using [CustomCarousel.onSelectedItemChanged] and [CustomCarousel.onSettledItemChanged]
/// - using [CustomCarousel.reverse] to reverse the interaction direction
///
/// Please note: to keep things simple, all demos were built for portrait mode
/// on mobile handsets, without a lot of effort or testing for responsiveness.
class DigitalWalletView extends StatefulWidget {
const DigitalWalletView({super.key});
@override
State<DigitalWalletView> createState() => _DigitalWalletViewState();
}
class _DigitalWalletViewState extends State<DigitalWalletView> {
int _selectedIndex = 0;
int? _activeIndex = 0;
@override
Widget build(BuildContext context) {
HSLColor color = HSLColor.fromColor(_accounts[_selectedIndex].color);
return DemoChrome(
backgroundColor: _accounts[_selectedIndex].color,
body: AnimatedContainer(
duration: 300.ms,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
color.withLightness(color.lightness * 0.1).toColor(),
color.withLightness(color.lightness * 0.3).toColor(),
color.toColor(),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildCarousel(),
const SizedBox(height: 16),
if (_activeIndex != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
key: ValueKey(_selectedIndex),
children: List.generate(
_selectedIndex % 3 + 3,
(i) => _buildTransactionRow(i),
),
),
),
],
),
),
);
}
Widget _buildCarousel() {
List<Widget> items = _accounts.map((account) => _Card(account)).toList();
// See `card_deck_view.dart` for a fully commented example of using
// Animate with CustomCarousel.
//
// This example is unusual in that it sets `reverse: true`, because it was
// easier to think about the animation effects that way. This simply
// reverses the direction of user scroll interactions.
Widget carousel = CustomCarousel(
itemCountBefore: 0,
itemCountAfter: 3,
scrollDirection: Axis.horizontal,
loop: true,
reverse: true,
depthOrder: DepthOrder.reverse,
scrollSpeed: 0.5,
alignment: Alignment.bottomCenter,
effectsBuilder: CustomCarousel.effectsBuilderFromAnimate(
effects: EffectList()
.fadeOut(delay: 100.ms, duration: 100.ms, curve: Curves.easeIn)
.blurXY(end: 8, curve: Curves.linear)
.slide(end: const Offset(-0.7, -0.45))
.slideX(delay: 0.ms, begin: 1.0),
),
// This uses a combination of selected and settled item so that the
// transaction list only appears after the user has settled on a card, but
// the list doesn't get removed until they scroll fully off the card.
onSelectedItemChanged: (i) => setState(() {
_selectedIndex = i;
_activeIndex = null;
}),
onSettledItemChanged: (i) {
if (i != null) setState(() => _activeIndex = i);
},
children: items,
);
return AspectRatio(aspectRatio: 1, child: carousel);
}
Widget _buildTransactionRow(int i) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 18),
child: Row(children: [
_box(width: 40, height: 40),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_box(height: 20, opacity: 0.25),
const SizedBox(height: 8),
_box(height: 12, width: 120, opacity: 0.15),
],
),
),
]),
)
.animate()
.fadeIn(delay: (i * 150).ms)
.slideY(begin: -0.1, curve: Curves.easeOut);
}
Widget _box({double? width, double? height, opacity = 0.3}) {
return Container(
width: width,
height: height,
decoration: BoxDecoration(
color: Colors.white.withOpacity(opacity),
borderRadius: BorderRadius.circular(6),
),
);
}
}
class _Card extends StatelessWidget {
const _Card(this.account, {Key? key}) : super(key: key);
final _AccountData account;
@override
Widget build(BuildContext context) {
Widget content = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Image.asset(
'assets/images/digital_wallet/${account.logo}',
width: 32,
),
const SizedBox(width: 12),
Text(
account.name,
style: const TextStyle(fontWeight: FontWeight.w300),
),
]),
const Spacer(flex: 3),
Text(
account.type,
style: const TextStyle(fontWeight: FontWeight.w400, fontSize: 14),
),
Text(account.balance, style: const TextStyle(fontSize: 22)),
const Spacer(flex: 2),
Text(account.cardNumber, style: const TextStyle(fontSize: 14)),
],
);
return AspectRatio(
aspectRatio: 3 / 2,
child: DefaultTextStyle(
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
child: Container(
padding: const EdgeInsets.all(24),
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/digital_wallet/${account.art}'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(12),
border: const Border(
top: BorderSide(color: Colors.white24, width: 2),
),
),
child: content,
),
),
);
}
}
class _AccountData {
const _AccountData({
required this.art,
required this.logo,
required this.name,
required this.type,
required this.balance,
required this.cardNumber,
required this.color,
});
final String art;
final String logo;
final String name;
final String type;
final String balance;
final String cardNumber;
final Color color;
}
const List<_AccountData> _accounts = [
_AccountData(
art: 'wallet-1.jpg',
logo: 'logo-1.png',
name: 'ProviderBank',
type: 'Savings Account',
balance: '\$11,234.56',
cardNumber: '**** **** **** 2345',
color: Color(0xFF3A8F07),
),
_AccountData(
art: 'wallet-2.jpg',
logo: 'logo-2.png',
name: 'WidgetOne',
type: 'Cashback Credit Card',
balance: '\$4,567.89',
cardNumber: '****** ***** 12345',
color: Color(0xFF6B1B9C),
),
_AccountData(
art: 'wallet-3.jpg',
logo: 'logo-2.png',
name: 'Dart Financial',
type: 'Credit Card',
balance: '\$2,345.67',
cardNumber: '**** **** **** 7890',
color: Color(0xFF1A949C),
),
_AccountData(
art: 'wallet-4.jpg',
logo: 'logo-3.png',
name: 'Dash+',
type: 'Travel Rewards',
balance: '10,678 pts',
cardNumber: 'Member #54321',
color: Color(0xFF073C96),
),
_AccountData(
art: 'wallet-5.jpg',
logo: 'logo-2.png',
name: 'Carousel',
type: 'Member Card',
balance: '\$987.00',
cardNumber: 'Member ID: C-12345',
color: Color(0xFFBC5A22),
),
];