diff --git a/lib/home.dart b/lib/home.dart index 7944c71..1bd8792 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -20,9 +20,13 @@ import 'package:url_launcher/url_launcher.dart'; class HomePage extends StatefulWidget { final SessionManager sessionManager; final Function reLogin; + final ValueChanged onDestinationSelected; const HomePage( - {super.key, required this.sessionManager, required this.reLogin}); + {super.key, + required this.sessionManager, + required this.reLogin, + required this.onDestinationSelected}); @override State createState() => HomePageState(); @@ -317,9 +321,13 @@ class HomePageState extends State { final response = await dio .get( 'https://api.github.com/repos/DislikesSchool/EduPage2/releases/latest') - .catchError((r) { + .catchError((obj) { return Response( - requestOptions: RequestOptions(path: r.path), statusCode: 500); + requestOptions: RequestOptions( + path: + 'https://api.github.com/repos/DislikesSchool/EduPage2/releases/latest'), + statusCode: 500, + ); }); if (response.statusCode == 500) { return; @@ -489,30 +497,35 @@ class HomePageState extends State { children: [ for (Map lesson in apidataTT["lessons"]) - Card( - child: Padding( - padding: const EdgeInsets.all(10), - child: Column( - children: [ - Text( - lesson["period"]["name"] + ".", - style: - const TextStyle(fontSize: 10), - ), - Text( - lesson["subject"]["short"], - style: - const TextStyle(fontSize: 20), - ), - Text( - lesson["classrooms"].length > 0 - ? lesson["classrooms"][0] - ["short"] - : "?", - style: - const TextStyle(fontSize: 14), - ), - ], + GestureDetector( + onTap: () { + widget.onDestinationSelected(1); + }, + child: Card( + child: Padding( + padding: const EdgeInsets.all(10), + child: Column( + children: [ + Text( + lesson["period"]["name"] + ".", + style: + const TextStyle(fontSize: 10), + ), + Text( + lesson["subject"]["short"], + style: + const TextStyle(fontSize: 20), + ), + Text( + lesson["classrooms"].length > 0 + ? lesson["classrooms"][0] + ["short"] + : "?", + style: + const TextStyle(fontSize: 14), + ), + ], + ), ), ), ), @@ -669,12 +682,72 @@ class HomePageState extends State { const Padding( padding: EdgeInsets.only(top: 15), ), + InkWell( + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + child: ListTile( + leading: const Icon(Icons.bolt_rounded), + title: Text(local!.homeQuickstart), + trailing: Transform.scale( + scale: 0.75, + child: Switch( + value: quickstart, + onChanged: (bool value) { + sharedPreferences.setBool('quickstart', value); + setState(() { + quickstart = value; + }); + }, + ), + ), + onTap: () { + sharedPreferences.setBool('quickstart', !quickstart); + setState(() { + quickstart = !quickstart; + }); + }, + ), + ), + /* + const Divider(), + ListTile( + leading: const Icon(Icons.language), + title: const Text('Language'), + trailing: SizedBox( + height: 32, + child: Container( + decoration: BoxDecoration( + border: Border.all(color: Colors.grey), + borderRadius: BorderRadius.circular(4), + ), + padding: const EdgeInsets.symmetric(horizontal: 8), + child: DropdownButton( + value: Localizations.localeOf(context), + onChanged: (Locale? locale) { + if (locale != null) { + // Handle locale selection + } + }, + icon: const Icon(Icons.arrow_drop_down), + underline: Container(), + style: Theme.of(context).textTheme.titleMedium, + items: AppLocalizations.supportedLocales + .map((locale) => DropdownMenuItem( + value: locale, + child: Text(locale.languageCode), + )) + .toList(), + ), + ), + ), + ),*/ + const Divider(), InkWell( highlightColor: Colors.transparent, splashColor: Colors.transparent, child: ListTile( leading: const Icon(Icons.lunch_dining_rounded), - title: Text(local!.homeSetupICanteen), + title: Text(local.homeSetupICanteen), onTap: () { Navigator.push( context, @@ -690,37 +763,6 @@ class HomePageState extends State { }, ), ), - InkWell( - highlightColor: Colors.transparent, - splashColor: Colors.transparent, - child: Badge( - label: Text(local.homePreview), - alignment: AlignmentDirectional.topEnd, - child: ListTile( - leading: const Icon(Icons.bolt_rounded), - title: Text(local.homeQuickstart), - trailing: Transform.scale( - scale: 0.75, - child: Switch( - value: quickstart, - onChanged: (bool value) { - sharedPreferences.setBool('quickstart', value); - setState(() { - quickstart = value; - }); - }, - ), - ), - onTap: () { - sharedPreferences.setBool('quickstart', !quickstart); - setState(() { - quickstart = !quickstart; - }); - }, - ), - ), - ), - const Divider(), InkWell( highlightColor: Colors.transparent, splashColor: Colors.transparent, @@ -735,6 +777,23 @@ class HomePageState extends State { }, ), ), + const Divider(), + InkWell( + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + child: ListTile( + leading: const Icon(Icons.discord), + title: const Text("EduPage2 Discord"), + onTap: () async { + final url = Uri.parse('https://discord.gg/xy5nqWa2kQ'); + if (await canLaunchUrl(url)) { + await launchUrl(url); + } else { + throw 'Could not launch $url'; + } + }, + ), + ), const AboutListTile( icon: Icon(Icons.info_outline), applicationName: 'EduPage2', diff --git a/lib/load.dart b/lib/load.dart index f5a632b..4b1de6e 100644 --- a/lib/load.dart +++ b/lib/load.dart @@ -110,7 +110,11 @@ class LoadingScreenState extends State { progress = 0.5; loaderText = local!.loadLoggedIn; setState(() {}); - sessionManager.set('user', response.data); + if (response.data.runtimeType == Map) { + sessionManager.set('user', jsonEncode(response.data)); + } else { + sessionManager.set('user', response.data); + } return loadTimetable(); } else { failedToken = token; @@ -202,7 +206,11 @@ class LoadingScreenState extends State { progress = 0.6; loaderText = local!.loadLoggedIn; setState(() {}); - sessionManager.set('user', response.data); + if (response.data.runtimeType == Map) { + sessionManager.set('user', jsonEncode(response.data)); + } else { + sessionManager.set('user', response.data); + } return loadTimetable(); } else { runningInit = false; diff --git a/lib/main.dart b/lib/main.dart index 44751d5..aabe0df 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -113,6 +113,12 @@ class PageBaseState extends State { super.setState(fn); } + void _onDestinationSelected(int index) { + setState(() { + _selectedIndex = index; + }); + } + initRemoteConfig() async { final remoteConfig = FirebaseRemoteConfig.instance; await remoteConfig.setConfigSettings(RemoteConfigSettings( @@ -165,12 +171,14 @@ class PageBaseState extends State { index: _selectedIndex, children: [ HomePage( - sessionManager: sessionManager, - reLogin: () { - setState(() { - loaded = false; - }); - }), + sessionManager: sessionManager, + reLogin: () { + setState(() { + loaded = false; + }); + }, + onDestinationSelected: _onDestinationSelected, + ), TimeTablePage( sessionManager: sessionManager, ),