From 46fb5851e7f6ad1385318ad7f7a702c0e86f457f Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Mon, 15 Sep 2025 10:14:20 +0200 Subject: [PATCH] Fix error route --- Frontend/lib/mih_config/mih_go_router.dart | 3 +- .../mih_home/mih_home_legacy.dart | 1317 ----------------- .../mih_home/mih_profile_getter.dart | 281 ---- .../mih_home/mih_route_error.dart | 149 ++ 4 files changed, 151 insertions(+), 1599 deletions(-) delete mode 100644 Frontend/lib/mih_packages/mih_home/mih_home_legacy.dart delete mode 100644 Frontend/lib/mih_packages/mih_home/mih_profile_getter.dart create mode 100644 Frontend/lib/mih_packages/mih_home/mih_route_error.dart diff --git a/Frontend/lib/mih_config/mih_go_router.dart b/Frontend/lib/mih_config/mih_go_router.dart index bbddb323..b3164dac 100644 --- a/Frontend/lib/mih_config/mih_go_router.dart +++ b/Frontend/lib/mih_config/mih_go_router.dart @@ -12,6 +12,7 @@ import 'package:mzansi_innovation_hub/mih_packages/mih_authentication/mih_auth_f import 'package:mzansi_innovation_hub/mih_packages/mih_authentication/mih_auth_password_reset.dart'; import 'package:mzansi_innovation_hub/mih_packages/mih_authentication/mih_authentication.dart'; import 'package:mzansi_innovation_hub/mih_packages/mih_home/mih_home.dart'; +import 'package:mzansi_innovation_hub/mih_packages/mih_home/mih_route_error.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_ai/mzansi_ai.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_directory/mzansi_directory.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profile/mzansi_business_profile.dart'; @@ -473,7 +474,7 @@ class MihGoRouter { // 3. Error handling with `errorBuilder` and `redirect` errorBuilder: (BuildContext context, GoRouterState state) { KenLogger.error('Invalid Route'); - return const Placeholder(); + return const MihRouteError(); }, ); } diff --git a/Frontend/lib/mih_packages/mih_home/mih_home_legacy.dart b/Frontend/lib/mih_packages/mih_home/mih_home_legacy.dart deleted file mode 100644 index b14b7f4a..00000000 --- a/Frontend/lib/mih_packages/mih_home/mih_home_legacy.dart +++ /dev/null @@ -1,1317 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; -// import 'dart:convert'; - -import 'package:flutter_speed_dial/flutter_speed_dial.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/business.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/notification.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/patients.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; -import '../../main.dart'; -import 'package:supertokens_flutter/http.dart' as http; -import "package:universal_html/html.dart" as html; - -import '../../mih_services/mih_location_services.dart'; -import '../../mih_components/mih_layout/mih_action.dart'; -import 'components/mih_app_drawer.dart'; -import '../../mih_components/mih_layout/mih_body.dart'; -import '../../mih_components/mih_layout/mih_header.dart'; -import '../../mih_components/mih_layout/mih_layout_builder.dart'; -import '../../mih_components/mih_layout/mih_notification_drawer.dart'; -import '../../mih_components/mih_layout/mih_tile.dart'; -import '../../mih_components/mih_pop_up_messages/mih_delete_message.dart'; -import '../../mih_components/mih_pop_up_messages/mih_error_message.dart'; -import '../../mih_components/mih_pop_up_messages/mih_loading_circle.dart'; -import '../../mih_components/mih_pop_up_messages/mih_notification_message.dart'; -import '../../mih_components/mih_pop_up_messages/mih_success_message.dart'; -import '../../mih_components/mih_pop_up_messages/mih_warning_message.dart'; -import '../../mih_config/mih_env.dart'; -import '../test/test.dart'; - -// ignore: must_be_immutable -class MIHHomeLegacy extends StatefulWidget { - final AppUser signedInUser; - final BusinessUser? businessUser; - final Business? business; - final Patient? patient; - final List notifications; - final ImageProvider? propicFile; - final bool isUserNew; - final bool isBusinessUser; - final bool isBusinessUserNew; - final bool isDevActive; - bool personalSelected; - MIHHomeLegacy({ - super.key, - required this.signedInUser, - required this.businessUser, - required this.business, - required this.patient, - required this.notifications, - required this.propicFile, - required this.isUserNew, - required this.isBusinessUser, - required this.isBusinessUserNew, - required this.isDevActive, - required this.personalSelected, - }); - - @override - State createState() => _MIHHomeLegacyState(); -} - -class _MIHHomeLegacyState extends State { - final proPicController = TextEditingController(); - final TextEditingController searchController = TextEditingController(); - final FocusNode _focusNode = FocusNode(); - late List persHTList = []; - late List busHTList = []; - late List> pbswitch; - late List notifiList; - late bool businessUserSwitch; - int _selectedIndex = 0; - String appSearch = ""; - int amount = 10; - final baseAPI = AppEnviroment.baseApiUrl; - // final MobileScannerController scannerController = MobileScannerController( - // // required options for the scanner - // ); - - void setAppsNewPersonal(List tileList) { - if (widget.signedInUser.fname == "") { - // tileList.add(MIHTile( - // videoID: "jFV3NN65DtQ", - // onTap: () { - // Navigator.of(context).pushNamed('/mzansi-profile', - // arguments: AppProfileUpdateArguments( - // widget.signedInUser, widget.propicFile)); - // }, - // tileName: "Setup Profie", - // tileIcon: Padding( - // padding: const EdgeInsets.all(15.0), - // child: Image(image: logo), - // ), - // p: getPrim(), - // s: getSec(), - // )); - } - } - - void setAppsNewBusiness(List tileList) { - tileList.add(MIHTile( - videoID: "Nfp4pVBZL78", - onTap: () { - Navigator.of(context).pushNamed( - '/business-profile/set-up', - arguments: widget.signedInUser, - ); - }, - tileName: "Setup Business", - tileIcon: Icon( - Icons.add_business_outlined, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - } - - void setAppsPersonal(List tileList) { - ImageProvider aiLogo = MzansiInnovationHub.of(context)!.theme.aiLogoImage(); - // tileList.add(MIHTile( - // videoID: "P2bM9eosJ_A", - // onTap: () { - // Navigator.of(context).pushNamed( - // '/mzansi-profile', - // arguments: AppProfileUpdateArguments( - // widget.signedInUser, - // widget.propicFile, - // ), - // ); - // }, - // tileName: "Mzansi Profile", - // tileIcon: Padding( - // padding: const EdgeInsets.all(15.0), - // child: Image(image: logo), - // ), - // p: getPrim(), - // s: getSec(), - // )); - tileList.add(MIHTile( - videoID: "6l8h0sjt08k", - onTap: () { - Navigator.of(context).pushNamed( - '/mzansi-wallet', - arguments: widget.signedInUser, - ); - }, - tileName: "Mzansi Wallet", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.wallet, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - // print("Pat Prof: ${widget.patient}"); - if (widget.patient != null) { - tileList.add(MIHTile( - videoID: "NUDdoWrbXNc", - onTap: () { - Navigator.of(context).pushNamed('/patient-profile', - arguments: PatientViewArguments( - widget.signedInUser, null, null, null, "personal")); - }, - tileName: "Patient Profile", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.bookMedical, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.medication, - // color: getSec(), - // size: 200, - // ), - p: getPrim(), - s: getSec(), - )); - } else { - tileList.add(MIHTile( - videoID: "NUDdoWrbXNc", - onTap: () { - Navigator.of(context).pushNamed('/patient-profile/set-up', - arguments: widget.signedInUser); - }, - tileName: "Set Up Patient", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.bookMedical, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.medication, - // color: getSec(), - // size: 200, - // ), - p: getPrim(), - s: getSec(), - )); - } - tileList.add(MIHTile( - videoID: "dYuLqZWzMnM", - onTap: () { - Navigator.of(context).pushNamed( - '/mzansi-ai', - arguments: MzansiAiArguments( - widget.signedInUser, - "", - ), - ); - }, - tileName: "Mzansi AI", - tileIcon: Center( - child: SizedBox( - width: 225, - child: Image(image: aiLogo), - ), - ), - // Icon( - // Icons.medication, - // color: getSec(), - // size: 200, - // ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - videoID: "nfzhJFY_W4Y", - onTap: () { - Navigator.of(context).pushNamed( - '/calendar', - arguments: CalendarArguments( - widget.signedInUser, - true, - widget.business, - null, - ), - ); - }, - tileName: "Calendar", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.calendarDays, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.calendar_month, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "woQ5hND5EaU", - onTap: () { - Navigator.of(context).pushNamed( - '/calculator', - arguments: widget.personalSelected, - ); - }, - tileName: "Calculator", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.calculator, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "", - onTap: () { - Navigator.of(context).pushNamed( - '/mih-access', - arguments: widget.signedInUser, - ); - }, - tileName: "MIH Access", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.userCheck, - color: getSec(), - size: 170, - ), - ), - // Icon( - // Icons.check_box_outlined, - // color: getSec(), - // size: 200, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "hbKhlmY_56U", - onTap: () { - Navigator.of(context).pushNamed( - '/about', - arguments: 0, - ); - }, - tileName: "About MIH", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.circleInfo, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - } - - void setAppsBusiness(List tileList) { - ImageProvider aiLogo = MzansiInnovationHub.of(context)!.theme.aiLogoImage(); - tileList.add(MIHTile( - videoID: "NWyJZq2ZYOM", - onTap: () { - Navigator.of(context).pushNamed( - '/business-profile/manage', - arguments: BusinessArguments( - widget.signedInUser, - widget.businessUser, - widget.business, - ), - ); - }, - tileName: "Biz Profile", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.buildingUser, - color: getSec(), - size: 165, - ), - ), - // Icon( - // Icons.business, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - // tileList.add(MIHTile( - // onTap: () { - // Navigator.of(context).pushNamed( - // '/mih-access', - // arguments: widget.signedInUser, - // ); - // }, - // tileName: "Access", - // tileIcon: Icon( - // Icons.check_box_outlined, - // color: getSec(), - // size: 200, - // ), - // p: getPrim(), - // s: getSec(), - // )); - tileList.add(MIHTile( - videoID: "D6q2qIavoiY", - onTap: () { - Navigator.of(context).pushNamed( - '/patient-manager', - arguments: PatManagerArguments( - widget.signedInUser, - widget.personalSelected, - widget.business, - widget.businessUser, - ), - ); - }, - tileName: "Pat Manager", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.bookMedical, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.medication, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "nfzhJFY_W4Y", - onTap: () { - Navigator.of(context).pushNamed( - '/calendar', - arguments: CalendarArguments( - widget.signedInUser, - false, - widget.business, - widget.businessUser, - ), - ); - }, - tileName: "Calendar", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.calendarDays, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.calendar_month, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "dYuLqZWzMnM", - onTap: () { - Navigator.of(context).pushNamed( - '/mzansi-ai', - arguments: MzansiAiArguments( - widget.signedInUser, - "", - ), - ); - }, - tileName: "Mzansi AI", - tileIcon: Center( - child: SizedBox( - width: 225, - child: Image(image: aiLogo), - ), - ), - // Icon( - // Icons.medication, - // color: getSec(), - // size: 200, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "woQ5hND5EaU", - onTap: () { - Navigator.of(context).pushNamed( - '/calculator', - arguments: widget.personalSelected, - ); - }, - tileName: "Calculator", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.calculator, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - videoID: "hbKhlmY_56U", - onTap: () { - Navigator.of(context).pushNamed( - '/about', - arguments: 0, - ); - }, - tileName: "About MIH", - tileIcon: Center( - child: FaIcon( - FontAwesomeIcons.circleInfo, - color: getSec(), - size: 200, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - } - - void setAppsDev(List tileList) { - if (AppEnviroment.getEnv() == "Dev") { - tileList.add(MIHTile( - videoID: "", - onTap: () { - Navigator.of(context).pushNamed( - '/home-dev', - //arguments: widget.signedInUser, - ); - }, - tileName: "Home - Dev", - tileIcon: Center( - child: Icon( - Icons.warning, - color: getSec(), - size: 230, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - videoID: "", - onTap: () { - Navigator.of(context).pushNamed( - '/package-dev', - //arguments: widget.signedInUser, - ); - }, - tileName: "Package - Dev", - tileIcon: Center( - child: Icon( - Icons.warning, - color: getSec(), - size: 230, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - videoID: "", - onTap: () { - Navigator.of(context).pushNamed( - '/terms-of-service', - //arguments: widget.signedInUser, - ); - }, - tileName: "TOS - Dev", - tileIcon: Center( - child: Icon( - Icons.design_services, - color: getSec(), - size: 230, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - videoID: "", - onTap: () { - Navigator.of(context).pushNamed( - '/privacy-policy', - //arguments: widget.signedInUser, - ); - }, - tileName: "Policy - Dev", - tileIcon: Center( - child: Icon( - Icons.policy, - color: getSec(), - size: 230, - ), - ), - // Icon( - // Icons.info_outline, - // color: getSec(), - // size: 230, - // ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - TextEditingController cardNumberController = TextEditingController(); - Navigator.of(context).pushNamed( - '/scanner', - arguments: cardNumberController, - ); - print(cardNumberController.text); - }, - tileName: "Scanner - Dev", - tileIcon: Icon( - Icons.camera_alt_outlined, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - showDialog( - barrierColor: const Color(0x01000000), - context: context, - builder: (context) { - return const MIHTest(); - }, - ); - }, - tileName: "video - Dev", - tileIcon: Icon( - Icons.video_file, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - showDialog( - barrierColor: const Color(0x01000000), - context: context, - builder: (context) { - return Builder(builder: (context) { - return MIHNotificationMessage( - arguments: NotificationArguments( - "Testing", - "Testing the new MIH Notification", - () { - Navigator.of(context).pop(); - //Scaffold.of(context).openEndDrawer(); - }, - ), - ); - }); - }, - ); - }, - tileName: "Notify - Dev", - tileIcon: Icon( - Icons.notifications, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - showDialog( - context: context, - builder: (context) { - return const Mihloadingcircle(); - }, - ); - }, - tileName: "Loading - Dev", - tileIcon: Icon( - Icons.change_circle, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - Navigator.of(context).pushNamed( - '/business-profile/set-up', - arguments: widget.signedInUser, - ); - }, - tileName: "Setup Bus - Dev", - tileIcon: Icon( - Icons.add_business_outlined, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - Navigator.of(context).pushNamed('/patient-profile/set-up', - arguments: widget.signedInUser); - }, - tileName: "Add Pat - Dev", - tileIcon: Icon( - Icons.add_circle_outline, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - onTap: () { - showDialog( - context: context, - builder: (context) { - // return const MIHWarningMessage(warningType: "No Access"); - return const MIHWarningMessage(warningType: "Expired Access"); - }, - ); - }, - tileName: "Warn - Dev", - tileIcon: Icon( - Icons.warning_amber_rounded, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - showDialog( - context: context, - builder: (context) { - // return const MIHErrorMessage(errorType: "Input Error"); - // return const MIHErrorMessage(errorType: "Password Requirements"); - // return const MIHErrorMessage(errorType: "Invalid Username"); - // return const MIHErrorMessage(errorType: "Invalid Email"); - // return const MIHErrorMessage(errorType: "User Exists"); - // return const MIHErrorMessage(errorType: "Password Match"); - // return const MIHErrorMessage(errorType: "Invalid Credentials"); - return const MIHErrorMessage(errorType: "Internet Connection"); - }, - ); - }, - tileName: "Error - Dev", - tileIcon: Icon( - Icons.error_outline_outlined, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - showDialog( - context: context, - builder: (context) { - return const MIHSuccessMessage( - successType: "Success", - successMessage: - "Congratulations! Your account has been created successfully. You are log in and can start exploring.\n\nPlease note: more apps will appear once you update your profile."); - }, - ); - }, - tileName: "Success - Dev", - tileIcon: Icon( - Icons.check_circle_outline_outlined, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - - tileList.add(MIHTile( - onTap: () { - showDialog( - context: context, - builder: (context) { - // return MIHDeleteMessage(deleteType: "Note", onTap: () {}); - return MIHDeleteMessage(deleteType: "File", onTap: () {}); - }, - ); - }, - tileName: "Delete - Dev", - tileIcon: Icon( - Icons.delete_forever_outlined, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - showDialog( - barrierDismissible: false, - context: context, - builder: (context) { - // return const MIHErrorMessage(errorType: "Input Error"); - // return const MIHErrorMessage(errorType: "Password Requirements"); - // return const MIHErrorMessage(errorType: "Invalid Username"); - // return const MIHErrorMessage(errorType: "Invalid Email"); - // return const MIHErrorMessage(errorType: "User Exists"); - // return const MIHErrorMessage(errorType: "Password Match"); - // return const MIHErrorMessage(errorType: "Invalid Credentials"); - return MihPackageWindow( - fullscreen: false, - windowTitle: - "Test Window title that is too large for mobile devices", - windowBody: const Column( - children: [ - SizedBox( - height: 250, - ) - ], - ), - menuOptions: [ - SpeedDialChild( - child: Icon( - Icons.delete, - color: MihColors.getPrimaryColor( - MzansiInnovationHub.of(context)!.theme.mode == - "Dark"), - ), - label: "Delete File", - labelBackgroundColor: MihColors.getGreenColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - labelStyle: TextStyle( - color: MihColors.getPrimaryColor( - MzansiInnovationHub.of(context)!.theme.mode == - "Dark"), - fontWeight: FontWeight.bold, - ), - backgroundColor: MihColors.getGreenColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - onTap: () {}, - ), - ], - onWindowTapClose: () { - Navigator.pop(context); - }, - ); - }, - ); - }, - tileName: "Window - Dev", - tileIcon: Icon( - Icons.window, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - tileList.add(MIHTile( - onTap: () { - MIHLocationAPI().getGPSPosition(context).then((position) { - if (position != null) { - print(position); - // print( - // "Distance: ${MIHLocationAPI().getDistanceInMeaters(position, position)}m"); - } - }); - }, - tileName: "Location - Dev", - tileIcon: Icon( - Icons.location_pin, - color: getSec(), - size: 230, - ), - p: getPrim(), - s: getSec(), - )); - } - } - - List searchApp(List appList, String searchString) { - if (searchString == "") { - return appList; - } else { - List temp = []; - for (var item in appList) { - if (item.tileName.toLowerCase().contains(appSearch.toLowerCase())) { - temp.add(item); - } - } - return temp; - } - } - - List> setApps( - List personalTileList, List businessTileList) { - if (widget.isUserNew) { - setAppsNewPersonal(personalTileList); - } else if (!widget.isBusinessUser) { - setAppsPersonal(personalTileList); - } else if (widget.isBusinessUserNew) { - setAppsPersonal(personalTileList); - setAppsNewBusiness(businessTileList); - } else { - setAppsPersonal(personalTileList); - setAppsBusiness(businessTileList); - } - if (widget.isDevActive) { - setAppsDev(personalTileList); - setAppsDev(businessTileList); - } - return [personalTileList, businessTileList]; - } - - Color getPrim() { - return MihColors.getSecondaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"); - } - - Color getSec() { - return MihColors.getPrimaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"); - } - - bool isBusinessUser(AppUser signedInUser) { - if (signedInUser.type == "personal") { - return false; - } else { - return true; - } - } - - String getHeading(int index) { - if (index == 0) { - return "Personal Apps"; - } else { - return "Business Apps"; - } - } - - void onDragStart(DragStartDetails startDrag) { - Scaffold.of(context).openDrawer(); - print(startDrag.globalPosition.dx); - } - - Widget getActionButton() { - return Builder(builder: (context) { - return MIHAction( - icon: Padding( - padding: const EdgeInsets.only(left: 5.0), child: Placeholder(), - // MIHProfilePicture( - // profilePictureFile: widget.propicFile, - // proPicController: proPicController, - // proPic: null, - // width: 45, - // radius: 21, - // drawerMode: false, - // editable: false, - // frameColor: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - // onChange: (newProPic) {}, - // ), - ), - // const Icon(Icons.apps), - iconSize: 45, - onTap: () { - setState(() { - appSearch = ""; - searchController.clear(); - }); - //key.currentState.o - Scaffold.of(context).openDrawer(); - }, - ); - }); - } - - Widget getSecondaryActionButton() { - Widget notIIcon; - if (hasNewNotifications()) { - notIIcon = Stack( - children: [ - const Icon(Icons.notifications), - Positioned( - right: 0, - top: 0, - child: Icon( - Icons.circle, - size: 10, - color: MihColors.getRedColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - ), - ) - ], - ); - } else { - notIIcon = const Icon(Icons.notifications); - } - return Builder(builder: (context) { - return MIHAction( - icon: notIIcon, - iconSize: 35, - onTap: () { - setState(() { - appSearch = ""; - searchController.clear(); - }); - //key.currentState.o - Scaffold.of(context).openEndDrawer(); - }, - ); - }); - } - - MIHHeader getHeader() { - return const MIHHeader( - headerAlignment: MainAxisAlignment.center, - headerItems: [ - Text( - "MIH", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - ), - ), - ], - ); - } - - MIHBody getBody(double width, double height) { - return MIHBody( - borderOn: false, - bodyItems: [ - const SizedBox(height: 10), - Row( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Flexible( - flex: 4, - child: KeyboardListener( - focusNode: _focusNode, - autofocus: true, - onKeyEvent: (event) async { - if (event is KeyDownEvent && - event.logicalKey == LogicalKeyboardKey.enter) { - setState(() { - appSearch = searchController.text; - }); - } - }, - child: SizedBox( - child: MihSearchBar( - controller: searchController, - hintText: "Ask Mzansi", - prefixIcon: Icons.search, - prefixAltIcon: MihIcons.mzansiAi, - fillColor: MihColors.getSecondaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - hintColor: MihColors.getPrimaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - onPrefixIconTap: () { - print("Search Text: ${searchController.text}"); - setState(() { - appSearch = searchController.text; - }); - }, - searchFocusNode: FocusNode(), - ), - ), - ), - ), - Flexible( - flex: 1, - child: IconButton( - //padding: const EdgeInsets.all(0), - onPressed: () { - setState(() { - appSearch = ""; - searchController.clear(); - }); - }, - icon: const Icon( - Icons.filter_alt_off, - size: 30, - ), - ), - ), - ], - ), - const SizedBox(height: 10), - GridView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.only( - left: width / 13, - right: width / 13, - bottom: height / 15, - //top: 20, - ), - // shrinkWrap: true, - itemCount: searchApp(pbswitch[_selectedIndex], appSearch).length, - gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( - mainAxisSpacing: 15, maxCrossAxisExtent: 200), - itemBuilder: (context, index) { - return searchApp(pbswitch[_selectedIndex], appSearch)[index]; - }, - ), - ], - ); - } - - MIHAppDrawer getActionDrawer() { - return MIHAppDrawer( - signedInUser: widget.signedInUser, - propicFile: widget.propicFile, - ); - } - - MIHNotificationDrawer getSecondaryActionDrawer() { - return MIHNotificationDrawer( - signedInUser: widget.signedInUser, - notifications: widget.notifications, - ); - } - - Widget getBottomNavBar() { - return Visibility( - visible: isBusinessUser(widget.signedInUser), - child: Padding( - padding: const EdgeInsets.only( - left: 10.0, right: 10.0, bottom: 10.0, top: 0), - child: Placeholder(), - // GNav( - // //hoverColor: Colors.lightBlueAccent, - // color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - // iconSize: 35.0, - // activeColor: MihColors.getPrimaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - // tabBackgroundColor: - // MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - // //gap: 20, - // //padding: EdgeInsets.all(15), - // tabs: [ - // GButton( - // icon: Icons.perm_identity, - // text: "Personal", - // onPressed: () { - // setState(() { - // widget.personalSelected = true; - // _selectedIndex = 0; - // }); - // print("personal selected: ${widget.personalSelected}"); - // }, - // ), - // GButton( - // icon: Icons.business_center, - // text: "Business", - // onPressed: () { - // setState(() { - // widget.personalSelected = false; - // _selectedIndex = 1; - // }); - // print("personal selected: ${widget.personalSelected}"); - // }, - // ), - // ], - // selectedIndex: _selectedIndex, - // ), - ), - ); - } - - bool hasNewNotifications() { - //print(widget.notifications.toString()); - if (notifiList.map((item) => item.notification_read).contains("No")) { - //print("New Notification Available"); - - return true; - } else { - //print("No New Notification Available"); - return false; - } - } - - Future refreshNotifications() async { - if (MzansiInnovationHub.of(context)!.theme.getPlatform() == "Web") { - html.window.location.reload(); - } else { - var responseNotification = await http.get(Uri.parse( - "$baseAPI/notifications/${widget.signedInUser.app_id}?amount=$amount")); - List notifi; - if (responseNotification.statusCode == 200) { - String body = responseNotification.body; - // var decodedData = jsonDecode(body); - // MIHNotification notifications = MIHNotification.fromJson(decodedData); - - Iterable l = jsonDecode(body); - //print("Here2"); - List notifications = List.from( - l.map((model) => MIHNotification.fromJson(model))); - notifi = notifications; - } else { - notifi = []; - } - setState(() { - notifiList = notifi; - }); - notificationPopUp(); - } - } - - void notificationPopUp() { - if (hasNewNotifications()) { - showDialog( - barrierColor: const Color(0x01000000), - context: context, - builder: (context) { - return MIHNotificationMessage( - arguments: NotificationArguments( - "Unread Notifications", - "You have unread notifications waiting for you.", - () { - Navigator.of(context).pop(); - //Scaffold.of(context).openEndDrawer(); - }, - ), - ); - }, - ); - } - } - - @override - void dispose() { - searchController.dispose(); - proPicController.dispose(); - _focusNode.dispose(); - super.dispose(); - } - - @override - void initState() { - super.initState(); - setState(() { - pbswitch = setApps(persHTList, busHTList); - businessUserSwitch = false; - notifiList = widget.notifications; - }); - if (!widget.personalSelected) { - setState(() { - _selectedIndex = 1; - }); - } - WidgetsBinding.instance.addPostFrameCallback((_) { - notificationPopUp(); - }); - } - - @override - Widget build(BuildContext context) { - final Size size = MediaQuery.sizeOf(context); - final double width = size.width; - final double height = size.height; - - return MIHLayoutBuilder( - actionButton: getActionButton(), - header: getHeader(), - secondaryActionButton: getSecondaryActionButton(), - body: getBody(width, height), - actionDrawer: getActionDrawer(), - secondaryActionDrawer: getSecondaryActionDrawer(), - bottomNavBar: getBottomNavBar(), - pullDownToRefresh: true, - onPullDown: refreshNotifications, - ); - } -} diff --git a/Frontend/lib/mih_packages/mih_home/mih_profile_getter.dart b/Frontend/lib/mih_packages/mih_home/mih_profile_getter.dart deleted file mode 100644 index e07ee97f..00000000 --- a/Frontend/lib/mih_packages/mih_home/mih_profile_getter.dart +++ /dev/null @@ -1,281 +0,0 @@ -import 'package:mzansi_innovation_hub/main.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart'; -import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; -import 'package:mzansi_innovation_hub/mih_packages/mih_home/mih_home.dart'; -import 'package:flutter/material.dart'; - -import '../../mih_services/mih_service_calls.dart'; -import '../../mih_components/mih_pop_up_messages/mih_loading_circle.dart'; -import '../../mih_config/mih_env.dart'; - -class MIHProfileGetter extends StatefulWidget { - final bool personalSelected; - const MIHProfileGetter({ - super.key, - required this.personalSelected, - }); - - @override - State createState() => _MIHProfileGetterState(); -} - -class _MIHProfileGetterState extends State { - String useremail = ""; - int amount = 10; - final baseAPI = AppEnviroment.baseApiUrl; - late Future profile; - - String proPicUrl = "empty"; - ImageProvider? propicFile; - int _selcetedIndex = 0; - - bool isUserNew(AppUser signedInUser) { - if (signedInUser.fname == "") { - return true; - } else { - return false; - } - } - - bool isDevActive() { - if (AppEnviroment.getEnv() == "Dev") { - return true; - } else { - return false; - } - } - - bool isBusinessUser(AppUser signedInUser) { - if (signedInUser.type == "personal") { - return false; - } else { - return true; - } - } - - bool isBusinessUserNew(BusinessUser? businessUser) { - if (businessUser == null) { - return true; - } else { - return false; - } - } - - MihPackageTools getErrorTools() { - Map temp = {}; - temp[const Icon(Icons.power_off_outlined)] = () { - setState(() { - _selcetedIndex = 0; - }); - }; - return MihPackageTools( - tools: temp, - selcetedIndex: _selcetedIndex, - ); - } - - List getErrorToolBody(String error) { - List toolBodies = [ - MihPackageToolBody( - borderOn: true, - bodyItem: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - "Connection Error", - textAlign: TextAlign.center, - style: TextStyle( - color: MihColors.getSecondaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - fontSize: 35, - fontWeight: FontWeight.bold, - ), - ), - Icon( - Icons.power_off_outlined, - size: 150, - color: MihColors.getSecondaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - ), - SizedBox( - width: 500, - child: Text( - "Looks like we ran into an issue getting your data.\nPlease check you internet connection and try again.", - textAlign: TextAlign.center, - style: TextStyle( - color: MihColors.getSecondaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - MihButton( - onPressed: () { - Navigator.of(context).popAndPushNamed("/"); - }, - buttonColor: MihColors.getGreenColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - width: 300, - child: Text( - "Refresh", - style: TextStyle( - color: MihColors.getPrimaryColor( - MzansiInnovationHub.of(context)!.theme.mode == "Dark"), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 15), - Padding( - padding: const EdgeInsets.all(10.0), - child: SizedBox( - width: 500, - child: SelectionArea( - child: Text( - "Error: $error", - textAlign: TextAlign.left, - style: TextStyle( - color: MihColors.getRedColor( - MzansiInnovationHub.of(context)!.theme.mode == - "Dark"), - fontSize: 15, - fontWeight: FontWeight.bold, - ), - ), - ), - ), - ), - ], - ), - ) - ]; - return toolBodies; - } - - Widget errorPage(String error) { - return MihPackage( - appActionButton: MihPackageAction( - icon: const Icon(Icons.refresh), - iconSize: 35, - onTap: () { - Navigator.of(context).popAndPushNamed("/"); - }, - ), - appTools: getErrorTools(), - appBody: getErrorToolBody(error), - selectedbodyIndex: _selcetedIndex, - onIndexChange: (newValue) { - setState(() { - _selcetedIndex = newValue; - }); - //print("Index: $_selcetedIndex"); - }, - ); - // return MIHLayoutBuilder( - // actionButton: MIHAction( - // icon: const Icon(Icons.refresh), - // iconSize: 35, - // onTap: () { - // Navigator.of(context).popAndPushNamed("/"); - // }, - // ), - // header: const MIHHeader( - // headerAlignment: MainAxisAlignment.center, - // headerItems: [ - // Text( - // "Mzanzi Innovation Hub", - // style: TextStyle( - // fontWeight: FontWeight.bold, - // fontSize: 20, - // ), - // ), - // ], - // ), - // secondaryActionButton: null, - // body: MIHBody( - // borderOn: false, - // bodyItems: [ - // Align( - // alignment: Alignment.center, - // child: Text( - // '$error occurred', - // style: const TextStyle(fontSize: 18), - // ), - // ), - // ], - // ), - // actionDrawer: null, - // secondaryActionDrawer: null, - // bottomNavBar: null, - // pullDownToRefresh: false, - // onPullDown: () async {}, - // ); - } - - @override - void dispose() { - // TODO: implement dispose - super.dispose(); - } - - @override - void initState() { - //profile = getProfile(); - profile = MIHApiCalls().getProfile(amount, context); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return FutureBuilder( - future: profile, - builder: (BuildContext context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.hasData) { - return MihHome( - // signedInUser: snapshot.requireData.signedInUser, - // businessUser: snapshot.data!.businessUser, - // business: snapshot.data!.business, - // patient: snapshot.data!.patient, - // notifications: snapshot.data!.notifi, - // propicFile: snapshot.data!.profilePicUrl != "" - // ? NetworkImage(snapshot.data!.profilePicUrl) - // : null, - // isUserNew: isUserNew(snapshot.requireData.signedInUser), - // isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser), - // isBusinessUserNew: isBusinessUserNew(snapshot.data!.businessUser), - // isDevActive: isDevActive(), - personalSelected: widget.personalSelected, - ); - // return MIHHomeLegacy( - // signedInUser: snapshot.requireData.signedInUser, - // businessUser: snapshot.data!.businessUser, - // business: snapshot.data!.business, - // patient: snapshot.data!.patient, - // notifications: snapshot.data!.notifi, - // propicFile: isPictureAvailable(snapshot.data!.profilePicUrl), - // isUserNew: isUserNew(snapshot.requireData.signedInUser), - // isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser), - // isBusinessUserNew: isBusinessUserNew(snapshot.data!.businessUser), - // isDevActive: isDevActive(), - // personalSelected: widget.personalSelected, - // ); - } else { - return errorPage(snapshot.error.toString()); - } - } - return const Mihloadingcircle(); - }, - ); - } -} diff --git a/Frontend/lib/mih_packages/mih_home/mih_route_error.dart b/Frontend/lib/mih_packages/mih_home/mih_route_error.dart new file mode 100644 index 00000000..5805758f --- /dev/null +++ b/Frontend/lib/mih_packages/mih_home/mih_route_error.dart @@ -0,0 +1,149 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:mzansi_innovation_hub/main.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart'; +import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; + +class MihRouteError extends StatefulWidget { + const MihRouteError({ + super.key, + }); + + @override + State createState() => _MihRouteErrorState(); +} + +class _MihRouteErrorState extends State { + int _selcetedIndex = 0; + + @override + Widget build(BuildContext context) { + return MihPackage( + appActionButton: getErrorAction(), + appTools: getErrorTools(), + appBody: getErrorToolBody(), + selectedbodyIndex: _selcetedIndex, + onIndexChange: (newValue) { + setState(() { + _selcetedIndex = newValue; + }); + //print("Index: $_selcetedIndex"); + }, + ); + } + + MihPackageAction getErrorAction() { + return MihPackageAction( + icon: const Icon(MihIcons.mihLogo), + iconSize: 35, + onTap: () { + context.goNamed( + 'mihHome', + extra: true, + ); + }, + ); + } + + MihPackageTools getErrorTools() { + Map temp = {}; + temp[const Icon(Icons.link_off_rounded)] = () { + setState(() { + _selcetedIndex = 0; + }); + }; + return MihPackageTools( + tools: temp, + selcetedIndex: _selcetedIndex, + ); + } + + List getErrorToolBody() { + List toolBodies = [ + MihPackageToolBody( + borderOn: true, + bodyItem: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "Oops! Wrong Turn.", + textAlign: TextAlign.center, + style: TextStyle( + color: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + fontSize: 35, + fontWeight: FontWeight.bold, + ), + ), + Icon( + Icons.link_off_rounded, + size: 150, + color: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + ), + SizedBox( + width: 700, + child: Text( + "It looks like you've taken a wrong turn and ended up on a package that doesn't exist within the MIH App.\n\nDon't worry, getting back is easy. Just click the button below or the MIH Logo to return to the correct path.", + textAlign: TextAlign.center, + style: TextStyle( + color: MihColors.getSecondaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + ), + const SizedBox(height: 15), + MihButton( + onPressed: () { + context.goNamed( + 'mihHome', + extra: true, + ); + }, + buttonColor: MihColors.getGreenColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + width: 300, + child: Text( + "Back to MIH", + style: TextStyle( + color: MihColors.getPrimaryColor( + MzansiInnovationHub.of(context)!.theme.mode == "Dark"), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), + // const SizedBox(height: 15), + // Padding( + // padding: const EdgeInsets.all(10.0), + // child: SizedBox( + // width: 500, + // child: SelectionArea( + // child: Text( + // "Error: $error", + // textAlign: TextAlign.left, + // style: TextStyle( + // color: MihColors.getRedColor( + // MzansiInnovationHub.of(context)!.theme.mode == + // "Dark"), + // fontSize: 15, + // fontWeight: FontWeight.bold, + // ), + // ), + // ), + // ), + // ), + ], + ), + ) + ]; + return toolBodies; + } +}