//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.dart'; import 'networking.dart'; import 'login.dart'; import 'schuelerzeitung.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: const CircularProgressIndicator( backgroundColor: Colors.black, ), ), ListTile( title: const Text("Einstellungen"), onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => Settings()), ); }, leading: const Icon(CupertinoIcons.settings), ), 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), ), AboutListTile( child: const Text("Info"), icon: const Icon(CupertinoIcons.info), applicationVersion: "0.6.5-alpha", applicationIcon: Image.asset("assets/images/meincantor_r.png", height: 64, width: 64), applicationName: "MeinCantor", aboutBoxChildren: const [ Text( "MeinCantor ist die Schulplatform für Schüler des Georg-Cantor-Gymnasiums in Halle (Saale)."), Divider(), Text("Copyright © 2021 Denys Konovalov") ], // applicationIcon: Image., ), ], ); var bottomNavBarItems = [ const BottomNavigationBarItem( icon: Icon(CupertinoIcons.home), label: "Startseite", ), const BottomNavigationBarItem( icon: Icon(CupertinoIcons.rectangle_grid_1x2), label: "Vertretungsplan"), ]; 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), ), Row(mainAxisSize: MainAxisSize.max, children: [ Expanded( child: Padding( padding: const EdgeInsets.fromLTRB(20, 20, 20, 10), child: Column( children: [ 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, children: [ Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Icon( CupertinoIcons.news, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Align( alignment: Alignment(0, 0), child: Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 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: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Icon( CupertinoIcons.book, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 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, 10, 10), child: Icon( CupertinoIcons.device_laptop, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 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, 10, 10), child: Icon( CupertinoIcons.house_alt, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: const [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 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: 2, child: Scaffold( appBar: AppBar( elevation: 0, title: const TabBar( tabs: [ Tab( text: "Heute", icon: Icon(CupertinoIcons.calendar_today), ), Tab( text: "Neuster Plan", icon: Icon(CupertinoIcons.calendar), ), /*Tab( text: "Archiv", icon: Icon(CupertinoIcons.archivebox), ),*/ ], ), ), body: TabBarView( children: [ buildTodayClassTimetable(), buildClassTimetable(), /* Center( child: Text("It's sunny here"), ), */ ], ), ), ), ), ); }); } else { return const Text("Such page does not exist."); } // return materialCard(item.label); } }