//import 'package:MeinCantor/timetable.dart'; //import 'package:MeinCantor/main.dart'; import 'package:MeinCantor/raumuebersicht.dart'; import 'package:MeinCantor/schulbibliothek.dart'; import 'package:MeinCantor/schulcomputer.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 'Settings/dashboard.dart'; // import 'settings.dart'; import 'main.dart'; import 'networking.dart'; import 'login.dart'; import 'schuelerzeitung.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 createState() => _DashboardState(); } Future getSettingsString(String key) async { SharedPreferences prefs = await SharedPreferences.getInstance(); String? value = prefs.getString(key); if (value == null || value.isEmpty) { value = ""; } print(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 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") /*const CircularProgressIndicator( backgroundColor: Colors.black, ),*/ ), ListTile( title: const Text("Einstellungen"), onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => 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; }); //print(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; var 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; } else { lessonCount = -1; } /* Widget timetable; if (_timeOfDayToDouble(TimeOfDay.now()) > _timeOfDayToDouble(const TimeOfDay(hour: , minute: 55))) { timetable = buildClassTimetable(); } else { timetable = buildTodayClassTimetable(); } */ print(lessonCount); 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', ), ), ), ), ) ), ), ) /*GestureDetector( onTap: () async { Navigator.push( context, MaterialPageRoute(builder: (context) => const SZ()), ); }, child: Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: [ Row( //mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 20, 10), child: Icon( MdiIcons.newspaper, color: Palette.accent, size: 48, ), ) ], ), Row( //mainAxisSize: MainAxisSize.max, children: const [ Align( alignment: Alignment(0, 0), child: Padding( padding: EdgeInsets.fromLTRB(15, 50, 15, 15), child: Text( 'Schülerzeitung', ), ), ), ], ) ], ), ), ), GestureDetector( onTap: () async { Navigator.push( context, MaterialPageRoute(builder: (context) => const SB()), ); }, child: Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Center( child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 20, 10), child: Icon( MdiIcons.libraryShelves, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 15, 15), child: Text( 'Schulbibliothek', ), ) ], ) ], ), ) ), ), GestureDetector( onTap: () async { Navigator.push( context, MaterialPageRoute(builder: (context) => const SC()), ); }, child: Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 20, 10), child: Icon( MdiIcons.laptop, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 15, 15), child: Text( 'Schulcomputer', ), ) ], ) ], ), ), ), GestureDetector( onTap: () async { Navigator.push( context, MaterialPageRoute(builder: (context) => const RoomOverview()), ); }, child: Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 20, 10), child: Icon( MdiIcons.door, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 15, 15), child: Text( 'Raumübersicht', ), ) ], ) ], ), ), ),*/ ], ), ), ]), ); return view; } else if (item.label == "Vertretungsplan") { return LayoutBuilder(builder: (context, constraints) { double widgetWidth = constraints.maxWidth; // double widgetHeight = constraints.maxHeight; var factor; if (widgetWidth <= 600) { factor = 1; } else if (widgetWidth <= 1400) { factor = 2; } else if (widgetWidth <= 2000) { factor = 3; } // 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: [ Tab( text: "Heute", icon: Icon(CupertinoIcons.calendar_today), ), Tab( text: "Morgen", icon: Icon(CupertinoIcons.calendar_today), ), Tab( text: "Neuster Plan", icon: Icon(CupertinoIcons.calendar), ), /*Tab( text: "Archiv", icon: Icon(CupertinoIcons.archivebox), ),*/ ], ), ), body: TabBarView( children: [ buildTodayClassTimetable(), buildTomorrowClassTimetable(), buildClassTimetable(), ], ), ), ), ), ); }); } else { return const Center(child: Text("Derzeit nichts hier...")); } } }