-
Notifications
You must be signed in to change notification settings - Fork 103
/
main.dart
166 lines (152 loc) · 4.74 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
import 'package:flutter/material.dart';
import 'package:flip_card/flip_card.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FlipCard',
theme: ThemeData(
brightness: Brightness.dark,
colorSchemeSeed: const Color(0xFF006666),
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late FlipCardController _controller;
bool skewed = false;
@override
void initState() {
super.initState();
_controller = FlipCardController();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('FlipCard'),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0, vertical: 64.0),
child: SizedBox.expand(
child: _buildCard(context),
),
),
bottomNavigationBar: Material(
elevation: 3.0,
surfaceTintColor: theme.colorScheme.surfaceTint,
child: SizedBox(
height: 80.0,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FilledButton(
onPressed: () => _controller.flip(),
child: const Text('Toggle'),
),
const SizedBox(width: 8.0),
FilledButton.icon(
onPressed: () async {
await _controller.skew(skewed ? 0.0 : 0.2);
setState(() => skewed = !skewed);
},
icon: skewed
? const Icon(Icons.circle)
: const Icon(Icons.circle_outlined),
label: const Text('Skew'),
),
const SizedBox(width: 8.0),
FilledButton(
onPressed: () async => await _controller.hint(),
child: const Text('Hint'),
),
],
),
),
),
),
);
}
Widget _buildCard(BuildContext context) {
final theme = Theme.of(context);
final titleStyle = theme.textTheme.displayLarge
?.copyWith(color: theme.colorScheme.onPrimary);
final paragraphStyle =
theme.textTheme.bodyLarge?.copyWith(color: theme.colorScheme.onPrimary);
return FlipCard(
direction: Axis.horizontal,
initialSide: CardSide.front,
duration: const Duration(milliseconds: 1000),
controller: _controller,
onFlipDone: (status) {
// ignore: avoid_print
print(status);
},
front: Card(
color: theme.colorScheme.primary,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Front', style: titleStyle),
Text('Click here to flip back', style: paragraphStyle),
const SizedBox(height: 16.0),
OutlinedButton(
onPressed: () => _showMessage(context, 'Clicked button on front'),
style: OutlinedButton.styleFrom(
foregroundColor: theme.colorScheme.onPrimary,
),
child: const Text('Click me!'),
),
],
),
),
back: Card(
color: theme.colorScheme.secondary,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Back',
style: theme.textTheme.displayLarge
?.copyWith(color: theme.colorScheme.onSecondary),
),
Text(
'Click here to flip front',
style: theme.textTheme.bodyLarge
?.copyWith(color: theme.colorScheme.onSecondary),
),
const SizedBox(height: 16.0),
OutlinedButton(
onPressed: () => _showMessage(context, 'Clicked button on back'),
style: OutlinedButton.styleFrom(
foregroundColor: theme.colorScheme.onPrimary,
),
child: const Text('Click me!'),
),
],
),
),
);
}
void _showMessage(
BuildContext context,
String message,
) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(message)));
}
}