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/dashboard.dart

457 lines
16 KiB
Dart
Raw Normal View History

import 'package:MeinCantor/raumuebersicht.dart';
import 'package:MeinCantor/schulbibliothek.dart';
import 'package:MeinCantor/schulcomputer.dart';
import 'package:MeinCantor/schuelerzeitung.dart';
import 'package:MeinCantor/Settings/dashboard.dart';
import 'package:MeinCantor/main.dart';
import 'package:MeinCantor/networking.dart';
import 'package:MeinCantor/login.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
class Dashboard extends StatefulWidget {
const Dashboard({Key? key, this.restorationId}) : super(key: key);
final String? restorationId;
@override
State<StatefulWidget> createState() => _DashboardState();
}
Future<String> getSettingsString(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? value = prefs.getString(key);
if (value == null || value.isEmpty) {
value = "";
}
return value;
}
Widget buildSettingsString(String key, TextStyle? style) {
return FutureBuilder(
future: getSettingsString(key),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(snapshot.data as String, style: style);
} else {
return (const Center(child: CircularProgressIndicator()));
}
});
}
class _DashboardState extends State<Dashboard> with RestorationMixin {
final RestorableInt _currentIndex = RestorableInt(0);
@override
Widget build(BuildContext context) {
final drawerElements = ListView(
children: [
UserAccountsDrawerHeader(
accountName: buildSettingsString('name', const TextStyle()),
accountEmail: buildSettingsString('user', const TextStyle()),
currentAccountPicture:
Image.asset("assets/images/meincantor_r.png")),
ListTile(
title: const Text("Einstellungen"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Settings()),
);
},
leading: const Icon(Icons.settings_outlined),
),
ListTile(
title: const Text("Abmelden"),
onTap: () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('api_key', "");
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => Login()),
);
},
leading: const Icon(Icons.exit_to_app_outlined),
),
],
);
var bottomNavBarItems = [
const BottomNavigationBarItem(
icon: Icon(MdiIcons.homeOutline),
label: "Startseite",
),
const BottomNavigationBarItem(
icon: Icon(MdiIcons.timetable), label: "Vertretungsplan"),
const BottomNavigationBarItem(
icon: Icon(Icons.notifications_outlined), label: "Hinweise"),
];
return Scaffold(
appBar: AppBar(
title: const Text("GCG.MeinCantor"),
centerTitle: true,
),
body: _DashboardBottomNavView(
key: UniqueKey(), item: bottomNavBarItems[_currentIndex.value]),
drawer: Drawer(
child: drawerElements,
),
bottomNavigationBar: BottomNavigationBar(
showUnselectedLabels: false,
items: bottomNavBarItems,
currentIndex: _currentIndex.value,
onTap: (index) {
setState(() {
_currentIndex.value = index;
});
},
),
);
}
@override
String? get restorationId => widget.restorationId;
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(_currentIndex, 'bottom_navigation_tab_index');
}
}
class _DashboardBottomNavView extends StatelessWidget {
const _DashboardBottomNavView({Key? key, required this.item})
: super(key: key);
final BottomNavigationBarItem item;
@override
Widget build(BuildContext context) {
if (item.label == "Startseite") {
double _timeOfDayToDouble(TimeOfDay tod) => tod.hour + tod.minute / 60.0;
int lessonCount;
if (_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 7, minute: 30))) {
lessonCount = 1;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 7, minute: 30)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 8, minute: 20))) {
lessonCount = 2;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 8, minute: 20)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 9, minute: 25))) {
lessonCount = 3;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 9, minute: 25)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 10, minute: 15))) {
lessonCount = 4;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 10, minute: 15)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 11, minute: 30))) {
lessonCount = 5;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 11, minute: 30)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 12, minute: 20))) {
lessonCount = 6;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 12, minute: 20)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 13, minute: 30))) {
lessonCount = 7;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 13, minute: 30)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 14, minute: 20))) {
lessonCount = 8;
} else if (_timeOfDayToDouble(TimeOfDay.now()) >
_timeOfDayToDouble(const TimeOfDay(hour: 14, minute: 20)) &&
_timeOfDayToDouble(TimeOfDay.now()) <=
_timeOfDayToDouble(const TimeOfDay(hour: 15, minute: 10))) {
lessonCount = 9;
2021-11-19 20:12:42 +01:00
} 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;
}
var view = SingleChildScrollView(
child: Column(children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 30, 20, 5),
child: Text(
'Hallo,',
style: GoogleFonts.robotoSlab(
fontSize: 20,
),
),
),
],
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 5, 20, 20),
child: buildSettingsString(
"name",
GoogleFonts.robotoSlab(
fontSize: 28,
fontWeight: FontWeight.w800,
),
),
)
],
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 10, 0, 10),
child: Text(
'Deine nächste Unterrichtsstunde:',
style: GoogleFonts.robotoSlab(
fontSize: 20,
fontWeight: FontWeight.w100,
),
),
)
],
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 10),
child: buildTodayClassTimetableLesson(lessonCount),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 10),
child: Wrap(
children: [
SizedBox(
child: GestureDetector(
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SZ()),
);
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: const Padding(
padding: EdgeInsets.all(10),
child: ListTile(
title: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Icon(
MdiIcons.newspaper,
color: Palette.accent,
size: 48,
),
),
subtitle: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Text(
'Schülerzeitung',
),
),
),
),
)),
),
width: 175,
),
SizedBox(
width: 175,
child: GestureDetector(
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SB()),
);
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: const Padding(
padding: EdgeInsets.all(10),
child: ListTile(
title: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Icon(
MdiIcons.libraryShelves,
color: Palette.accent,
size: 48,
),
),
subtitle: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Text(
'Schulbibliothek',
),
),
),
),
)),
),
),
SizedBox(
width: 175,
child: GestureDetector(
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SC()),
);
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: const Padding(
padding: EdgeInsets.all(10),
child: ListTile(
title: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Icon(
MdiIcons.laptop,
color: Palette.accent,
size: 48,
),
),
subtitle: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Text(
'Schulcomputer',
),
),
),
),
)),
),
),
SizedBox(
width: 175,
child: GestureDetector(
onTap: () async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const RoomOverview()),
);
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: const Padding(
padding: EdgeInsets.all(10),
child: ListTile(
title: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Icon(
MdiIcons.door,
color: Palette.accent,
size: 48,
),
),
subtitle: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Text(
'Raumübersicht',
),
),
),
),
)),
),
)
],
),
),
]),
);
return view;
} else if (item.label == "Vertretungsplan") {
return LayoutBuilder(builder: (context, constraints) {
double widgetWidth = constraints.maxWidth;
int factor;
if (widgetWidth <= 600) {
factor = 1;
} else if (widgetWidth <= 1400) {
factor = 2;
} else if (widgetWidth <= 2000) {
factor = 3;
} else {
factor = 1;
}
// print(screenType);
return Center(
child: Container(
constraints: BoxConstraints(
// minHeight: 500, //minimum height
// minWidth: 300, // minimum width
//maximum height set to 100% of vertical height
maxWidth: MediaQuery.of(context).size.width / factor,
//maximum width set to 100% of width
),
child: DefaultTabController(
initialIndex: 0,
length: 3,
child: Scaffold(
appBar: AppBar(
elevation: 0,
title: const TabBar(
tabs: <Widget>[
Tab(
text: "Heute",
icon: Icon(CupertinoIcons.calendar_today),
),
Tab(
text: "Morgen",
icon: Icon(CupertinoIcons.calendar_today),
),
Tab(
text: "Neuster Plan",
icon: Icon(CupertinoIcons.calendar),
),
],
),
),
body: TabBarView(
children: <Widget>[
buildTodayClassTimetable(),
buildTomorrowClassTimetable(),
buildClassTimetable(),
],
),
),
),
),
);
});
} else {
return const Center(child: Text("Derzeit nichts hier..."));
}
}
}