-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
189 lines (178 loc) · 4.73 KB
/
main.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
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'package:carousel/carousel.dart';
import 'package:carousel_example/pokemon.dart';
import 'package:carousel_example/pokemon_card.dart';
import 'package:carousel_example/pokemon_types.dart';
import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() {
runApp(const CarouselExampleApp());
}
class CarouselExampleApp extends StatefulWidget {
const CarouselExampleApp({Key? key}) : super(key: key);
@override
State<CarouselExampleApp> createState() => _CarouselExampleAppState();
}
class _CarouselExampleAppState extends State<CarouselExampleApp> {
Pokemon? selected;
final List<Pokemon> pokemons = [
Pokemon(
name: 'Bulbasaur',
nr: 1,
types: [
PokemonType.grass,
PokemonType.poison,
],
),
Pokemon(
name: 'Charmander',
nr: 4,
types: [
PokemonType.fire,
],
),
Pokemon(
name: 'Squirtle',
nr: 7,
types: [
PokemonType.water,
],
),
Pokemon(
name: 'Caterpie',
nr: 10,
types: [
PokemonType.bug,
],
),
Pokemon(
name: 'Pidgey',
nr: 16,
types: [
PokemonType.normal,
PokemonType.flying,
],
),
Pokemon(
name: 'Pikachu',
nr: 25,
types: [
PokemonType.electric,
],
),
Pokemon(
name: 'Machop',
nr: 66,
types: [
PokemonType.fighting,
],
),
Pokemon(
name: 'Geodude',
nr: 74,
types: [
PokemonType.rock,
PokemonType.ground,
],
),
];
Widget _buildCard(BuildContext context, int index) {
return PokemonCard(
pokemon: pokemons[index % pokemons.length],
);
}
void _onClick(int index) {
setState(() {
selected = pokemons[index % pokemons.length];
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
alignment: Alignment.bottomCenter,
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: [
const SizedBox(height: 50),
Carousel(
pageViewHeight: 220,
selectableCardId: 4,
onCardClick: _onClick,
transforms: [
CardTransform(
x: 220,
y: -85,
angle: -math.pi / 12,
scale: 0.3,
opacity: 0.2,
),
CardTransform(
x: 230,
y: -80,
angle: math.pi / 12,
scale: 0.5,
opacity: 0.4,
),
CardTransform(
x: 200,
y: -75,
angle: -math.pi / 12,
scale: 0.6,
opacity: 0.6,
),
CardTransform(
x: 110,
y: -60,
angle: math.pi / 12,
scale: 0.7,
opacity: 0.8,
),
CardTransform(
x: 0,
y: 0,
angle: 0,
scale: 1,
opacity: 1.0,
),
CardTransform(
x: -270,
y: 70,
angle: -math.pi / 50,
scale: 1,
opacity: 0.5,
),
],
builder: _buildCard,
),
Carousel(
selectableCardId: 1,
onCardClick: _onClick,
alignment: Alignment.center,
transforms: [
CardTransform(x: 0, y: 0, angle: 0, scale: 0.5),
CardTransform(x: 0, y: 0, angle: 0, scale: 1),
CardTransform(
x: 300, y: 0, angle: math.pi / 20, scale: 1),
],
builder: _buildCard,
),
],
),
),
if (selected != null)
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Text('Clicked: ${selected!.name}'),
),
],
),
),
);
}
}