general code cleanup

This commit is contained in:
Denys Konovalov 2021-11-19 20:12:42 +01:00
parent 223414559e
commit 649e226c66
9 changed files with 76 additions and 288 deletions

@ -33,11 +33,10 @@ class DevSettings extends StatelessWidget {
final snackBar = SnackBar(
content:
Text('Neuer API-Schlüssel gesetzt: $apiKey'));
// Find the ScaffoldMessenger in the widget tree
// and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
})),
}
)
),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
@ -49,8 +48,10 @@ class DevSettings extends StatelessWidget {
);
},
child: const Text("Benutzerdaten neu laden"),
))
)
)
],
));
)
);
}
}

@ -27,11 +27,9 @@ class InfoSettings extends StatelessWidget {
isScrollControlled: true,
context: context,
builder: (BuildContext context) {
return Container(
return SizedBox(
height: 400,
//color: Colors.amber,
child: Column(
//mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AppBar(
@ -41,10 +39,6 @@ class InfoSettings extends StatelessWidget {
padding: EdgeInsets.all(10),
child: Text(""),
),
/*ElevatedButton(
child: const Text('Close BottomSheet'),
onPressed: () => Navigator.pop(context),
)*/
],
),
);

@ -111,68 +111,6 @@ class _PlanSettingsState extends State<PlanSettings> {
return (const Center(child: CircularProgressIndicator()));
}
}),
/*FutureBuilder(
future: buildPlanColors("Mat"),
builder: (context, snapshot) {
if (snapshot.hasData) {
Color color = snapshot.data as Color;
return ListTile(
leading: ColorButton(
key: const Key('c1'),
color: color,
//boxShape: BoxShape.circle, // default : circle
config: const ColorPickerConfig(enableEyePicker: false),
onSwatchesChanged: (Set<Color> value) {
swatches = value;
},
size: 32,
swatches: swatches,
onColorChanged: (Color value) async {
setState(() {
color = value;
});
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt("colorMat", value.value);
}
),
title: const Text("Mathematik"),
);
} else {
return (const Center(child: CircularProgressIndicator()));
}
}
),
FutureBuilder(
future: buildPlanColors("Bio"),
builder: (context, snapshot) {
if (snapshot.hasData) {
Color color = snapshot.data as Color;
return ListTile(
leading: ColorButton(
key: const Key('c1'),
color: color,
//boxShape: BoxShape.circle, // default : circle
config: const ColorPickerConfig(enableEyePicker: false),
onSwatchesChanged: (Set<Color> value) {
swatches = value;
},
size: 32,
swatches: swatches,
onColorChanged: (Color value) async {
setState(() {
color = value;
});
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt("colorBio", value.value);
}
),
title: const Text("Biologie"),
);
} else {
return (const Center(child: CircularProgressIndicator()));
}
}
),*/
],
));
}

@ -36,7 +36,10 @@ class UserSettings extends StatelessWidget {
image: DecorationImage(
fit: BoxFit.scaleDown,
image:
AssetImage("assets/images/meincantor_r.png")))),
AssetImage("assets/images/meincantor_r.png")
)
)
),
),
FutureBuilder(
future: getSettingsString("name"),
@ -59,6 +62,7 @@ class UserSettings extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(5, 20, 5, 5),
child: buildClassesChooser()),
],
));
)
);
}
}

@ -174,6 +174,11 @@ class _DashboardBottomNavView extends StatelessWidget {
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 15, minute: 10))) {
lessonCount = 9;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 15, minute: 10)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 16, minute: 00))) {
lessonCount = 10;
} else {
lessonCount = -1;
}

