-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhome_view.dart
More file actions
216 lines (198 loc) · 5.55 KB
/
home_view.dart
File metadata and controls
216 lines (198 loc) · 5.55 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
import 'package:flutter/material.dart';
import 'package:flutter_custom_carousel/flutter_custom_carousel.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'card_deck_view.dart';
import 'circular_menu_view.dart';
import 'cover_slider_view.dart';
import 'digital_wallet_view.dart';
import 'record_box_view.dart';
/// Example showing card vertically scrolling card-based navigation.
///
/// Demonstrates:
/// - using [CustomCarousel.onSettledItemChanged] to update the active card's UI
/// - interacting with items to navigate to other views
///
/// 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 HomeView extends StatefulWidget {
const HomeView({super.key});
@override
State<HomeView> createState() => _HomeViewState();
}
class _HomeViewState extends State<HomeView> {
int? _activeIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: _buildCarousel(),
),
);
}
Widget _buildCarousel() {
List<Widget> items = [];
for (int i = 0; i < _examples.length; i++) {
items.add(_ExampleCard(
example: _examples[i],
selected: i == _activeIndex,
key: ValueKey(i),
));
}
// See `card_deck_view.dart` for a fully commented example of using
// Animate with CustomCarousel.
return CustomCarousel(
alignment: Alignment.center,
itemCountBefore: 2,
itemCountAfter: 2,
scrollSpeed: 1.5,
loop: true,
effectsBuilder: CustomCarousel.effectsBuilderFromAnimate(
effects: EffectList()
.shimmer(
delay: 60.ms,
duration: 140.ms,
color: Colors.white38,
angle: 0.3,
)
.blurXY(delay: 0.ms, duration: 100.ms, begin: 8)
.blurXY(delay: 100.ms, end: 8)
.slideY(delay: 0.ms, duration: 200.ms, begin: -3, end: 3)
.flipH(begin: -0.3, end: 0.3),
),
onSettledItemChanged: (i) => setState(() => _activeIndex = i),
children: items,
);
}
}
class _ExampleCard extends StatelessWidget {
const _ExampleCard({
Key? key,
required this.example,
this.selected = false,
}) : super(key: key);
final _ExampleData example;
final bool selected;
@override
Widget build(BuildContext context) {
Widget card = AspectRatio(
aspectRatio: 1.125,
child: Container(
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
color: example.color,
image: DecorationImage(
image: AssetImage('assets/images/home/${example.id}.png'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(16),
border: const Border(
top: BorderSide(color: Colors.white30, width: 2),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
example.title,
style: const TextStyle(
fontSize: 32,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
const Spacer(),
if (selected)
Align(
alignment: Alignment.bottomRight,
child: _buildTryBtn(),
)
],
),
),
);
if (selected) {
card = MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => _goto(context, example),
child: card,
),
);
}
return card;
}
void _goto(BuildContext context, _ExampleData example) {
Navigator.of(context).push(
MaterialPageRoute(builder: example.builder),
);
}
Widget _buildTryBtn() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(999),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 8,
offset: Offset(2, 4),
),
],
),
child: const Text(
'Try It →',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
).animate().fadeIn(delay: 100.ms).moveX(begin: -6, curve: Curves.easeOut);
}
}
class _ExampleData {
const _ExampleData({
required this.id,
required this.title,
required this.color,
required this.builder,
});
final String id;
final String title;
final Color color;
final WidgetBuilder builder;
}
final List<_ExampleData> _examples = [
_ExampleData(
id: 'cover-slider',
title: 'Cover Slider',
color: const Color(0xFF4DACF7),
builder: (_) => const CoverSliderView(),
),
_ExampleData(
id: 'circular-menu',
title: 'Circular Menu',
color: const Color(0xFF71C51C),
builder: (_) => const CircularMenuView(),
),
_ExampleData(
id: 'card-deck',
title: 'Card Deck',
color: const Color(0xFFE79B2D),
builder: (_) => const CardDeckView(),
),
_ExampleData(
id: 'digital-wallet',
title: 'Digital Wallet',
color: const Color(0xFFA02BD7),
builder: (_) => const DigitalWalletView(),
),
_ExampleData(
id: 'record-box',
title: 'Record Box',
color: const Color(0xFFD72B44),
builder: (_) => const RecordBoxView(),
),
];