-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathlostandfoundfeedpage.dart
More file actions
370 lines (353 loc) · 14.6 KB
/
Copy pathlostandfoundfeedpage.dart
File metadata and controls
370 lines (353 loc) · 14.6 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import 'package:InstiApp/src/api/model/lostandfoundPost.dart';
import 'package:InstiApp/src/bloc_provider.dart';
import 'package:InstiApp/src/blocs/lost_and_found_bloc.dart';
import 'package:InstiApp/src/drawer.dart';
import 'package:InstiApp/src/utils/common_widgets.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import '../api/model/lostandfoundPost.dart';
import '../utils/title_with_backbutton.dart';
class LostNFoundPage extends StatefulWidget {
LostNFoundPage({Key? key}) : super(key: key);
//final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
@override
State<LostNFoundPage> createState() => _LostNFoundPageState();
}
class _LostNFoundPageState extends State<LostNFoundPage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: LostPage(),
);
}
}
class LostPage extends StatefulWidget {
const LostPage({Key? key}) : super(key: key);
@override
State<LostPage> createState() => _LostpageState();
}
class _LostpageState extends State<LostPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
lnFType lnftype = lnFType.All;
bool firstBuild = true;
@override
void initState() {
super.initState();
}
Widget build(BuildContext context) {
LostAndFoundPostBloc lnFPostBloc =
BlocProvider.of(context)!.bloc.lostAndFoundPostBloc;
if (firstBuild) {
lnFPostBloc.refresh();
}
double screen_wr = MediaQuery.of(context).size.width;
double screen_hr = MediaQuery.of(context).size.height;
double x, y;
var bloc = BlocProvider.of(context)!.bloc;
var theme = Theme.of(context);
bool isLoggedIn = bloc.currSession != null;
screen_hr >= screen_wr ? x = 0.35 : x = 0.80;
if (1 >= screen_hr / screen_wr && screen_hr / screen_wr >= 0.5) {
x = 0.35;
}
screen_hr >= screen_wr ? y = 0.9 : y = 0.5;
double screen_w = screen_wr * y;
double screen_h = screen_hr * x;
double myfont = ((18 / 274.4) * screen_h);
return Scaffold(
key: _scaffoldKey,
drawer: NavDrawer(),
bottomNavigationBar: MyBottomAppBar(
shape: RoundedNotchedRectangle(),
notchMargin: 4.0,
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
Icons.menu_outlined,
semanticLabel: "Show navigation drawer",
),
onPressed: () {
_scaffoldKey.currentState?.openDrawer();
},
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton: FloatingActionButton.extended(
icon: Icon(Icons.info),
label: Text("Info"),
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text('How to use Lost and Found'),
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'If you find a lost item:',
style: TextStyle(fontWeight: FontWeight.w600),
),
Text(
'Give the item to the nearest security office \n'),
Text(
'If you want to claim your lost item:',
style: TextStyle(fontWeight: FontWeight.w600),
),
Text(
'Use the contact details provided to claim your item\n'),
Text(
'Only the security offices can post items on Lost and Found, students can only claim items and report lost items to the security offices'),
],
)),
actions: <Widget>[
Center(
child: TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'OK',
style: TextStyle(color: Colors.white),
),
style: TextButton.styleFrom(
backgroundColor: Colors.lightBlue),
),
)
])),
),
body: SafeArea(
child: !isLoggedIn
? Container(
alignment: Alignment.center,
padding: EdgeInsets.all(50),
child: Column(
children: [
Icon(
Icons.cloud,
size: 200,
color: Colors.grey[600],
),
Text(
"Login To View Lost and Found Posts",
style: theme.textTheme.headline5,
textAlign: TextAlign.center,
)
],
crossAxisAlignment: CrossAxisAlignment.center,
),
)
: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TitleWithBackButton(
child: Text(
"Lost & Found (Beta)",
style: theme.textTheme.headline4,
),
),
StreamBuilder<List<LostAndFoundPost>>(
stream: lnFPostBloc.lostAndFoundPosts,
builder: (BuildContext context,
AsyncSnapshot<List<LostAndFoundPost>> snapshot) {
if (snapshot.data?.length != 0) {
return ListView.builder(
primary: false,
shrinkWrap: true,
itemCount: snapshot.data?.length ?? 0,
itemBuilder: (_, index) {
if (!snapshot.hasData) {
return Center(
child:
CircularProgressIndicatorExtended(
label: Text("Loading..."),
));
}
return _buildContent(screen_h, screen_w,
index, myfont, context, snapshot);
},
);
}
return Center(
child: Text(
'No posts \n have been added yet',
style: TextStyle(
fontSize: 25.0,
color: Colors.grey[600],
fontWeight: FontWeight.w300),
textAlign: TextAlign.center,
),
);
}),
],
))));
}
Widget _buildContent(double screen_h, double screen_w, int index,
double myfont, BuildContext context, AsyncSnapshot snapshot) {
List<LostAndFoundPost> posts = snapshot.data!;
var theme = Theme.of(context);
return Center(
child: (SizedBox(
height: screen_h * 0.7,
width: screen_w * 1.2,
child: Container(
child: Stack(alignment: Alignment.center, children: [
Card(
color: theme.cardColor,
margin: EdgeInsets.symmetric(horizontal: 25, vertical: 10),
child: InkWell(
onTap: () {
Navigator.of(context).pushNamed(
"/lostandfound/info" + (posts[index].id ?? ""));
},
child: SizedBox(
child: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
topLeft: Radius.circular(10)),
child: Row(
children: [
Center(
child: Container(
padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
height: screen_h,
width: screen_h * 0.20 / 0.43,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10)),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
topLeft: Radius.circular(10)),
child: CachedNetworkImage(
imageUrl: posts[index].imageUrl?[0] ?? '',
placeholder: (context, url) => Image.asset(
'assets/buynsell/DevcomLogo.png',
fit: BoxFit.fill,
),
errorWidget: (context, url, error) =>
new Image.asset(
'assets/buynsell/DevcomLogo.png',
fit: BoxFit.fill,
),
fit: BoxFit.cover,
),
),
),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
margin: EdgeInsets.fromLTRB(
screen_h * 0.20 / 0.43, 11, 0, 50),
child: Text(
posts[index].name ?? "",
style: theme.textTheme.headline6,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
Container(
margin: EdgeInsets.fromLTRB(
screen_h * 0.20 / 0.43, 105, 10, 0),
child: Text(
(posts[index].foundAt ?? "").length <= 10
? posts[index].foundAt ?? ""
: (posts[index].foundAt ?? "").substring(0, 10) +
'...',
style: theme.textTheme.bodyText2,
maxLines: 1,
),
),
Container(
margin: EdgeInsets.fromLTRB(
screen_w * 0.7, 110, screen_h * 0.04 / 1.5, 1),
child: Row(
children: [
Spacer(),
Text(
(posts[index].claimed == true
? "Claimed"
: "Not\nclaimed"),
style: theme.textTheme.bodyText1,
textAlign: TextAlign.center,
)
],
)),
Container(
// child: MyPosts
// ? Container()
child: Row(children: [
Icon(
Icons.access_time,
size: ((myfont / 18 * 12).toInt()).toDouble(),
),
Text(' ' + (posts[index].timeBefore ?? ""),
style: theme.textTheme.bodyText1!.copyWith(
fontWeight: FontWeight.bold,
))
]),
margin: EdgeInsets.fromLTRB(
screen_h * 0.20 / 0.43, 135, 0, 0),
),
Container(
margin: EdgeInsets.fromLTRB(
screen_h * 0.20 / 0.43, 35, 0, 0)),
Container(
padding: EdgeInsets.fromLTRB(0, 13, 10, 0),
child: Text(
(posts[index].description ?? ""),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyText2,
),
margin: EdgeInsets.fromLTRB(
screen_h * 0.20 / 0.43, 43, 0, 0)),
Row(
children: [
Spacer(),
Container(),
],
)
],
)),
),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.blue),
),
),
if (posts[index].claimed == true)
Container(
width: screen_w * 0.15,
height: screen_w * 0.15,
decoration: new BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
if (posts[index].claimed == true)
Container(
child: Icon(
Icons.check,
color: Colors.white,
size: screen_w * 0.15,
)),
]),
),
)),
);
}
}