diff --git a/lib/controllers/user_controller.dart b/lib/controllers/user_controller.dart index a7282b9..46ed1b5 100644 --- a/lib/controllers/user_controller.dart +++ b/lib/controllers/user_controller.dart @@ -22,28 +22,6 @@ class UserController extends GetxController { final loadedUser = await loadUserFromDisk(); if (loadedUser != null) { - // login(user.value!.admissionNumber, user.value!.password).then((value) { - // value.fold((l) { - // HapticFeedback.heavyImpact().then( - // (value) { - // Get.rawSnackbar( - // messageText: Text( - // l, - // textAlign: TextAlign.center, - // style: const TextStyle( - // color: Colors.white, - // ), - // ), - // duration: const Duration(days: 1), - // isDismissible: true, - // snackPosition: SnackPosition.TOP, - // backgroundColor: Colors.red[400]!, - // icon: const Icon(Ionicons.flash_outline, color: Colors.white), - // ); - // }, - // ); - // }, (r) {}); - // }); user.value = loadedUser; isLoggedIn.value = true; } diff --git a/lib/exports/barrel.dart b/lib/exports/barrel.dart index 8a8afbd..1a8f8c8 100644 --- a/lib/exports/barrel.dart +++ b/lib/exports/barrel.dart @@ -5,8 +5,6 @@ export 'package:ionicons/ionicons.dart'; export 'package:academia/controllers/notifications_controller.dart'; export 'package:percent_indicator/percent_indicator.dart'; export 'package:academia/controllers/settings_controller.dart'; -export 'package:academia/pages/home_page.dart'; -export 'package:academia/pages/intro_page.dart'; export 'package:academia/themes/theme.dart'; export 'package:magnet/magnet.dart'; export 'package:screenshot/screenshot.dart'; @@ -18,13 +16,6 @@ export 'package:academia/controllers/dashboard_controller.dart'; export 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; export 'package:academia/tools/exam_timetable/exams_timetable_page.dart'; export 'package:academia/tools/fees/fees_page.dart'; -export 'package:academia/pages/pdf_viewer.dart'; -export 'package:academia/pages/webview_page.dart'; -export 'package:academia/pages/courses_page.dart'; -export 'package:academia/pages/dashboard.dart'; -export 'package:academia/pages/settings_page.dart'; -export 'package:academia/pages/tool_page.dart'; -export 'package:academia/pages/login_page.dart'; export 'package:flutter_pdfview/flutter_pdfview.dart'; export 'package:academia/widgets/info_card.dart'; export 'package:cached_network_image/cached_network_image.dart'; @@ -35,3 +26,6 @@ export 'package:academia/controllers/controllers.dart'; export 'package:awesome_notifications/awesome_notifications.dart'; export 'package:academia/tools/todo/todo.dart'; export 'package:academia/tools/tools.dart'; + +// academia core pages +export '../pages/pages.dart'; diff --git a/lib/main.dart b/lib/main.dart index aec102e..5ebb431 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -48,7 +48,7 @@ class Academia extends StatelessWidget { Get.put(RewardController()); Get.put(CoursesController()); - // Prompt for permission + // Prompt for notification permission AwesomeNotifications().isNotificationAllowed().then( (value) { if ((!value) && (Platform.isAndroid || Platform.isIOS)) { @@ -82,35 +82,10 @@ class Academia extends StatelessWidget { } }, ); - - return FutureBuilder( - future: userController.loadUserFromDisk(), - builder: (context, snapshot) { - if (snapshot.connectionState != ConnectionState.done) { - return Scaffold( - body: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Image.asset( - "assets/icons/academia.png", - height: 200, - ), - const SizedBox(height: 22), - Text( - "Let the past die, kill it if you have to ~ The Last Jedi", - style: Theme.of(context).textTheme.titleLarge, - textAlign: TextAlign.center, - ), - ], - ), - ), - ); - } - return snapshot.hasData ? const HomePage() : const IntroPage(); - }, + return Obx( + () => userController.isLoggedIn.value + ? const LayoutPage() + : const IntroPage(), ); } } diff --git a/lib/pages/auth/auth.dart b/lib/pages/auth/auth.dart new file mode 100644 index 0000000..6d6f482 --- /dev/null +++ b/lib/pages/auth/auth.dart @@ -0,0 +1,2 @@ +export 'login_page.dart'; +export 'register_page.dart'; diff --git a/lib/pages/login_page.dart b/lib/pages/auth/login_page.dart similarity index 98% rename from lib/pages/login_page.dart rename to lib/pages/auth/login_page.dart index a80ac52..5eca24d 100644 --- a/lib/pages/login_page.dart +++ b/lib/pages/auth/login_page.dart @@ -1,5 +1,4 @@ import 'package:academia/exports/barrel.dart'; -import 'package:academia/pages/register_page.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:lottie/lottie.dart'; @@ -51,7 +50,7 @@ class _LoginPageState extends State { if (userController.isLoggedIn.value) { Navigator.of(context).pushReplacement( MaterialPageRoute( - builder: (context) => const HomePage(), + builder: (context) => const LayoutPage(), ), ); return; diff --git a/lib/pages/register_page.dart b/lib/pages/auth/register_page.dart similarity index 99% rename from lib/pages/register_page.dart rename to lib/pages/auth/register_page.dart index 9ab237b..a413db4 100644 --- a/lib/pages/register_page.dart +++ b/lib/pages/auth/register_page.dart @@ -45,7 +45,7 @@ class _RegisterPageState extends State { }); Navigator.of(context).pushReplacement( MaterialPageRoute( - builder: (context) => const HomePage(), + builder: (context) => const LayoutPage(), ), ); return; diff --git a/lib/pages/courses/courses.dart b/lib/pages/courses/courses.dart new file mode 100644 index 0000000..d32fade --- /dev/null +++ b/lib/pages/courses/courses.dart @@ -0,0 +1 @@ +export 'courses_page.dart'; diff --git a/lib/pages/courses_page.dart b/lib/pages/courses/courses_page.dart similarity index 100% rename from lib/pages/courses_page.dart rename to lib/pages/courses/courses_page.dart diff --git a/lib/pages/dashboard.dart b/lib/pages/dashboard.dart index c0197d3..10948d7 100644 --- a/lib/pages/dashboard.dart +++ b/lib/pages/dashboard.dart @@ -25,15 +25,17 @@ class DashBoard extends StatelessWidget { floating: false, snap: false, ), - SliverVisibility( - visible: storyController.stories.isNotEmpty, - sliver: const SliverToBoxAdapter( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - HomeScreenStoryWidget(), - ], + Obx( + () => SliverVisibility( + visible: storyController.stories.isNotEmpty, + sliver: const SliverToBoxAdapter( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + HomeScreenStoryWidget(), + ], + ), ), ), ), diff --git a/lib/pages/home_page.dart b/lib/pages/layout_page.dart similarity index 75% rename from lib/pages/home_page.dart rename to lib/pages/layout_page.dart index de29d52..663c095 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/layout_page.dart @@ -2,27 +2,30 @@ import 'package:academia/exports/barrel.dart'; import 'package:academia/pages/profile_page.dart'; import 'package:get/get.dart'; -class HomePage extends StatefulWidget { - const HomePage({super.key}); +class LayoutPage extends StatefulWidget { + const LayoutPage({super.key}); @override - State createState() => _HomePageState(); + State createState() => _LayoutPageState(); } -class _HomePageState extends State { +class _LayoutPageState extends State { int currentIndex = 0; - final pages = const [ - DashBoard(), - ToolsPage(), - CoursesPage(), - ProfilePage(), - ]; @override Widget build(BuildContext context) { Get.put(StoryController()); + return Scaffold( body: SafeArea( - child: IndexedStack(index: currentIndex, children: pages), + child: IndexedStack( + index: currentIndex, + children: const [ + DashBoard(), + ToolsPage(), + CoursesPage(), + ProfilePage(), + ], + ), ), bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, diff --git a/lib/pages/pages.dart b/lib/pages/pages.dart new file mode 100644 index 0000000..fdf76dc --- /dev/null +++ b/lib/pages/pages.dart @@ -0,0 +1,10 @@ +export 'dashboard.dart'; +export 'layout_page.dart'; +export 'profile_page.dart'; +export 'settings_page.dart'; +export 'tool_page.dart'; + +// Supporting pages +export 'auth/auth.dart'; +export 'courses/courses.dart'; +export 'util_pages/util_pages.dart'; diff --git a/lib/pages/profile_page.dart b/lib/pages/profile_page.dart index eef1863..c34697e 100644 --- a/lib/pages/profile_page.dart +++ b/lib/pages/profile_page.dart @@ -1,7 +1,6 @@ import 'package:academia/exports/barrel.dart'; -import 'package:academia/pages/membership_pages.dart'; -import 'package:get/get.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:get/get.dart'; class ProfilePage extends StatelessWidget { const ProfilePage({super.key}); diff --git a/lib/pages/intro_page.dart b/lib/pages/util_pages/intro_page.dart similarity index 100% rename from lib/pages/intro_page.dart rename to lib/pages/util_pages/intro_page.dart diff --git a/lib/pages/membership_pages.dart b/lib/pages/util_pages/membership_pages.dart similarity index 100% rename from lib/pages/membership_pages.dart rename to lib/pages/util_pages/membership_pages.dart diff --git a/lib/pages/pdf_viewer.dart b/lib/pages/util_pages/pdf_viewer.dart similarity index 100% rename from lib/pages/pdf_viewer.dart rename to lib/pages/util_pages/pdf_viewer.dart diff --git a/lib/pages/util_pages/util_pages.dart b/lib/pages/util_pages/util_pages.dart new file mode 100644 index 0000000..9709732 --- /dev/null +++ b/lib/pages/util_pages/util_pages.dart @@ -0,0 +1,4 @@ +export 'intro_page.dart'; +export 'membership_pages.dart'; +export 'pdf_viewer.dart'; +export 'webview_page.dart'; diff --git a/lib/pages/webview_page.dart b/lib/pages/util_pages/webview_page.dart similarity index 100% rename from lib/pages/webview_page.dart rename to lib/pages/util_pages/webview_page.dart