@ -25,7 +25,7 @@ class Login extends StatelessWidget {
builder: (context, constraints) {
double widgetWidth = constraints.maxWidth;
//double widgetHeight = constraints.maxHeight;
var factor;
int factor;
if (widgetWidth <= 600) {
factor = 1;
@ -33,6 +33,8 @@ class Login extends StatelessWidget {
factor = 2;
} else if (widgetWidth <= 2000) {
factor = 3;
} else {
factor = 4;
}
return Scaffold(
@ -93,15 +95,6 @@ class Login extends StatelessWidget {
obscureText: true,
controller: otpController,
),
/*const Divider(),
TextField(
decoration: const InputDecoration(
icon: Icon(CupertinoIcons.device_laptop),
border: OutlineInputBorder(),
labelText: 'Gerätebezeichnung',
),
controller: devIdController,
),*/
const Divider(),
OutlinedButton(
onPressed: () async {
@ -115,7 +108,6 @@ class Login extends StatelessWidget {
if (loginResponse.statusCode == 200) {
String apiKey = jsonDecode(utf8.decode(
loginResponse.bodyBytes))['token'];
print('Set new API key to $apiKey');
await prefs.setString('api_key', apiKey);
dynamic userinfo = jsonDecode(
await getUserInfo(
@ -136,9 +128,6 @@ class Login extends StatelessWidget {
String text = loginResponse.body;
final snackBar = SnackBar(
content: Text('Fehler: $text'));
// Find the ScaffoldMessenger in the widget tree
// and use it to show a SnackBar.
ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
}
@ -159,7 +148,11 @@ class Login extends StatelessWidget {
child: const Text("Anmelden"))
],
),
)))));
)
)
)
)
);
},
);
}

