-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed_screen.dart
233 lines (220 loc) · 7.89 KB
/
feed_screen.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
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
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:snappable/snappable.dart';
import 'package:retrotrack/core/index.dart';
import 'package:retrotrack/ui/index.dart';
class FeedScreen extends StatelessWidget {
const FeedScreen();
@override
Widget build(BuildContext context) {
return Scaffold(
body: RetroBody(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Logo(
color: Colors.black,
bgColor: Theme.of(context).primaryColor,
),
Expanded(
child: ScrollConfiguration(
behavior: const NoneScrollBehavior(),
child: Consumer<FeedProvider>(
builder: (_, FeedProvider feed, __) {
if (feed.isLoading) {
return const Center(child: Text('LOADING...'));
} else {
if (feed.list.isEmpty) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('NO ENTRY'),
RetroOutlineButton(
text: 'Refresh',
onPressed: () async => feed.refresh(),
),
],
),
);
}
return RefreshIndicator(
onRefresh: () async {
feed.refresh();
},
child: ListView.separated(
itemCount: feed.list.length,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (_, int index) {
return _LogDisplay(
feed.list[feed.list.length - index - 1],
);
},
),
);
}
},
),
),
)
],
),
),
floatingActionButton: const _FAB(),
);
}
}
class _LogDisplay extends StatelessWidget {
const _LogDisplay(this.log);
final LogEntry log;
@override
Widget build(BuildContext context) {
const Duration snapDuration = Duration(seconds: 4);
final GlobalKey<SnappableState> key = GlobalKey<SnappableState>();
final FeedProvider feed = Provider.of<FeedProvider>(context);
return Padding(
padding: const EdgeInsets.all(8),
child: Snappable(
key: key,
duration: snapDuration,
child: GestureDetector(
onLongPress: () async {
final bool res = await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (_) => _DeleteDialog(),
);
if (res) {
key.currentState.snap().then((_) async {
await Future<void>.delayed(snapDuration);
feed.removeFromList(log);
});
}
},
child: InkWell(
onTap: () {},
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.green[300],
border: Border.all(
width: 3.0,
color: Colors.green[300],
),
),
child:
Image.file(File(log.photoUrl), fit: BoxFit.fitWidth),
),
),
VerticalDivider(
color: Theme.of(context).primaryColor.withOpacity(0.75),
width: 16,
),
Expanded(
flex: 2,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: log.people.map(
(Person p) {
bool danger = false;
if (p.temperature != null &&
p.temperature.temperature != null)
danger = p.temperature.temperature >= 37.5;
return Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.green[300],
border: Border.all(
width: 2.0,
color: Colors.green[300],
),
),
child: Image.file(File(p.photoUrl),
height: 40),
),
const Spacer(),
Text(
'${p.temperature.temperature}°C',
style: !danger
? Theme.of(context)
.textTheme
.headline6
: Theme.of(context)
.textTheme
.headline5
.copyWith(
color: const Color(0xFFD2001E),
),
),
if (danger)
const Padding(
padding: EdgeInsets.only(left: 8),
child: FlareDanger(),
),
],
),
const Divider(
thickness: 2.0,
),
],
);
},
).toList(),
),
),
),
],
),
),
),
),
),
);
}
}
class _FAB extends StatelessWidget {
const _FAB();
@override
Widget build(BuildContext context) {
return FloatingActionButton.extended(
onPressed: () {
Navigator.pushNamed(context, '/camera');
},
label: const Text('ENTRY'),
icon: const Icon(Icons.add),
);
}
}
class _DeleteDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text(
'REMOVE RECORD',
textAlign: TextAlign.center,
),
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
RetroOutlineButton(
text: 'no',
onPressed: () => Navigator.pop(context, false),
),
RetroOutlineButton(
text: 'yes',
onPressed: () => Navigator.pop(context, true),
),
],
),
);
}
}