diff --git a/mih_ui/analysis_options.yaml b/mih_ui/analysis_options.yaml index 0d290213..65062592 100644 --- a/mih_ui/analysis_options.yaml +++ b/mih_ui/analysis_options.yaml @@ -1,28 +1,9 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. +analyzer: + exclude: + - lib/**/*.g.dart + - lib/**/hive_registrar.g.dart -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. include: package:flutter_lints/flutter.yaml linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at https://dart.dev/lints. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/mih_ui/build.yaml b/mih_ui/build.yaml new file mode 100644 index 00000000..f99dfb8c --- /dev/null +++ b/mih_ui/build.yaml @@ -0,0 +1,14 @@ +targets: + $default: + builders: + # 1. Restrict adapter generation to your mih_hive folder + hive_ce_generator:hive_adapters_generator: + generate_for: + - lib/mih_hive/*.dart + + # 2. Restrict registrar generation to your entry points + hive_ce_generator:hive_registrar_generator: + generate_for: + - lib/main.dart + - lib/main_dev.dart + - lib/main_prod.dart diff --git a/mih_ui/lib/main.dart b/mih_ui/lib/main.dart index ebf3c1d0..49ae024b 100644 --- a/mih_ui/lib/main.dart +++ b/mih_ui/lib/main.dart @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:ken_logger/ken_logger.dart'; +import 'package:mzansi_innovation_hub/mih_hive/about_mih_hive_data.dart'; import 'package:mzansi_innovation_hub/mih_hive/mzansi_profile_hive_data.dart'; import 'package:mzansi_innovation_hub/mih_hive/mzansi_wallet_hive_data.dart'; import 'package:mzansi_innovation_hub/mih_providers/about_mih_provider.dart'; @@ -151,7 +152,9 @@ class _MzansiInnovationHubState extends State { create: (context) => MihCalendarProvider(), ), ChangeNotifierProvider( - create: (context) => AboutMihProvider(), + create: (context) => AboutMihProvider( + AboutMihHiveData(), + ), ), ChangeNotifierProvider( create: (context) => MihMineSweeperProvider(), diff --git a/mih_ui/lib/main_dev.dart b/mih_ui/lib/main_dev.dart index 55881da2..71e42e5c 100644 --- a/mih_ui/lib/main_dev.dart +++ b/mih_ui/lib/main_dev.dart @@ -45,6 +45,7 @@ void main() async { // Mzansi Wallet Data await Hive.openBox('loyalty_card_box'); await Hive.openBox('fav_loyalty_card_box'); + await Hive.openBox('about_mih_box'); // await Firebase.initializeApp( // // options: DefaultFirebaseOptions.currentPlatform, diff --git a/mih_ui/lib/mih_hive/about_mih_hive_data.dart b/mih_ui/lib/mih_hive/about_mih_hive_data.dart new file mode 100644 index 00000000..3429c7b8 --- /dev/null +++ b/mih_ui/lib/mih_hive/about_mih_hive_data.dart @@ -0,0 +1,42 @@ +import 'package:hive_ce_flutter/adapters.dart'; +import 'package:ken_logger/ken_logger.dart'; +import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart'; +import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart'; + +class AboutMihHiveData { + final Box _mihUserBusinessCountBox = Hive.box('about_mih_box'); + + static const String kUserCountKey = 'current_user_count'; + static const String kBusinessCountKey = 'current_user_count'; + + // Get Data from local storage + int? getcachedUserCount() => _mihUserBusinessCountBox.get(kUserCountKey); + int? getcachedBusinessCount() => + _mihUserBusinessCountBox.get(kBusinessCountKey); + + // Caching Data to local storage + Future cacheUserCount(int remoteUserCount) async { + await _mihUserBusinessCountBox.put(kUserCountKey, remoteUserCount); + KenLogger.success("MIH User Count Cached"); + } + + Future cacheBusinessCount(int remoteBusinessCount) async { + await _mihUserBusinessCountBox.put(kUserCountKey, remoteBusinessCount); + KenLogger.success("MIH Business Count Cached"); + } + + // Sync Local Data from data from MIH Server + Future syncAboutMihDataWithServer() async { + try { + int remoteUserCount = await MihUserServices().fetchUserCount(); + cacheUserCount(remoteUserCount); + int remoteBusinessCount = + await MihBusinessDetailsServices().fetchBusinessCount(); + cacheBusinessCount(remoteBusinessCount); + return true; + } catch (error) { + KenLogger.warning("MIH App Operating in Offline Mode. Sync Paused"); + return false; + } + } +} diff --git a/mih_ui/lib/mih_hive/mzansi_profile_hive_data.dart b/mih_ui/lib/mih_hive/mzansi_profile_hive_data.dart index cd818fff..a6b5318a 100644 --- a/mih_ui/lib/mih_hive/mzansi_profile_hive_data.dart +++ b/mih_ui/lib/mih_hive/mzansi_profile_hive_data.dart @@ -159,7 +159,7 @@ class MzansiProfileHiveData { } return true; } catch (error) { - KenLogger.warning("App Operating in Offline Mode. Sync Paused"); + KenLogger.warning("MIH App Operating in Offline Mode. Sync Paused"); return false; // KenLogger.warning("App operating offline mode. Sync paused: $error"); } diff --git a/mih_ui/lib/mih_hive/mzansi_wallet_hive_data.dart b/mih_ui/lib/mih_hive/mzansi_wallet_hive_data.dart index 66fa4187..21bdec6e 100644 --- a/mih_ui/lib/mih_hive/mzansi_wallet_hive_data.dart +++ b/mih_ui/lib/mih_hive/mzansi_wallet_hive_data.dart @@ -51,7 +51,7 @@ class MzansiWalletHiveData { cacheFavLoyaltyCardsData(remoteFavLoyaltyCards); return true; } catch (error) { - KenLogger.warning("App Operating in Offline Mode. Sync Paused"); + KenLogger.warning("MIH App Operating in Offline Mode. Sync Paused"); return false; // KenLogger.warning("App operating offline mode. Sync paused: $error"); } diff --git a/mih_ui/lib/mih_packages/about_mih/components/about_mih_heading.dart b/mih_ui/lib/mih_packages/about_mih/components/about_mih_heading.dart new file mode 100644 index 00000000..33e89743 --- /dev/null +++ b/mih_ui/lib/mih_packages/about_mih/components/about_mih_heading.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:mih_package_toolkit/mih_package_toolkit.dart'; +import 'package:mzansi_innovation_hub/mih_providers/about_mih_provider.dart'; +import 'package:provider/provider.dart'; + +class AboutMihHeading extends StatefulWidget { + const AboutMihHeading({super.key}); + + @override + State createState() => _AboutMihHeadingState(); +} + +class _AboutMihHeadingState extends State { + @override + Widget build(BuildContext context) { + return Consumer( + builder: (BuildContext context, AboutMihProvider aboutProvider, + Widget? child) { + return Column( + children: [ + SizedBox( + width: 165, + child: FittedBox( + child: Icon( + MihIcons.mihLogo, + color: MihColors.secondary(), + ), + ), + ), + const SizedBox( + height: 10, + ), + const Text( + "Mzansi Innovation Hub", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 30, + ), + ), + Text( + "MIH App Version: ${aboutProvider.version}", + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.normal, + fontSize: 15, + ), + ), + const SizedBox( + height: 10, + ), + ], + ); + }, + ); + } +} diff --git a/mih_ui/lib/mih_packages/about_mih/components/call_to_action_buttons.dart b/mih_ui/lib/mih_packages/about_mih/components/call_to_action_buttons.dart new file mode 100644 index 00000000..326453ca --- /dev/null +++ b/mih_ui/lib/mih_packages/about_mih/components/call_to_action_buttons.dart @@ -0,0 +1,239 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:go_router/go_router.dart'; +import 'package:mih_package_toolkit/mih_package_toolkit.dart'; +import 'package:mzansi_innovation_hub/main.dart'; +import 'package:mzansi_innovation_hub/mih_services/mih_install_services.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class CallToActionButtons extends StatefulWidget { + const CallToActionButtons({super.key}); + + @override + State createState() => _CallToActionButtonsState(); +} + +class _CallToActionButtonsState extends State { + Future launchSocialUrl(Uri linkUrl) async { + if (!await launchUrl(linkUrl)) { + throw Exception('Could not launch $linkUrl'); + } + } + + Widget getInstallButtonText() { + final isWebAndroid = + kIsWeb && (defaultTargetPlatform == TargetPlatform.android); + final isWebIos = kIsWeb && (defaultTargetPlatform == TargetPlatform.iOS); + String btnText = ""; + FaIconData platformIcon; + if (isWebAndroid) { + btnText = "Install MIH"; + platformIcon = FontAwesomeIcons.googlePlay; + } else if (isWebIos) { + btnText = "Install MIH"; + platformIcon = FontAwesomeIcons.appStoreIos; + } else if (MzansiInnovationHub.of(context)!.theme.getPlatform() == + "Android") { + btnText = "Update MIH"; + platformIcon = FontAwesomeIcons.googlePlay; + } else if (MzansiInnovationHub.of(context)!.theme.getPlatform() == "iOS") { + btnText = "Update MIH"; + platformIcon = FontAwesomeIcons.appStoreIos; + } else { + btnText = "Install MIH"; + platformIcon = FontAwesomeIcons.globe; + } + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FaIcon( + platformIcon, + color: MihColors.primary(), + ), + const SizedBox(width: 10), + Text( + btnText, + style: TextStyle( + color: MihColors.primary(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + return Column( + children: [ + Wrap( + alignment: WrapAlignment.center, + crossAxisAlignment: WrapCrossAlignment.center, + spacing: 10, + runSpacing: 10, + children: [ + MihButton( + onPressed: () { + if (MzansiInnovationHub.of(context)!.theme.getPlatform() == + "Android") { + showDialog( + context: context, + builder: (context) { + return MihPackageWindow( + fullscreen: false, + windowTitle: "Select Option", + onWindowTapClose: () { + context.pop(); + }, + windowBody: Column( + children: [ + Text( + "Please select the platform you want to install/ Update MIH from", + style: TextStyle( + color: MihColors.secondary(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 25), + MihButton( + onPressed: () { + launchSocialUrl( + Uri.parse( + "https://play.google.com/store/apps/details?id=za.co.mzansiinnovationhub.mih", + ), + ); + }, + buttonColor: MihColors.green(), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FaIcon( + FontAwesomeIcons.googlePlay, + color: MihColors.primary(), + ), + const SizedBox(width: 10), + Text( + "Play Store", + style: TextStyle( + color: MihColors.primary(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + const SizedBox( + height: 10, + ), + MihButton( + onPressed: () { + launchSocialUrl( + Uri.parse( + "https://appgallery.huawei.com/app/C113315335?pkgName=za.co.mzansiinnovationhub.mih", + ), + ); + }, + buttonColor: MihColors.green(), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.store, + color: MihColors.primary(), + ), + const SizedBox(width: 10), + Text( + "App Gallery", + style: TextStyle( + color: MihColors.primary(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + ], + ), + ); + }, + ); + } else { + MihInstallServices().installMihTrigger(context); + } + }, + buttonColor: MihColors.green(), + width: 300, + child: getInstallButtonText(), + ), + MihButton( + onPressed: () { + launchSocialUrl( + Uri.parse( + "https://www.youtube.com/playlist?list=PLuT35kJIui0H5kXjxNOZlHoOPZbQLr4qh", + ), + ); + }, + buttonColor: MihColors.green(), + width: 300, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FaIcon( + FontAwesomeIcons.youtube, + color: MihColors.primary(), + ), + const SizedBox(width: 10), + Text( + "MIH Beginners Guide", + style: TextStyle( + color: MihColors.primary(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + MihButton( + onPressed: () { + launchSocialUrl( + Uri.parse( + "https://patreon.com/MzansiInnovationHub?utm_medium=unknown&utm_source=join_link&utm_campaign=creatorshare_creator&utm_content=copyLink", + ), + ); + }, + buttonColor: MihColors.green(), + width: 300, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FaIcon( + FontAwesomeIcons.patreon, + color: MihColors.primary(), + ), + const SizedBox(width: 10), + Text( + "Support Our Journey", + style: TextStyle( + color: MihColors.primary(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + ], + ); + } +} diff --git a/mih_ui/lib/mih_packages/about_mih/components/founder_details.dart b/mih_ui/lib/mih_packages/about_mih/components/founder_details.dart new file mode 100644 index 00000000..a45053cd --- /dev/null +++ b/mih_ui/lib/mih_packages/about_mih/components/founder_details.dart @@ -0,0 +1,97 @@ +import 'package:flutter/material.dart'; +import 'package:mih_package_toolkit/mih_package_toolkit.dart'; + +class FounderDetails extends StatefulWidget { + const FounderDetails({super.key}); + + @override + State createState() => _FounderDetailsState(); +} + +class _FounderDetailsState extends State { + Widget founderTitle() { + String heading = "Yasien Meth (Founder & CEO)"; + return Column( + children: [ + Text( + heading, + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25, + ), + ), + const SizedBox( + height: 10, + ), + ], + ); + } + + Widget founderBio() { + String bio = ""; + bio += "BSc Computer Science & Information Systems\n"; + bio += "(University of the Western Cape)\n"; + bio += + "6 Year of banking experience with one of the big 5 banks of South Africa."; + return Wrap( + alignment: WrapAlignment.center, + crossAxisAlignment: WrapCrossAlignment.center, + spacing: 10, + runSpacing: 10, + children: [ + SizedBox( + width: 300, + child: Stack( + alignment: Alignment.center, + fit: StackFit.loose, + children: [ + Padding( + padding: const EdgeInsets.only(left: 4.0), + child: CircleAvatar( + backgroundColor: MihColors.primary(), + backgroundImage: const AssetImage( + "lib/mih_package_components/assets/images/founder.jpg"), + //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'), + radius: 75, + ), + ), + Icon( + MihIcons.mihRing, + size: 165, + color: MihColors.secondary(), + ), + ], + ), + ), + SizedBox( + width: 400, + child: Text( + bio, + textAlign: TextAlign.center, + style: const TextStyle( + //fontWeight: FontWeight.bold, + fontSize: 17, + ), + ), + ), + const SizedBox( + height: 10, + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + founderTitle(), + founderBio(), + ], + ); + } +} diff --git a/mih_ui/lib/mih_packages/about_mih/components/mih_social_links.dart b/mih_ui/lib/mih_packages/about_mih/components/mih_social_links.dart new file mode 100644 index 00000000..bbb4301c --- /dev/null +++ b/mih_ui/lib/mih_packages/about_mih/components/mih_social_links.dart @@ -0,0 +1,137 @@ +import 'package:flutter/material.dart'; +import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart'; +import 'package:mzansi_innovation_hub/mih_package_components/mih_profile_links.dart'; + +class MihSocialLinks extends StatefulWidget { + const MihSocialLinks({super.key}); + + @override + State createState() => _MihSocialLinksState(); +} + +class _MihSocialLinksState extends State { + List links = [ + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Youtube", + custom_name: "", + destination: "https://www.youtube.com/@MzansiInnovationHub", + order: 1, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "TikTok", + custom_name: "", + destination: "https://www.tiktok.com/@mzansiinnovationhub", + order: 2, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Twitch", + custom_name: "", + destination: "https://www.twitch.tv/mzansiinnovationhub", + order: 3, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Threads", + custom_name: "", + destination: "https://www.threads.com/@mzansi.innovation.hub", + order: 4, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "WhatsApp", + custom_name: "", + destination: "https://whatsapp.com/channel/0029Vax3INCIyPtMn8KgeM2F", + order: 5, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Instagram", + custom_name: "", + destination: "https://www.instagram.com/mzansi.innovation.hub/", + order: 6, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "X", + custom_name: "", + destination: "https://x.com/mzansi_inno_hub", + order: 7, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "LinkedIn", + custom_name: "", + destination: "https://www.linkedin.com/company/mzansi-innovation-hub/", + order: 8, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Facebook", + custom_name: "", + destination: "https://www.facebook.com/profile.php?id=61565345762136", + order: 9, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Reddit", + custom_name: "", + destination: "https://www.reddit.com/r/Mzani_Innovation_Hub/", + order: 10, + ), + ProfileLink( + idprofile_links: 1, + app_id: "1234", + business_id: "", + site_name: "Git", + custom_name: "", + destination: + "https://git.mzansi-innovation-hub.co.za/yaso_meth/mih-project", + order: 11, + ), + ]; + @override + Widget build(BuildContext context) { + return Column( + children: [ + Text( + "Follow Our Journey", + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25, + ), + ), + const SizedBox( + height: 10, + ), + MihProfileLinks(links: links), + const SizedBox( + height: 75, + ), + ], + ); + } +} diff --git a/mih_ui/lib/mih_packages/about_mih/components/mission_and_vission.dart b/mih_ui/lib/mih_packages/about_mih/components/mission_and_vission.dart new file mode 100644 index 00000000..c06fea09 --- /dev/null +++ b/mih_ui/lib/mih_packages/about_mih/components/mission_and_vission.dart @@ -0,0 +1,101 @@ +import 'package:flutter/material.dart'; + +class MissionAndVission extends StatefulWidget { + const MissionAndVission({super.key}); + + @override + State createState() => _MissionAndVissionState(); +} + +class _MissionAndVissionState extends State { + Widget ourVision() { + String heading = "Our Vision"; + String vision = + "Digitizing Mzansi one process at a time. Discover essential Mzansi apps to streamline your personal and professional life. Simplify your daily tasks with our user-friendly solutions."; + return SizedBox( + width: 500, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Text( + heading, + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25, + ), + ), + const SizedBox( + height: 10, + ), + Text( + vision, + textAlign: TextAlign.center, + style: const TextStyle( + //fontWeight: FontWeight.bold, + fontSize: 17, + ), + ), + ], + ), + ); + } + + Widget ourMission() { + String heading = "Our Mission"; + String mission = + "Bridge the digital divide in Mzansi, ensuring that everyone can benefit from the power of technology. We empower lives by providing simple, elegant solutions that elevate daily experiences. With our user-friendly approach, we're making the digital world accessible to all, ensuring no one is left behind in the digital revolution."; + return SizedBox( + width: 500, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + heading, + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25, + ), + ), + const SizedBox( + height: 10, + ), + Text( + mission, + textAlign: TextAlign.center, + style: const TextStyle( + //fontWeight: FontWeight.bold, + fontSize: 17, + ), + ), + ], + ), + ); + } + + @override + Widget build(BuildContext context) { + return Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 25.0), + child: Wrap( + alignment: WrapAlignment.start, + crossAxisAlignment: WrapCrossAlignment.start, + spacing: 10, + runSpacing: 10, + children: [ + ourVision(), + ourMission(), + ], + ), + ), + const SizedBox( + height: 10, + ), + ], + ); + } +} diff --git a/mih_ui/lib/mih_packages/about_mih/package_tools/mih_info.dart b/mih_ui/lib/mih_packages/about_mih/package_tools/mih_info.dart index 44493a26..9f24529b 100644 --- a/mih_ui/lib/mih_packages/about_mih/package_tools/mih_info.dart +++ b/mih_ui/lib/mih_packages/about_mih/package_tools/mih_info.dart @@ -1,18 +1,13 @@ import 'package:flutter_speed_dial/flutter_speed_dial.dart'; -import 'package:go_router/go_router.dart'; import 'package:mih_package_toolkit/mih_package_toolkit.dart'; -import 'package:mzansi_innovation_hub/main.dart'; -import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart'; -import 'package:mzansi_innovation_hub/mih_package_components/mih_profile_links.dart'; +import 'package:mzansi_innovation_hub/mih_packages/about_mih/components/about_mih_heading.dart'; +import 'package:mzansi_innovation_hub/mih_packages/about_mih/components/call_to_action_buttons.dart'; +import 'package:mzansi_innovation_hub/mih_packages/about_mih/components/founder_details.dart'; +import 'package:mzansi_innovation_hub/mih_packages/about_mih/components/mih_social_links.dart'; +import 'package:mzansi_innovation_hub/mih_packages/about_mih/components/mission_and_vission.dart'; import 'package:mzansi_innovation_hub/mih_providers/about_mih_provider.dart'; -import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart'; -import 'package:mzansi_innovation_hub/mih_services/mih_install_services.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:mzansi_innovation_hub/mih_services/mih_user_services.dart'; import 'package:provider/provider.dart'; -import 'package:url_launcher/url_launcher.dart'; import 'package:redacted/redacted.dart'; import 'package:share_plus/share_plus.dart'; @@ -24,199 +19,6 @@ class MihInfo extends StatefulWidget { } class _MihInfoState extends State { - late Future _futureUserCount; - late Future _futureBusinessCount; - - Widget founderBio() { - String bio = ""; - bio += "BSc Computer Science & Information Systems\n"; - bio += "(University of the Western Cape)\n"; - bio += - "6 Year of banking experience with one of the big 5 banks of South Africa."; - return Wrap( - alignment: WrapAlignment.center, - crossAxisAlignment: WrapCrossAlignment.center, - spacing: 10, - runSpacing: 10, - children: [ - SizedBox( - width: 300, - child: Stack( - alignment: Alignment.center, - fit: StackFit.loose, - children: [ - Padding( - padding: const EdgeInsets.only(left: 4.0), - child: CircleAvatar( - backgroundColor: MihColors.primary(), - backgroundImage: const AssetImage( - "lib/mih_package_components/assets/images/founder.jpg"), - //'https://media.licdn.com/dms/image/D4D03AQGd1-QhjtWWpA/profile-displayphoto-shrink_400_400/0/1671698053061?e=2147483647&v=beta&t=a3dJI5yxs5-KeXjj10LcNCFuC9IOfa8nNn3k_Qyr0CA'), - radius: 75, - ), - ), - Icon( - MihIcons.mihRing, - size: 165, - color: MihColors.secondary(), - ), - ], - ), - ), - SizedBox( - width: 400, - child: Text( - bio, - textAlign: TextAlign.center, - style: const TextStyle( - //fontWeight: FontWeight.bold, - fontSize: 17, - ), - ), - ), - const SizedBox( - height: 10, - ), - ], - ); - } - - Widget founderTitle() { - String heading = "Yasien Meth (Founder & CEO)"; - return Column( - children: [ - Text( - heading, - textAlign: TextAlign.center, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 25, - ), - ), - const SizedBox( - height: 10, - ), - ], - ); - } - - Widget ourVision() { - String heading = "Our Vision"; - String vision = - "Digitizing Mzansi one process at a time. Discover essential Mzansi apps to streamline your personal and professional life. Simplify your daily tasks with our user-friendly solutions."; - - return SizedBox( - width: 500, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Text( - heading, - textAlign: TextAlign.center, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 25, - ), - ), - const SizedBox( - height: 10, - ), - Text( - vision, - textAlign: TextAlign.center, - style: const TextStyle( - //fontWeight: FontWeight.bold, - fontSize: 17, - ), - ), - ], - ), - ); - } - - Widget ourMission() { - String heading = "Our Mission"; - String mission = - "Bridge the digital divide in Mzansi, ensuring that everyone can benefit from the power of technology. We empower lives by providing simple, elegant solutions that elevate daily experiences. With our user-friendly approach, we're making the digital world accessible to all, ensuring no one is left behind in the digital revolution."; - return SizedBox( - width: 500, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - heading, - textAlign: TextAlign.center, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 25, - ), - ), - const SizedBox( - height: 10, - ), - Text( - mission, - textAlign: TextAlign.center, - style: const TextStyle( - //fontWeight: FontWeight.bold, - fontSize: 17, - ), - ), - ], - ), - ); - } - - Future launchSocialUrl(Uri linkUrl) async { - if (!await launchUrl(linkUrl)) { - throw Exception('Could not launch $linkUrl'); - } - } - - Widget getInstallButtonText() { - final isWebAndroid = - kIsWeb && (defaultTargetPlatform == TargetPlatform.android); - final isWebIos = kIsWeb && (defaultTargetPlatform == TargetPlatform.iOS); - String btnText = ""; - FaIconData platformIcon; - if (isWebAndroid) { - btnText = "Install MIH"; - platformIcon = FontAwesomeIcons.googlePlay; - } else if (isWebIos) { - btnText = "Install MIH"; - platformIcon = FontAwesomeIcons.appStoreIos; - } else if (MzansiInnovationHub.of(context)!.theme.getPlatform() == - "Android") { - btnText = "Update MIH"; - platformIcon = FontAwesomeIcons.googlePlay; - } else if (MzansiInnovationHub.of(context)!.theme.getPlatform() == "iOS") { - btnText = "Update MIH"; - platformIcon = FontAwesomeIcons.appStoreIos; - } else { - btnText = "Install MIH"; - platformIcon = FontAwesomeIcons.globe; - } - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - FaIcon( - platformIcon, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - btnText, - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ); - } - void shareMIHLink(BuildContext context, String message, String link) { String shareText = "$message: $link"; SharePlus.instance.share( @@ -224,45 +26,26 @@ class _MihInfoState extends State { ); } - Widget displayBusinessCount() { + Widget displayBusinessCount(AboutMihProvider aboutProvider) { return Row( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - FutureBuilder( - future: _futureBusinessCount, - builder: (context, snapshot) { - bool isLoading = true; - String userCount = "⚠️"; - if (snapshot.connectionState == ConnectionState.waiting) { - isLoading = true; - } else if (snapshot.connectionState == ConnectionState.done && - snapshot.hasError) { - isLoading = false; - } else if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - isLoading = false; - userCount = snapshot.data.toString(); - } else { - isLoading = true; - } - return SizedBox( - child: Text( - userCount, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 23, - ), - ), - ).redacted( - context: context, - redact: isLoading, - configuration: RedactedConfiguration( - defaultBorderRadius: BorderRadius.circular(5), - redactedColor: MihColors.secondary(), - ), - ); - }, + SizedBox( + child: Text( + "${aboutProvider.businessCount}", + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 23, + ), + ), + ).redacted( + context: context, + redact: aboutProvider.businessCount == null, + configuration: RedactedConfiguration( + defaultBorderRadius: BorderRadius.circular(5), + redactedColor: MihColors.secondary(), + ), ), const SizedBox(width: 10), Text( @@ -277,45 +60,26 @@ class _MihInfoState extends State { ); } - Widget displayUserCount() { + Widget displayUserCount(AboutMihProvider aboutProvider) { return Row( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - FutureBuilder( - future: _futureUserCount, - builder: (context, snapshot) { - bool isLoading = true; - String userCount = "⚠️"; - if (snapshot.connectionState == ConnectionState.waiting) { - isLoading = true; - } else if (snapshot.connectionState == ConnectionState.done && - snapshot.hasError) { - isLoading = false; - } else if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - isLoading = false; - userCount = snapshot.data.toString(); - } else { - isLoading = true; - } - return SizedBox( - child: Text( - userCount, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 23, - ), - ), - ).redacted( - context: context, - redact: isLoading, - configuration: RedactedConfiguration( - defaultBorderRadius: BorderRadius.circular(5), - redactedColor: MihColors.secondary(), - ), - ); - }, + SizedBox( + child: Text( + "${aboutProvider.businessCount}", + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 23, + ), + ), + ).redacted( + context: context, + redact: aboutProvider.userCount == null, + configuration: RedactedConfiguration( + defaultBorderRadius: BorderRadius.circular(5), + redactedColor: MihColors.secondary(), + ), ), const SizedBox(width: 10), Text( @@ -343,45 +107,7 @@ class _MihInfoState extends State { ); } - Widget aboutHeadings(AboutMihProvider aboutProvider) { - return Column( - children: [ - SizedBox( - width: 165, - child: FittedBox( - child: Icon( - MihIcons.mihLogo, - color: MihColors.secondary(), - ), - ), - ), - const SizedBox( - height: 10, - ), - const Text( - "Mzansi Innovation Hub", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 30, - ), - ), - Text( - "MIH App Version: ${aboutProvider.version}", - textAlign: TextAlign.center, - style: const TextStyle( - fontWeight: FontWeight.normal, - fontSize: 15, - ), - ), - const SizedBox( - height: 10, - ), - ], - ); - } - - Widget communityCounter() { + Widget communityCounter(AboutMihProvider aboutProvider) { return Column( children: [ Wrap( @@ -390,8 +116,8 @@ class _MihInfoState extends State { spacing: 25, runSpacing: 10, children: [ - displayUserCount(), - displayBusinessCount(), + displayUserCount(aboutProvider), + displayBusinessCount(aboutProvider), ], ), Text( @@ -409,447 +135,18 @@ class _MihInfoState extends State { ); } - Widget callToActionsButtons() { - return Column( - children: [ - Wrap( - alignment: WrapAlignment.center, - crossAxisAlignment: WrapCrossAlignment.center, - spacing: 10, - runSpacing: 10, - children: [ - MihButton( - onPressed: () { - if (MzansiInnovationHub.of(context)!.theme.getPlatform() == - "Android") { - showDialog( - context: context, - builder: (context) { - return MihPackageWindow( - fullscreen: false, - windowTitle: "Select Option", - onWindowTapClose: () { - context.pop(); - }, - windowBody: Column( - children: [ - Text( - "Please select the platform you want to install/ Update MIH from", - style: TextStyle( - color: MihColors.secondary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 25), - MihButton( - onPressed: () { - launchSocialUrl( - Uri.parse( - "https://play.google.com/store/apps/details?id=za.co.mzansiinnovationhub.mih", - ), - ); - }, - buttonColor: MihColors.green(), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - FaIcon( - FontAwesomeIcons.googlePlay, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - "Play Store", - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - const SizedBox( - height: 10, - ), - MihButton( - onPressed: () { - launchSocialUrl( - Uri.parse( - "https://appgallery.huawei.com/app/C113315335?pkgName=za.co.mzansiinnovationhub.mih", - ), - ); - }, - buttonColor: MihColors.green(), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - Icons.store, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - "App Gallery", - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - ], - ), - ); - }, - ); - } else { - MihInstallServices().installMihTrigger(context); - } - }, - buttonColor: MihColors.green(), - width: 300, - child: getInstallButtonText(), - ), - MihButton( - onPressed: () { - launchSocialUrl( - Uri.parse( - "https://www.youtube.com/playlist?list=PLuT35kJIui0H5kXjxNOZlHoOPZbQLr4qh", - ), - ); - }, - buttonColor: MihColors.green(), - width: 300, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - FaIcon( - FontAwesomeIcons.youtube, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - "MIH Beginners Guide", - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - MihButton( - onPressed: () { - launchSocialUrl( - Uri.parse( - "https://patreon.com/MzansiInnovationHub?utm_medium=unknown&utm_source=join_link&utm_campaign=creatorshare_creator&utm_content=copyLink", - ), - ); - }, - buttonColor: MihColors.green(), - width: 300, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - FaIcon( - FontAwesomeIcons.patreon, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - "Support Our Journey", - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - ], - ), - const SizedBox( - height: 10, - ), - ], - ); - } - - Widget womenForChange() { - String heading = "MIH Stands with Women For Change SA"; - String mission = - "South Africa is facing a devastating crisis of Gender-Based Violence and Femicide (GBVF), with at least 15 women murdered and 117 women reporting rape daily, often at the hands of known individuals, as highlighted by a shocking 33.8% rise in femicide in the last year, despite the existence of the National Strategic Plan on GBVF (NSP GBVF). Due to the government's lack of urgent action and funding for the NSP GBVF's implementation, organizations like Women For Change are urgently calling for the immediate declaration of GBVF as a National Disaster to mobilize resources and political will for decisive action, which must include judicial reforms (like opposing bail and implementing harsher sentences), immediate funding of the NSP GBVF and the new National Council, making the National Sex Offenders Register publicly accessible, and mandating comprehensive GBVF education and continuous public awareness campaigns."; - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 25.0), - child: SizedBox( - width: 500, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - heading, - textAlign: TextAlign.center, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 25, - ), - ), - const SizedBox( - height: 10, - ), - Wrap( - alignment: WrapAlignment.center, - crossAxisAlignment: WrapCrossAlignment.center, - spacing: 10, - runSpacing: 10, - children: [ - MihButton( - onPressed: () { - launchSocialUrl( - Uri.parse( - "https://www.tiktok.com/@womenforchange.sa", - ), - ); - }, - buttonColor: MihColors.green(), - width: 300, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - FaIcon( - FontAwesomeIcons.tiktok, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - "@womenforchange.sa", - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - MihButton( - onPressed: () { - launchSocialUrl( - Uri.parse( - "https://www.change.org/p/declare-gbvf-a-national-disaster-in-south-africa", - ), - ); - }, - buttonColor: MihColors.green(), - width: 300, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - Icons.edit, - color: MihColors.primary(), - ), - const SizedBox(width: 10), - Text( - "Sign Petition", - style: TextStyle( - color: MihColors.primary(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - ], - ), - const SizedBox( - height: 10, - ), - Text( - mission, - textAlign: TextAlign.center, - style: const TextStyle( - //fontWeight: FontWeight.bold, - fontSize: 17, - ), - ), - ], - ), - ), - ); - } - - Widget missionAndVission() { - return Column( - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 25.0), - child: Wrap( - alignment: WrapAlignment.start, - crossAxisAlignment: WrapCrossAlignment.start, - spacing: 10, - runSpacing: 10, - children: [ - ourVision(), - ourMission(), - ], - ), - ), - const SizedBox( - height: 10, - ), - ], - ); - } - - Widget founderDetails() { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - founderTitle(), - founderBio(), - ], - ); - } - - Widget mihSocials() { - List links = [ - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Youtube", - custom_name: "", - destination: "https://www.youtube.com/@MzansiInnovationHub", - order: 1, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "TikTok", - custom_name: "", - destination: "https://www.tiktok.com/@mzansiinnovationhub", - order: 2, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Twitch", - custom_name: "", - destination: "https://www.twitch.tv/mzansiinnovationhub", - order: 3, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Threads", - custom_name: "", - destination: "https://www.threads.com/@mzansi.innovation.hub", - order: 4, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "WhatsApp", - custom_name: "", - destination: "https://whatsapp.com/channel/0029Vax3INCIyPtMn8KgeM2F", - order: 5, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Instagram", - custom_name: "", - destination: "https://www.instagram.com/mzansi.innovation.hub/", - order: 6, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "X", - custom_name: "", - destination: "https://x.com/mzansi_inno_hub", - order: 7, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "LinkedIn", - custom_name: "", - destination: "https://www.linkedin.com/company/mzansi-innovation-hub/", - order: 8, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Facebook", - custom_name: "", - destination: "https://www.facebook.com/profile.php?id=61565345762136", - order: 9, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Reddit", - custom_name: "", - destination: "https://www.reddit.com/r/Mzani_Innovation_Hub/", - order: 10, - ), - ProfileLink( - idprofile_links: 1, - app_id: "1234", - business_id: "", - site_name: "Git", - custom_name: "", - destination: - "https://git.mzansi-innovation-hub.co.za/yaso_meth/mih-project", - order: 11, - ), - ]; - return Column( - children: [ - Text( - "Follow Our Journey", - textAlign: TextAlign.center, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 25, - ), - ), - const SizedBox( - height: 10, - ), - MihProfileLinks(links: links), - const SizedBox( - height: 75, - ), - ], - ); + Future _syncUserBizCountData() async { + AboutMihProvider aboutProvider = context.read(); + aboutProvider.loadCachedAboutMihSate(); + await aboutProvider.syncWithMihServerData(); } @override void initState() { super.initState(); - _futureUserCount = MihUserServices().fetchUserCount(); - _futureBusinessCount = MihBusinessDetailsServices().fetchBusinessCount(); + WidgetsBinding.instance.addPostFrameCallback((_) { + _syncUserBizCountData(); + }); } @override @@ -874,17 +171,15 @@ class _MihInfoState extends State { scrollbarOn: true, child: Column( children: [ - aboutHeadings(aboutProvider), - communityCounter(), - callToActionsButtons(), - // mihDivider(), - // womenForChange(), + AboutMihHeading(), + communityCounter(aboutProvider), + CallToActionButtons(), mihDivider(), - missionAndVission(), + MissionAndVission(), mihDivider(), - founderDetails(), + FounderDetails(), mihDivider(), - mihSocials(), + MihSocialLinks(), ], ), ), diff --git a/mih_ui/lib/mih_packages/mih_home/mih_home.dart b/mih_ui/lib/mih_packages/mih_home/mih_home.dart index cd29c124..320f4c54 100644 --- a/mih_ui/lib/mih_packages/mih_home/mih_home.dart +++ b/mih_ui/lib/mih_packages/mih_home/mih_home.dart @@ -2,11 +2,13 @@ import 'package:mih_package_toolkit/mih_package_toolkit.dart'; import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart'; import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart'; import 'package:mzansi_innovation_hub/mih_packages/mih_home/components/mih_user_consent_window.dart'; +import 'package:mzansi_innovation_hub/mih_providers/about_mih_provider.dart'; import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart'; import 'package:mzansi_innovation_hub/mih_packages/mih_home/components/mih_app_drawer.dart'; import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tools/mih_business_home.dart'; import 'package:mzansi_innovation_hub/mih_packages/mih_home/package_tools/mih_personal_home.dart'; import 'package:flutter/material.dart'; +import 'package:mzansi_innovation_hub/mih_providers/mzansi_wallet_provider.dart'; import 'package:provider/provider.dart'; class MihHome extends StatefulWidget { @@ -88,8 +90,14 @@ class _MihHomeState extends State { RefreshIndicator( key: mzansiProfileProvider.refreshIndicatorKey, onRefresh: () async { - bool success = - await mzansiProfileProvider.syncWithMihServerData(); + MzansiWalletProvider walletProvider = + context.read(); + AboutMihProvider aboutProvider = + context.read(); + await mzansiProfileProvider.syncWithMihServerData(); + await walletProvider + .syncWithMihServerData(mzansiProfileProvider); + bool success = await aboutProvider.syncWithMihServerData(); if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( MihSnackBar( diff --git a/mih_ui/lib/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart b/mih_ui/lib/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart index 8e7c7d1b..65cd2796 100644 --- a/mih_ui/lib/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart +++ b/mih_ui/lib/mih_packages/mih_home/package_tile/mih_home_refresh_tile.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:mih_package_toolkit/mih_package_toolkit.dart'; +import 'package:mzansi_innovation_hub/mih_providers/about_mih_provider.dart'; import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart'; +import 'package:mzansi_innovation_hub/mih_providers/mzansi_wallet_provider.dart'; import 'package:provider/provider.dart'; class MihHomeRefreshTile extends StatefulWidget { @@ -17,35 +19,34 @@ class MihHomeRefreshTile extends StatefulWidget { class _MihHomeRefreshTileState extends State { @override Widget build(BuildContext context) { - return Consumer( - builder: (BuildContext context, MzansiProfileProvider profileProvider, - Widget? child) { - return MihPackageTile( - onTap: profileProvider.triggerRefresh, - packageName: "Sync Data", - packageIcon: Stack( - alignment: Alignment.center, - children: [ - Icon( - MihIcons.mihRing, + return MihPackageTile( + onTap: () async { + MzansiProfileProvider profileProvider = + context.read(); + profileProvider.triggerRefresh(); + }, + packageName: "Sync Data", + packageIcon: Stack( + alignment: Alignment.center, + children: [ + Icon( + MihIcons.mihRing, + color: MihColors.secondary(), + ), + Center( + child: Transform.scale( + scale: 0.75, + origin: Offset(-4, 0), + child: Icon( + Icons.cloud_sync_rounded, color: MihColors.secondary(), ), - Center( - child: Transform.scale( - scale: 0.75, - origin: Offset(-4, 0), - child: Icon( - Icons.cloud_sync_rounded, - color: MihColors.secondary(), - ), - ), - ), - ], + ), ), - iconSize: widget.packageSize, - textColor: MihColors.secondary(), - ); - }, + ], + ), + iconSize: widget.packageSize, + textColor: MihColors.secondary(), ); } } diff --git a/mih_ui/lib/mih_packages/mzansi_ai/mzansi_ai.dart b/mih_ui/lib/mih_packages/mzansi_ai/mzansi_ai.dart index 60bc360b..ff081e5a 100644 --- a/mih_ui/lib/mih_packages/mzansi_ai/mzansi_ai.dart +++ b/mih_ui/lib/mih_packages/mzansi_ai/mzansi_ai.dart @@ -4,7 +4,6 @@ import 'package:mzansi_innovation_hub/mih_providers/mzansi_ai_provider.dart'; import 'package:flutter/material.dart'; import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_ai/package_tools/mih_ai_chat.dart'; -import 'package:mzansi_innovation_hub/mih_services/mih_data_helper_services.dart'; import 'package:provider/provider.dart'; class MzansiAi extends StatefulWidget { @@ -17,37 +16,36 @@ class MzansiAi extends StatefulWidget { } class _MzansiAiState extends State { - bool _isLoadingInitialData = true; late final MihAiChat _aiChat; - Future _loadInitialData() async { - setState(() { - _isLoadingInitialData = true; - }); + Future _syncProfileData() async { MzansiProfileProvider mzansiProfileProvider = context.read(); + mzansiProfileProvider.loadCachedProfileState(); if (mzansiProfileProvider.user == null) { - await MihDataHelperServices().loadUserDataWithBusinessesData( - mzansiProfileProvider, - ); + await mzansiProfileProvider.syncWithMihServerData(); + } else { + await mzansiProfileProvider.syncWithMihServerData(); } - setState(() { - _isLoadingInitialData = false; - }); } @override void initState() { super.initState(); _aiChat = MihAiChat(); - _loadInitialData(); + _syncProfileData(); } @override Widget build(BuildContext context) { - return Consumer( - builder: (BuildContext context, MzansiAiProvider value, Widget? child) { - if (_isLoadingInitialData) { + return Consumer2( + builder: ( + BuildContext context, + MzansiAiProvider aiProvider, + MzansiProfileProvider profileProvider, + Widget? child, + ) { + if (profileProvider.user == null) { return Scaffold( body: Center( child: Mihloadingcircle(), diff --git a/mih_ui/lib/mih_packages/mzansi_wallet/mih_wallet.dart b/mih_ui/lib/mih_packages/mzansi_wallet/mih_wallet.dart index cf61c013..5ddd4f32 100644 --- a/mih_ui/lib/mih_packages/mzansi_wallet/mih_wallet.dart +++ b/mih_ui/lib/mih_packages/mzansi_wallet/mih_wallet.dart @@ -5,8 +5,6 @@ import 'package:mzansi_innovation_hub/mih_providers/mzansi_wallet_provider.dart' import 'package:flutter/material.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/package_tools/mih_card_favourites.dart'; import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/package_tools/mih_cards.dart'; -import 'package:mzansi_innovation_hub/mih_services/mih_data_helper_services.dart'; -import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_wallet_services.dart'; import 'package:provider/provider.dart'; class MihWallet extends StatefulWidget { diff --git a/mih_ui/lib/mih_providers/about_mih_provider.dart b/mih_ui/lib/mih_providers/about_mih_provider.dart index e5da12d0..05288d0d 100644 --- a/mih_ui/lib/mih_providers/about_mih_provider.dart +++ b/mih_ui/lib/mih_providers/about_mih_provider.dart @@ -1,13 +1,34 @@ import 'package:flutter/foundation.dart'; +import 'package:ken_logger/ken_logger.dart'; +import 'package:mzansi_innovation_hub/mih_hive/about_mih_hive_data.dart'; class AboutMihProvider extends ChangeNotifier { - int toolIndex; - String version = "1.3.0"; + final AboutMihHiveData _hiveData; - AboutMihProvider({ + int toolIndex; + String version = "1.4.0"; + int? userCount; + int? businessCount; + + AboutMihProvider( + this._hiveData, { this.toolIndex = 0, }); + void loadCachedAboutMihSate() { + userCount = _hiveData.getcachedUserCount(); + businessCount = _hiveData.getcachedBusinessCount(); + + KenLogger.success("About Mih Data Loaded from Cache"); + notifyListeners(); + } + + Future syncWithMihServerData() async { + bool success = await _hiveData.syncAboutMihDataWithServer(); + loadCachedAboutMihSate(); + return success; + } + void reset() { toolIndex = 0; notifyListeners();