-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathmain.dart
More file actions
294 lines (268 loc) · 7.19 KB
/
main.dart
File metadata and controls
294 lines (268 loc) · 7.19 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:popup_card/fake_data.dart';
import 'package:popup_card/styles.dart';
import 'package:popup_card/models.dart';
import 'add_todo_button.dart';
import 'custom_rect_tween.dart';
import 'hero_dialog_route.dart';
void main() => runApp(const MyApp());
/// {@template my_app}
/// Entry point for the application.
/// {@endtemplate}
class MyApp extends StatelessWidget {
/// {@macro my_app}
const MyApp();
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: const Home(),
);
}
}
/// {@template home}
/// Home widget of the application.
/// {@endtemplate}
class Home extends StatelessWidget {
/// {@macro home}
const Home({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
AppColors.backgroundFadedColor,
AppColors.backgroundColor,
],
stops: [0.0, 1],
),
),
),
SafeArea(
child: _TodoListContent(
todos: fakeData,
),
),
const Align(
alignment: Alignment.bottomRight,
child: AddTodoButton(),
)
],
),
);
}
}
/// {@template todo_list_content}
/// List of [Todo]s.
/// {@endtemplate}
class _TodoListContent extends StatelessWidget {
const _TodoListContent({
Key? key,
required this.todos,
}) : super(key: key);
final List<Todo> todos;
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: todos.length,
padding: const EdgeInsets.all(16),
itemBuilder: (context, index) {
final _todo = todos[index];
return _TodoCard(todo: _todo);
},
);
}
}
/// {@template todo_card}
/// Card that display a [Todo]'s content.
///
/// On tap it opens a [HeroDialogRoute] with [_TodoPopupCard] as the content.
/// {@endtemplate}
class _TodoCard extends StatelessWidget {
/// {@macro todo_card}
const _TodoCard({
Key? key,
required this.todo,
}) : super(key: key);
final Todo todo;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.of(context).push(
HeroDialogRoute(
builder: (context) => Center(
child: _TodoPopupCard(todo: todo),
),
),
);
},
child: Hero(
createRectTween: (begin, end) {
return CustomRectTween(begin: begin, end: end);
},
tag: todo.id,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Material(
color: AppColors.cardColor,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
_TodoTitle(title: todo.description),
const SizedBox(
height: 8,
),
if (todo.items != null) ...[
const Divider(),
_TodoItemsBox(items: todo.items),
]
],
),
),
),
),
),
);
}
}
/// {@template todo_title}
/// Title of a [Todo].
/// {@endtemplate}
class _TodoTitle extends StatelessWidget {
/// {@macro todo_title}
const _TodoTitle({
Key? key,
required this.title,
}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Text(
title,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
);
}
}
/// {@template todo_popup_card}
/// Popup card to expand the content of a [Todo] card.
///
/// Activated from [_TodoCard].
/// {@endtemplate}
class _TodoPopupCard extends StatelessWidget {
const _TodoPopupCard({Key? key, this.todo}) : super(key: key);
final Todo? todo;
@override
Widget build(BuildContext context) {
return Hero(
tag: todo!.id,
createRectTween: (begin, end) {
return CustomRectTween(begin: begin, end: end);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Material(
borderRadius: BorderRadius.circular(16),
color: AppColors.cardColor,
child: SizedBox(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_TodoTitle(title: todo!.description),
const SizedBox(
height: 8,
),
if (todo!.items != null) ...[
const Divider(),
_TodoItemsBox(items: todo!.items),
],
Container(
margin: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.black12,
borderRadius: BorderRadius.circular(8),
),
child: const TextField(
maxLines: 8,
cursorColor: Colors.white,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
hintText: 'Write a note...',
border: InputBorder.none),
),
),
],
),
),
),
),
),
),
);
}
}
/// {@template todo_items_box}
/// Box containing the list of a [Todo]'s items.
///
/// These items can be checked.
/// {@endtemplate}
class _TodoItemsBox extends StatelessWidget {
/// {@macro todo_items_box}
const _TodoItemsBox({
Key? key,
required this.items,
}) : super(key: key);
final List<Item>? items;
@override
Widget build(BuildContext context) {
return Column(
children: [
for (final item in items!) _TodoItemTile(item: item),
],
);
}
}
/// {@template todo_item_template}
/// An individual [Todo] [Item] with its [Checkbox].
/// {@endtemplate}
class _TodoItemTile extends StatefulWidget {
/// {@macro todo_item_template}
const _TodoItemTile({
Key? key,
required this.item,
}) : super(key: key);
final Item item;
@override
_TodoItemTileState createState() => _TodoItemTileState();
}
class _TodoItemTileState extends State<_TodoItemTile> {
void _onChanged(bool? val) {
setState(() {
widget.item.completed = val;
});
}
@override
Widget build(BuildContext context) {
return ListTile(
leading: Checkbox(
onChanged: _onChanged,
value: widget.item.completed,
),
title: Text(widget.item.description),
);
}
}