This repository has been archived on 2023-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
meincantor-app/lib/timetable.dart
Denys Konovalov bae624dd67 ==0.6.5==
- added A LOT, TLTD
- TODO:
  - update README
  - update license & copyright info
  - cleanup code
  - merge code parts to server side
  - add more settings
  - fix 11/12
  - add more timetable options
  - add timetable additional info
  - muuuuuuuch more...
2021-09-14 20:55:58 +02:00

262 lines
7.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class ClassTimetableBuilder {
final ListView view;
ClassTimetableBuilder({required this.view});
factory ClassTimetableBuilder.buildView(Map<String, dynamic> json) {
return ClassTimetableBuilder(
view: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: LessonsListBuilder.buildList(json).lessons));
}
}
class LessonsListBuilder {
final List<Widget> lessons;
LessonsListBuilder({required this.lessons});
factory LessonsListBuilder.buildList(Map<String, dynamic> json, {int count: 0}) {
List<Widget> children = [];
ClassTimetable.fromJson(json).timetable.forEach((element) {
List<Widget> cardChildren = [];
print(element.count.toString() + " " + count.toString());
if (element.count.toString() == count.toString() || count == 0) {
print("teeee");
cardChildren.add(ListTile(
title: Text(element.count.toString() + '.' + ' ' + element.name,
style: TextStyle(color: element.fontColor)),
subtitle: Row(children: [
Icon(CupertinoIcons.person, color: element.fontColor),
const SizedBox(width: 5),
Text(element.teacher, style: TextStyle(color: element.fontColor)),
const Spacer(),
Icon(CupertinoIcons.home, color: element.fontColor),
const SizedBox(width: 5),
Text(element.room, style: TextStyle(color: element.fontColor))
]),
leading: Icon(CupertinoIcons.time, color: element.fontColor)));
if (element.info != '') {
cardChildren.add(ListTile(
title: Text(element.info,
style: TextStyle(color: element.fontColor))));
}
Card card = Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
color: element.color,
child: Column(
children: cardChildren,
));
children.add(card);
}
});
return LessonsListBuilder(lessons: children);
}
}
class ClassTimetable {
final List timetable;
ClassTimetable({required this.timetable});
factory ClassTimetable.fromJson(Map<String, dynamic> json) {
print(json);
List<TimetableLesson> lessons = [];
json['courses'].forEach((value) {
var name;
var teacher;
var room;
dynamic teachers = {
'Poli': 'Herr Polity',
'Zura': 'Frau Zuralski',
'Enzi': 'Frau Enzian',
'Bütt': 'Frau Büttner',
'Brod': 'Herr Brode',
'Rink': 'Frau Rinke',
'Schk': 'Frau Schmidt',
'Rudo': 'Frau Rudolph',
'Kipp': 'Frau Kipping',
'Bach': 'Frau Bachran',
'Bad': 'Herr Bader',
'Prei': 'Frau Preiß',
'Scha': 'Frau Schapitz',
'&nbsp;': '',
'Link': 'Herr Linke',
'Stei': 'Herr Stein',
'Tupp': 'Frau Tuppack',
'Hoff': 'Frau Hoffman',
'Knol': 'Frau Knoll',
'Bet': 'Frau Bethin',
'Schu': 'Frau Schulz',
'Seid': 'Frau Seidel',
'Krug': 'Frau Krug',
'Laer': 'Frau Langer',
'Youn': 'Frau Younso',
'Härt': 'Frau Härtig',
'Bros': 'Frau Brosig',
'Ber': 'Frau Bernhardt',
'Stüb': 'Frau Stüber',
'Bor': 'Frau Borchert',
'Dubb': 'Frau Dubberstein',
'Tren': 'Frau Trentsch',
'Meit': 'Herr Meitzner',
'Stol': 'Frau Stolpe',
'Jac': 'Frau Jacob',
'Jüne': 'Herr Jünemann',
'Bert': 'Frau Berthelmann',
'Felk': 'Frau Felke',
'Kimm': 'Herr Kimmel',
'PM1': 'Pädagosische(r) Mitarbeiter(in) 1',
'Schet': 'Herr Schetler',
'Mani': 'Herr Manigk',
'Segg': 'Frau Seggern',
'Opel': 'Frau Opel-Fritzler',
'Möll': 'Frau Möller',
'Laen': 'Herr Langen',
'Plin': 'Herr Plinke',
'Koch': 'Herr Koch',
'Gors': 'Herr Gorsler',
'Krau': 'Herr Krause',
'Henk': 'Frau Henke',
'Wolf': 'Herr Wolf'
};
if (value['Fa'].runtimeType != String) {
name = value['Fa']['#text'];
} else {
name = value['Fa'];
}
if (value['Le'].runtimeType != String) {
teacher = value['Le']['#text'];
} else {
teacher = value['Le'];
}
print(value['Ra']);
if (value['Ra'].runtimeType != String && value['Ra'].runtimeType != int) {
if (value['Ra']['#text'] == '&nbsp;') {
room = '';
} else if (value['Ra']['#text'] == null) {
room = '';
} else {
room = value['Ra']['#text'];
}
} else if (value['Ra'] == '&nbsp;') {
room = '';
} else {
room = value['Ra'];
}
Color fontColor;
if (name == '---') {
fontColor = Colors.red;
} else {
fontColor = Colors.white;
}
var info;
if (value['If'].runtimeType != String) {
info = '';
} else {
info = value['If'];
}
dynamic colors = {
'Bio': Colors.green,
'Mat': Colors.indigo,
'matL1': Colors.indigo,
'matL2': Colors.indigo,
'matL3': Colors.indigo,
'Deu': Colors.red,
'deu1': Colors.red,
'deu2': Colors.red,
'deu3': Colors.red,
'Kun': Colors.deepPurple,
'kun1': Colors.deepPurple,
'kun2': Colors.deepPurple,
'kun3': Colors.deepPurple,
'Geo': Colors.brown,
'Lat': Colors.teal,
'lat1': Colors.teal,
'lat2': Colors.teal,
'lat3': Colors.teal,
'Che': Colors.lightGreen,
'Eng': Colors.amber,
'eng1': Colors.amber,
'eng2': Colors.amber,
'eng3': Colors.amber,
'Phy': Colors.cyan,
'phy1': Colors.cyan,
'phy2': Colors.cyan,
'phy3': Colors.cyan,
'Inf': Colors.tealAccent[400],
'Mus': Colors.deepOrange,
'mus1': Colors.deepOrange,
'mus2': Colors.deepOrange,
'mus3': Colors.deepOrange,
'Lme': Colors.amber[700],
'Ges': Colors.grey,
'ges1': Colors.grey,
'ges2': Colors.grey,
'ges3': Colors.grey,
'Spa': Colors.redAccent,
'Frz': Colors.amberAccent[700],
'frz1': Colors.amberAccent[700],
'---': Colors.white
};
dynamic names = {
'Bio': 'Biologie',
'Mat': 'Mathematik',
'matL1': 'Mathematik Leistungskurs 1',
'Kun': 'Kunst',
'Mus': 'Musik',
'Geo': 'Geographie',
'Ges': 'Geschichte',
'Che': 'Chemie',
'Lat': 'Latein',
'Inf': 'Informatik',
'Eng': 'Englisch',
'Frz': 'Französisch',
'frz1': 'Französisch 1',
'Phy': 'Physik',
'---': '---',
'Spo': 'Sport',
'Deu': 'Deutsch',
'deu1': 'Deutsch 1',
'deu2': 'Deutsch 2',
'deu3': 'Deutsch 3',
'Lme': 'Lernmethoden',
'Eth': 'Ethik',
'EvR': 'Evangelische Religion',
'Soz': 'Sozialkunde',
'Ast': 'Astronomie',
'Spa': 'Spanisch',
'FK': 'Fachkurs',
'JIA': 'Junior-Ingenieur-Akademie',
'WoU': 'Wahlobligatorischer Unterricht'
};
lessons.add(TimetableLesson(
value['St'],
names[name] ?? name.toString(),
teachers[teacher] ?? teacher.toString(),
room.toString(),
value['If'].toString(),
colors[name] ?? Colors.grey[700],
fontColor,
info));
});
return ClassTimetable(timetable: lessons);
}
}
class TimetableLesson {
final int count;
final String name;
final String teacher;
final String room;
final String comment;
final Color color;
final Color fontColor;
final String info;
const TimetableLesson(this.count, this.name, this.teacher, this.room,
this.comment, this.color, this.fontColor, this.info);
}