@ -11,12 +11,8 @@ import 'package:MeinCantor/login.dart';
import 'package:MeinCantor/main.dart';
Future<http.Response> getArticles() async {
print("hjkl0");
var uri = Uri.https(szUrl["url"]!, "/articles");
print(uri.toString());
final response = await http.get(uri);
print("hji");
print(response);
return (response);
}
@ -25,7 +21,6 @@ Future<http.Response> getToken(
var uri = Uri.https("mein.cantorgymnasium.de", "/login");
String body =
'{"user":"$user", "password": "$password", "otp": "$otp", "devid": "$devId"}';
print(uri);
final response = await http.post(uri, body: body);
return (response);
}
@ -35,7 +30,6 @@ Future<String> getUserInfo(
var uri = Uri.https("mein.cantorgymnasium.de", "/api/userinfo");
String body =
'{"user":"$user", "password": "$password", "otp": "$otp", "devid": "$devId"}';
print(uri);
final response = await http.post(uri, body: body);
if (response.statusCode == 200) {
@ -45,29 +39,26 @@ Future<String> getUserInfo(
}
}
Future<http.Response> fetchClassTimetable() async {
Future<http.Response> fetchClassTimetable(String ext) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String classNum;
print(prefs.getString('class_num'));
if (prefs.getString('class_num') != null) {
classNum = prefs.getString('class_num')!.replaceAll("/", "_");
} else {
classNum = '05_1';
}
var apiKey = prefs.getString('api_key');
var uri = Uri.https("mein.cantorgymnasium.de", "/api/timetable/$classNum");
var uri = Uri.https("mein.cantorgymnasium.de", "/api/timetable/$classNum$ext");
var headers = {"x-api-key": "$apiKey"};
print(uri);
final response = http.get(uri, headers: headers).onError((error, stackTrace) {
return (http.Response("", 404));
});
return response;
}
Future<http.Response> fetchTodayClassTimetable() async {
/*Future<http.Response> fetchTodayClassTimetable() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String classNum;
print(prefs.getString('class_num'));
if (prefs.getString('class_num') != null) {
classNum = prefs.getString('class_num')!.replaceAll("/", "_");
} else {
@ -77,7 +68,6 @@ Future<http.Response> fetchTodayClassTimetable() async {
var uri =
Uri.https("mein.cantorgymnasium.de", "/api/timetable/$classNum/today");
var headers = {"x-api-key": "$apiKey"};
print(uri);
final response = http.get(uri, headers: headers).onError((error, stackTrace) {
return (http.Response("", 404));
});
@ -87,7 +77,6 @@ Future<http.Response> fetchTodayClassTimetable() async {
Future<http.Response> fetchTomorrowClassTimetable() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String classNum;
print(prefs.getString('class_num'));
if (prefs.getString('class_num') != null) {
classNum = prefs.getString('class_num')!.replaceAll("/", "_");
} else {
@ -97,12 +86,11 @@ Future<http.Response> fetchTomorrowClassTimetable() async {
var uri =
Uri.https("mein.cantorgymnasium.de", "/api/timetable/$classNum/tomorrow");
var headers = {"x-api-key": "$apiKey"};
print(uri);
final response = http.get(uri, headers: headers).onError((error, stackTrace) {
return (http.Response("", 404));
});
return response;
}
}*/
fetchLessonList() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
@ -127,101 +115,20 @@ fetchLessonList() async {
}
Widget buildClassTimetable() {
return FutureBuilder<http.Response>(
future: fetchClassTimetable(),
builder: (context, snapshot) {
if (snapshot.hasData) {
int statusCode = snapshot.data!.statusCode;
if (statusCode == 200) {
Widget timetableView = ClassTimetableBuilder.buildView(
jsonDecode(utf8.decode(snapshot.data!.bodyBytes)), context)
.view
.child;
return timetableView;
} else if (statusCode == 400) {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => Login()));
} else if (statusCode == 500) {
return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
child: Text("Es konnte kein Vertretungsplan gefunden werden.")),
);
} else if (statusCode == 404) {
return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
child: Text(
"Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internetverbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support.")),
);
}
return Center(child: Text('Error $statusCode'));
} else if (snapshot.hasError) {
return Text('$snapshot.error');
} else {
return const Center(child: CircularProgressIndicator());
}
},
);
return buildTimetable(fetchClassTimetable(""), "aktueller Vertretungsplan");
}
Widget buildTodayClassTimetable() {
return FutureBuilder<http.Response>(
future: fetchTodayClassTimetable(),
builder: (context, snapshot) {
if (snapshot.hasData) {
int statusCode = snapshot.data!.statusCode;
if (statusCode == 200) {
Widget timetableView = ClassTimetableBuilder.buildView(
jsonDecode(utf8.decode(snapshot.data!.bodyBytes)), context)
.view
.child;
return timetableView;
} else if (statusCode == 400) {
Navigator.push(
context, MaterialPageRoute(builder: (context) => Login()));
} else if (statusCode == 500) {
var chars = Runes(
'Es konnte kein Vertretungsplan für heute gefunden werden. \u{1F937}');
List<Widget> cardChildren = [];
cardChildren.add(ListTile(
title: Text(String.fromCharCodes(chars),
style: const TextStyle(color: Palette.primary)),
));
Card card = Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
color: Colors.white,
child: Column(
children: cardChildren,
));
return Padding(
padding: EdgeInsets.fromLTRB(20, 20, 20, 20),
child: ListView(
children: [card],
));
} else if (statusCode == 404) {
return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
child: Text(
"Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internetverbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support.")),
);
}
return Center(child: Text('Error $statusCode'));
} else if (snapshot.hasError) {
return Text('$snapshot.error');
} else {
return const Center(child: CircularProgressIndicator());
}
},
);
return buildTimetable(fetchClassTimetable("/today"), "Vertretungsplan für heute");
}
Widget buildTomorrowClassTimetable() {
return buildTimetable(fetchClassTimetable("/tomorrow"), "Vertretungsplan für morgen");
}
Widget buildTimetable(Future<http.Response> future, String info) {
return FutureBuilder<http.Response>(
future: fetchTomorrowClassTimetable(),
future: future,
builder: (context, snapshot) {
if (snapshot.hasData) {
int statusCode = snapshot.data!.statusCode;
@ -236,7 +143,7 @@ Widget buildTomorrowClassTimetable() {
context, MaterialPageRoute(builder: (context) => Login()));
} else if (statusCode == 500) {
var chars = Runes(
'Es konnte kein Vertretungsplan für morgen gefunden werden. \u{1F937}');
'Es konnte kein $info gefunden werden. \u{1F937}');
List<Widget> cardChildren = [];
cardChildren.add(ListTile(
title: Text(String.fromCharCodes(chars),
@ -251,54 +158,18 @@ Widget buildTomorrowClassTimetable() {
children: cardChildren,
));
return Padding(
padding: EdgeInsets.fromLTRB(20, 20, 20, 20),
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
child: ListView(
children: [card],
));
/*return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(child: Text("Es konnte kein Vertretungsplan für heute gefunden werden.")),
);*/
} else if (statusCode == 404) {
return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
child: Text(
"Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internetverbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support.")),
);
}
return Center(child: Text('Error $statusCode'));
} else if (snapshot.hasError) {
return Text('$snapshot.error');
} else {
return const Center(child: CircularProgressIndicator());
}
},
);
}
Widget buildClassTimetableLesson(int count) {
return FutureBuilder<http.Response>(
future: fetchClassTimetable(),
builder: (context, snapshot) {
if (snapshot.hasData) {
int statusCode = snapshot.data!.statusCode;
if (statusCode == 200) {
List<Widget> lessons = LessonsListBuilder.buildList(
jsonDecode(utf8.decode(snapshot.data!.bodyBytes)),
count: count)
.lessons;
return Column(children: lessons);
} else if (statusCode == 400) {
Navigator.push(
context, MaterialPageRoute(builder: (context) => Login()));
} else if (statusCode == 500) {
var chars = Runes(
'Es konnte kein Vertretungsplan für gefunden werden. \u{1F937}');
'Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internet-Verbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support. \u{1F4e1}');
List<Widget> cardChildren = [];
cardChildren.add(ListTile(
title: Text(String.fromCharCodes(chars),
style: const TextStyle(color: Palette.primary))));
style: const TextStyle(color: Palette.primary)),
));
Card card = Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
@ -307,17 +178,11 @@ Widget buildClassTimetableLesson(int count) {
child: Column(
children: cardChildren,
));
return card;
/*return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(child: Text("Es konnte kein Vertretungsplan gefunden werden.")),
);*/
} else if (statusCode == 404) {
return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
child: Text(
"Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internetverbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support")),
return Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
child: ListView(
children: [card],
)
);
}
return Center(child: Text('Error $statusCode'));
@ -332,7 +197,7 @@ Widget buildClassTimetableLesson(int count) {
Widget buildTodayClassTimetableLesson(int count) {
return FutureBuilder<http.Response>(
future: fetchTodayClassTimetable(),
future: fetchClassTimetable("/today"),
builder: (context, snapshot) {
if (snapshot.hasData) {
int statusCode = snapshot.data!.statusCode;
@ -383,16 +248,27 @@ Widget buildTodayClassTimetableLesson(int count) {
children: cardChildren,
));
return card;
/*return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(child: Text("Es konnte kein Vertretungsplan für heute gefunden werden.")),
);*/
} else if (statusCode == 404) {
return const Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Center(
child: Text(
"Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internetverbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support")),
var chars = Runes(
'Keine Verbindung mit dem MeinCantor-Server möglich. Bitte prüfe deine Internet-Verbindung und deine DNS-Einstellungen oder wende dich an den MeinCantor-Support. \u{1F4e1}');
List<Widget> cardChildren = [];
cardChildren.add(ListTile(
title: Text(String.fromCharCodes(chars),
style: const TextStyle(color: Palette.primary)),
));
Card card = Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
color: Colors.white,
child: Column(
children: cardChildren,
));
return Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
child: ListView(
children: [card],
)
);
}
return Center(child: Text('Error $statusCode'));
@ -410,7 +286,6 @@ Future<http.Response> fetchClassesList() async {
var apiKey = prefs.getString('api_key');
var uri = Uri.https("mein.cantorgymnasium.de", "/api/classes");
var headers = {"x-api-key": "$apiKey"};
print(uri);
final response = http.get(uri, headers: headers).onError((error, stackTrace) {
return (http.Response("", 404));
});
@ -498,7 +373,6 @@ class _ClassesChooserState extends State<ClassesChooser> {
dropdownValue = newValue!;
SharedPreferences prefs = await SharedPreferences.getInstance();
String classNum = newValue;
print('Set new class to $classNum');
await prefs.setString('class_num', classNum);
});
},

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:MeinCantor/networking.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:http/http.dart' as http;
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
@ -89,40 +90,17 @@ class Article {
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
children: [
ListTile(
leading: Icon(MdiIcons.accountOutline),
leading: const Icon(MdiIcons.accountOutline),
title: Text(author),
),
ListTile(
leading: Icon(MdiIcons.calendarOutline),
leading: const Icon(MdiIcons.calendarOutline),
title: Text("${DateTime.parse(publishDate).day.toString()}.${DateTime.parse(publishDate).month.toString()}.${DateTime.parse(publishDate).year.toString()}"),
),
Text(content)
MarkdownBody(data: content)
],
)
)
);
}
//@override
/*Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
"Schülersprecherwahl 2021: Kandidatenduos im Interview"),
centerTitle: true,
),
body: ListView(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
children: const [
Text("""
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer
""")
],
));
}*/
}

@ -41,6 +41,7 @@ dependencies:
flutter_colorpicker: ^0.6.0
material_design_icons_flutter: ^5.0.5955-rc.1
cyclop: ^0.5.2
flutter_markdown: ^0.6.8
flutter_icons:
# image_path: "assets/images/icon-128x128.png"