1
1
import 'dart:convert' ;
2
2
import 'dart:io' ;
3
- import 'dart:math' ;
4
3
5
4
import 'package:barcode_scan/barcode_scan.dart' ;
6
5
import 'package:http/http.dart' as http;
@@ -52,6 +51,8 @@ class ClassTableState extends State<ClassTable> {
52
51
borderRadius: BorderRadius .circular (5 ),
53
52
side: BorderSide (color: Colors .black87)
54
53
);
54
+ final classButtonPadding = EdgeInsets .symmetric (vertical: 5 );
55
+ final dayColumnPadding = EdgeInsets .symmetric (horizontal: 5 );
55
56
56
57
Class currentClass;
57
58
Map <String , List <Class >> classes = Map ();
@@ -62,6 +63,8 @@ class ClassTableState extends State<ClassTable> {
62
63
Widget build (BuildContext context) {
63
64
currentClass = null ;
64
65
66
+ final now = DateTime .now ();
67
+
65
68
return Scaffold (
66
69
appBar: AppBar (
67
70
title: Text ('TimeTable' ),
@@ -92,12 +95,12 @@ class ClassTableState extends State<ClassTable> {
92
95
]
93
96
),
94
97
body: SingleChildScrollView (
95
- child: Column (children : [
96
- Row ( children: createColumnsForTable (context, DateTime . now () ),
98
+ child: Row (
99
+ children: this .classes.keys. map ((k) => createColumnForDay (k, now)). toList ( ),
97
100
mainAxisAlignment: MainAxisAlignment .spaceEvenly,
98
- crossAxisAlignment: CrossAxisAlignment .start)
99
- ]
100
- ))
101
+ crossAxisAlignment: CrossAxisAlignment .start
102
+ )
103
+ )
101
104
);
102
105
}
103
106
@@ -184,8 +187,18 @@ class ClassTableState extends State<ClassTable> {
184
187
}
185
188
186
189
void updateClassListFromBackend (String id) async {
190
+ showDialog (
191
+ context: context,
192
+ child: AlertDialog (
193
+ title: Text ('Szinkronizálás' ),
194
+ contentPadding: EdgeInsets .all (16 ),
195
+ content: Text ('Szinkronizálás a felhővel folyamatban' )
196
+ )
197
+ );
187
198
final backendResponse = await http.get ('$backendURL ?id=$id ' , headers: { 'Content-Type' : 'application/json' });
188
199
200
+ Navigator .pop (context);
201
+
189
202
if (backendResponse.statusCode == 200 ) {
190
203
this .hasLocalID = true ;
191
204
@@ -197,6 +210,21 @@ class ClassTableState extends State<ClassTable> {
197
210
};
198
211
199
212
this .settingsFile.writeAsStringSync (jsonEncode (fileContent));
213
+ }else {
214
+ showDialog (
215
+ context: context,
216
+ child: AlertDialog (
217
+ title: Text ('Hiba' ),
218
+ contentPadding: EdgeInsets .all (16 ),
219
+ content: Text ("Nem sikerült lekérni az órarendet ehhez az azonosítóhoz: \n '$id '" ),
220
+ actions: [
221
+ RaisedButton (
222
+ child: Text ('Vissza' ),
223
+ onPressed: () => Navigator .pop (context)
224
+ )
225
+ ]
226
+ )
227
+ );
200
228
}
201
229
}
202
230
@@ -214,31 +242,32 @@ class ClassTableState extends State<ClassTable> {
214
242
return classesObject;
215
243
}
216
244
217
- List <Column > createColumnsForTable (BuildContext context, DateTime now) {
218
- return this .classes.keys.map ((k) => Column (children: createButtonsForColumn (k, context, now)))
219
- .toList ();
245
+ Widget createColumnForDay (String day, DateTime now) {
246
+ return Expanded (
247
+ child: Padding (
248
+ padding: dayColumnPadding,
249
+ child: Column (
250
+ crossAxisAlignment: CrossAxisAlignment .stretch,
251
+ children: createButtonsForColumn (day, now)
252
+ )
253
+ )
254
+ );
220
255
}
221
256
222
- List <Widget > createButtonsForColumn (String day, BuildContext context, DateTime now) {
223
- List <Widget > result = List ();
257
+ List <Widget > createButtonsForColumn (String day, DateTime now) {
258
+ final result = List <Widget >();
259
+
224
260
result.add (RaisedButton (
225
261
onPressed: () => {},
226
262
shape: buttonShape,
227
263
child: Text (day)
228
264
));
229
265
230
- result.add (SizedBox (height: 15 ));
231
-
232
- final currentClasses = this .classes[day];
233
- for (var i = 0 ; i < currentClasses.length; ++ i) {
234
- result.add (createClassButton (currentClasses[i], now, i, context));
235
- result.add (SizedBox (height: 10 ));
236
- }
237
-
266
+ this .classes[day].forEach ((k) => result.add (createClassButton (k, now)));
238
267
return result;
239
268
}
240
269
241
- Widget createClassButton (Class clazz, DateTime now, int index, BuildContext context ) {
270
+ Widget createClassButton (Class clazz, DateTime now) {
242
271
final today = dayList[now.weekday - 1 ];
243
272
final isToday = clazz.day == today;
244
273
final isBefore = isToday && now.isBefore (clazz.startTime);
@@ -254,11 +283,17 @@ class ClassTableState extends State<ClassTable> {
254
283
'Típus: ${clazz .type }\n ' +
255
284
'Terem: ${clazz .room }' ;
256
285
257
- return RaisedButton (
258
- onPressed: () => {},
259
- shape: buttonShape,
260
- child: Text (buttonText, style: TextStyle (color: clazz.unImportant ? lightGray : Colors .black)),
261
- color: clazz.unImportant ? unimportantClassColor : isNext ? currentClassColor : isBefore ? upcomingClassColor : isAfter ? pastClassColor : otherDayClassColor
286
+ return Padding (
287
+ padding: classButtonPadding,
288
+ child: RaisedButton (
289
+ onPressed: () => {},
290
+ shape: buttonShape,
291
+ child: Padding (
292
+ padding: classButtonPadding,
293
+ child: Text (buttonText, style: TextStyle (color: clazz.unImportant ? lightGray : Colors .black))
294
+ ),
295
+ color: clazz.unImportant ? unimportantClassColor : isNext ? currentClassColor : isBefore ? upcomingClassColor : isAfter ? pastClassColor : otherDayClassColor
296
+ )
262
297
);
263
298
}
264
299
}
@@ -276,7 +311,7 @@ class Class {
276
311
this .day = jsonData['day' ],
277
312
this .startTime = parseTimeFrom (jsonData['startTime' ], now),
278
313
this .endTime = parseTimeFrom (jsonData['endTime' ], now),
279
- this .name = jsonData['name' ]. substring ( 0 , min (jsonData[ 'name' ].length as int , 15 )) ,
314
+ this .name = jsonData['name' ],
280
315
this .type = jsonData['type' ],
281
316
this .room = jsonData['room' ],
282
317
this .unImportant = jsonData['unImportant' ];
0 commit comments