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'; 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 = await 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(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', TextStyle()), accountEmail: buildSettingsString('user', TextStyle()), currentAccountPicture: const CircularProgressIndicator(backgroundColor: Colors.black,), ), ListTile( title: Text("Einstellungen"), onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => Settings()), ); }, leading: Icon(CupertinoIcons.settings), ), ListTile( title: Text("Abmelden"), onTap: () async { SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString('api_key', ""); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => Login()), ); }, leading: Icon(Icons.exit_to_app_outlined), ), AboutListTile( child: Text("Info"), icon: Icon(CupertinoIcons.info), applicationVersion: "0.5.0-alpha1", applicationIcon: Image.asset("assets/images/meincantor_r.png", height: 64, width: 64), applicationName: "MeinCantor", aboutBoxChildren: [ 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 = [ BottomNavigationBarItem( icon: const Icon(CupertinoIcons.home), label: "Startseite", ), BottomNavigationBarItem(icon: const Icon(CupertinoIcons.rectangle_grid_1x2), label: "Vertretungsplan"), ]; return Scaffold( appBar: AppBar( title: 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 { _DashboardBottomNavView({ Key? key, required this.item }) : super(key:key); final BottomNavigationBarItem item; @override Widget build(BuildContext context) { return materialCard(item.label); } Widget materialCard(String? label) { if (label == "Startseite") { var view = SingleChildScrollView( child: Column( children: [ Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 30, 20, 5), child: Text( 'Hallo,', style: GoogleFonts.robotoSlab( fontSize: 20, ), ), ), ], ), Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 5, 20, 20), child: buildSettingsString("name", GoogleFonts.robotoSlab( fontSize: 28, fontWeight: FontWeight.w800, ), ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 10, 0, 10), child: Text( 'Deine nächste Unterrichtsstunde:', style: GoogleFonts.robotoSlab( fontSize: 20, fontWeight: FontWeight.w100, ), ), ) ], ), Padding( padding: EdgeInsets.fromLTRB(20, 20, 20, 10), child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15.0), ), color: Colors.red, child: Column( children: [ListTile( title: Text('3' + '.' + ' ' + 'Deutsch', style: TextStyle(color: Colors.white)), subtitle: Row( children: [Icon(CupertinoIcons.person, color: Colors.white), SizedBox(width: 5), Text("Herr Jünemann", style: TextStyle(color: Colors.white)), Spacer(), Icon(CupertinoIcons.home, color: Colors.white), SizedBox(width: 5), Text("106", style: TextStyle(color: Colors.white))] ), leading: Icon(CupertinoIcons.time, color: Colors.white) )], ) ), ), Row( mainAxisSize: MainAxisSize.max, children: [ Expanded( child: Padding( padding: EdgeInsets.fromLTRB(20, 20, 20, 10), child: Column( children: [ Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Icon( CupertinoIcons.news, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: [ Align( alignment: Alignment(0, 0), child: Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 15), child: Text( 'Schülerzeitung', ), ), ), ], ) ], ), ), Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Icon( CupertinoIcons.book, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 15), child: Text( 'Schulbibliothek', ), ) ], ) ], ), ), Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Icon( CupertinoIcons.device_laptop, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 15), child: Text( 'Schulcomputer', ), ) ], ) ], ), ), Card( clipBehavior: Clip.antiAliasWithSaveLayer, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Column( mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Icon( CupertinoIcons.house_alt, color: Color(0xFFFFBC3B), size: 48, ), ) ], ), Row( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.fromLTRB(15, 50, 0, 15), child: Text( 'Raumübersicht', ), ) ], ) ], ), ) ], ), ), ) ] ), ], ) ); return view; } else if (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: buildClassTimetable(), ), ); } ); } else { return Text("Such page does not exist."); } } }