diff --git a/assets/images/png/smartwatches/Apple-Watch-6.png b/assets/images/png/smartwatches/Apple-Watch-6.png new file mode 100644 index 0000000..1e67050 Binary files /dev/null and b/assets/images/png/smartwatches/Apple-Watch-6.png differ diff --git a/assets/images/png/smartwatches/apple-watch-1.jpeg b/assets/images/png/smartwatches/apple-watch-1.jpeg new file mode 100644 index 0000000..7262e7e Binary files /dev/null and b/assets/images/png/smartwatches/apple-watch-1.jpeg differ diff --git a/assets/images/png/smartwatches/apple-watch-2.jpg b/assets/images/png/smartwatches/apple-watch-2.jpg new file mode 100644 index 0000000..f688f74 Binary files /dev/null and b/assets/images/png/smartwatches/apple-watch-2.jpg differ diff --git a/assets/images/png/smartwatches/apple-watch-3.jpg b/assets/images/png/smartwatches/apple-watch-3.jpg new file mode 100644 index 0000000..b68c1ce Binary files /dev/null and b/assets/images/png/smartwatches/apple-watch-3.jpg differ diff --git a/assets/images/png/smartwatches/apple-watch-4.jpg b/assets/images/png/smartwatches/apple-watch-4.jpg new file mode 100644 index 0000000..2fc19b6 Binary files /dev/null and b/assets/images/png/smartwatches/apple-watch-4.jpg differ diff --git a/assets/images/png/smartwatches/apple-watch-5.jpg b/assets/images/png/smartwatches/apple-watch-5.jpg new file mode 100644 index 0000000..4c497ea Binary files /dev/null and b/assets/images/png/smartwatches/apple-watch-5.jpg differ diff --git a/assets/images/png/smartwatches/bloodoxygen_icon.svg b/assets/images/png/smartwatches/bloodoxygen_icon.svg new file mode 100644 index 0000000..0971a30 --- /dev/null +++ b/assets/images/png/smartwatches/bloodoxygen_icon.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/images/png/smartwatches/calories_icon.svg b/assets/images/png/smartwatches/calories_icon.svg new file mode 100644 index 0000000..660ce0d --- /dev/null +++ b/assets/images/png/smartwatches/calories_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/png/smartwatches/distance_icon.svg b/assets/images/png/smartwatches/distance_icon.svg new file mode 100644 index 0000000..29dcf3d --- /dev/null +++ b/assets/images/png/smartwatches/distance_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/png/smartwatches/galaxy_fit_3.jpg b/assets/images/png/smartwatches/galaxy_fit_3.jpg new file mode 100644 index 0000000..ff05834 Binary files /dev/null and b/assets/images/png/smartwatches/galaxy_fit_3.jpg differ diff --git a/assets/images/png/smartwatches/galaxy_watch_7.webp b/assets/images/png/smartwatches/galaxy_watch_7.webp new file mode 100644 index 0000000..09748b4 Binary files /dev/null and b/assets/images/png/smartwatches/galaxy_watch_7.webp differ diff --git a/assets/images/png/smartwatches/galaxy_watch_7_classic.jpg b/assets/images/png/smartwatches/galaxy_watch_7_classic.jpg new file mode 100644 index 0000000..f177dd4 Binary files /dev/null and b/assets/images/png/smartwatches/galaxy_watch_7_classic.jpg differ diff --git a/assets/images/png/smartwatches/galaxy_watch_8.jpg b/assets/images/png/smartwatches/galaxy_watch_8.jpg new file mode 100644 index 0000000..7fd4746 Binary files /dev/null and b/assets/images/png/smartwatches/galaxy_watch_8.jpg differ diff --git a/assets/images/png/smartwatches/galaxy_watch_8_classic.jpeg b/assets/images/png/smartwatches/galaxy_watch_8_classic.jpeg new file mode 100644 index 0000000..6e84096 Binary files /dev/null and b/assets/images/png/smartwatches/galaxy_watch_8_classic.jpeg differ diff --git a/assets/images/png/smartwatches/galaxy_watch_ultra.jpg b/assets/images/png/smartwatches/galaxy_watch_ultra.jpg new file mode 100644 index 0000000..e401d73 Binary files /dev/null and b/assets/images/png/smartwatches/galaxy_watch_ultra.jpg differ diff --git a/assets/images/png/smartwatches/heartrate_icon.svg b/assets/images/png/smartwatches/heartrate_icon.svg new file mode 100644 index 0000000..dac05ef --- /dev/null +++ b/assets/images/png/smartwatches/heartrate_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/png/smartwatches/steps_icon.svg b/assets/images/png/smartwatches/steps_icon.svg new file mode 100644 index 0000000..4af073a --- /dev/null +++ b/assets/images/png/smartwatches/steps_icon.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/images/svg/daily_water_monitor.svg b/assets/images/svg/daily_water_monitor.svg new file mode 100644 index 0000000..b5f057d --- /dev/null +++ b/assets/images/svg/daily_water_monitor.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/images/svg/health_calculators_services_icon.svg b/assets/images/svg/health_calculators_services_icon.svg new file mode 100644 index 0000000..9f30d08 --- /dev/null +++ b/assets/images/svg/health_calculators_services_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/images/svg/health_converters_icon.svg b/assets/images/svg/health_converters_icon.svg new file mode 100644 index 0000000..225ad01 --- /dev/null +++ b/assets/images/svg/health_converters_icon.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/images/svg/smartwatch_icon.svg b/assets/images/svg/smartwatch_icon.svg new file mode 100644 index 0000000..162ab36 --- /dev/null +++ b/assets/images/svg/smartwatch_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 8f2ef94..ab9828e 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -71,6 +71,8 @@ This app requires contacts access to show incoming virtual consultation request. NSFaceIDUsageDescription This app requires Face ID to allow biometric authentication for app login. + NSHealthClinicalHealthRecordsShareUsageDescription + This App need access to HealthKit to read heart rate & other data from your smart watch. NSHealthShareUsageDescription This App need access to HealthKit to read heart rate & other data from your smart watch. NSHealthUpdateUsageDescription diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements index 319178a..2c37e77 100644 --- a/ios/Runner/Runner.entitlements +++ b/ios/Runner/Runner.entitlements @@ -4,6 +4,14 @@ aps-environment development + com.apple.developer.healthkit + + com.apple.developer.healthkit.access + + health-records + + com.apple.developer.healthkit.background-delivery + com.apple.developer.in-app-payments merchant.com.hmgwebservices diff --git a/lib/core/app_assets.dart b/lib/core/app_assets.dart index f5d0fe5..aa8d26e 100644 --- a/lib/core/app_assets.dart +++ b/lib/core/app_assets.dart @@ -202,6 +202,10 @@ class AppAssets { static const String insurance_approval_icon = '$svgBasePath/insurance_approval_icon.svg'; static const String invoices_list_icon = '$svgBasePath/invoices_list_icon.svg'; static const String ancillary_orders_list_icon = '$svgBasePath/ancillary_orders_list_icon.svg'; + static const String daily_water_monitor_icon = '$svgBasePath/daily_water_monitor.svg'; + static const String health_calculators_services_icon = '$svgBasePath/health_calculators_services_icon.svg'; + static const String health_converters_icon = '$svgBasePath/health_converters_icon.svg'; + static const String smartwatch_icon = '$svgBasePath/smartwatch_icon.svg'; //bottom navigation// static const String homeBottom = '$svgBasePath/home_bottom.svg'; diff --git a/lib/core/dependencies.dart b/lib/core/dependencies.dart index 4c17de6..054819e 100644 --- a/lib/core/dependencies.dart +++ b/lib/core/dependencies.dart @@ -39,6 +39,7 @@ import 'package:hmg_patient_app_new/features/prescriptions/prescriptions_view_mo import 'package:hmg_patient_app_new/features/profile_settings/profile_settings_view_model.dart'; import 'package:hmg_patient_app_new/features/radiology/radiology_repo.dart'; import 'package:hmg_patient_app_new/features/radiology/radiology_view_model.dart'; +import 'package:hmg_patient_app_new/features/smartwatch_health_data/health_provider.dart'; import 'package:hmg_patient_app_new/features/symptoms_checker/symptoms_checker_repo.dart'; import 'package:hmg_patient_app_new/features/symptoms_checker/symptoms_checker_view_model.dart'; import 'package:hmg_patient_app_new/features/todo_section/todo_section_repo.dart'; @@ -232,6 +233,10 @@ class AppDependencies { () => BloodDonationViewModel(bloodDonationRepo: getIt(), errorHandlerService: getIt(), navigationService: getIt(), dialogService: getIt(), appState: getIt()), ); + getIt.registerLazySingleton( + () => HealthProvider(), + ); + // Screen-specific VMs → Factory // getIt.registerFactory( // () => BookAppointmentsViewModel( diff --git a/lib/features/smartwatch_health_data/health_provider.dart b/lib/features/smartwatch_health_data/health_provider.dart new file mode 100644 index 0000000..fc9dacc --- /dev/null +++ b/lib/features/smartwatch_health_data/health_provider.dart @@ -0,0 +1,85 @@ +import 'package:flutter/foundation.dart'; +import 'package:health/health.dart'; +import 'package:hmg_patient_app_new/features/smartwatch_health_data/health_service.dart'; + +class HealthProvider with ChangeNotifier { + final HealthService _healthService = HealthService(); + Map> healthData = {}; + bool isLoading = false; + String? error; + String selectedTimeRange = '7D'; + int selectedTabIndex = 0; + + void onTabChanged(int index) { + selectedTabIndex = index; + notifyListeners(); + } + + Future fetchHealthData() async { + isLoading = true; + error = null; + notifyListeners(); + healthData.clear(); + try { + final authorized = await _healthService.requestAuthorization(); + if (!authorized) { + error = 'Health data access not authorized'; + isLoading = false; + notifyListeners(); + return; + } + + final startTime = _getStartDate(); + final endTime = DateTime.now(); + + healthData = await _healthService.getAllHealthData(startTime, endTime); + + isLoading = false; + notifyListeners(); + } catch (e) { + error = 'Error fetching health data: $e'; + isLoading = false; + notifyListeners(); + } + } + + Future refreshMetric(HealthDataType type) async { + try { + final startTime = _getStartDate(); + final endTime = DateTime.now(); + + final data = await _healthService.getSpecificHealthData( + type, + startTime, + endTime, + ); + + healthData[type] = data; + notifyListeners(); + } catch (e) { + print('Error refreshing metric $type: $e'); + } + } + + void updateTimeRange(String range) { + selectedTimeRange = range; + fetchHealthData(); + } + + DateTime _getStartDate() { + switch (selectedTimeRange) { + case '1D': + return DateTime.now().subtract(const Duration(days: 1)); + case '7D': + return DateTime.now().subtract(const Duration(days: 7)); + case '1M': + return DateTime.now().subtract(const Duration(days: 30)); + case '3M': + return DateTime.now().subtract(const Duration(days: 90)); + case '1Y': + return DateTime.now().subtract(const Duration(days: 365)); + default: + return DateTime.now().subtract(const Duration(days: 7)); + } + } +} diff --git a/lib/features/smartwatch_health_data/health_service.dart b/lib/features/smartwatch_health_data/health_service.dart new file mode 100644 index 0000000..c5dca48 --- /dev/null +++ b/lib/features/smartwatch_health_data/health_service.dart @@ -0,0 +1,166 @@ +import 'dart:io'; + +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:health/health.dart'; +import 'package:permission_handler/permission_handler.dart'; + +import 'health_utils.dart'; + +class HealthService { + static final HealthService _instance = HealthService._internal(); + + factory HealthService() => _instance; + + HealthService._internal(); + + final Health health = Health(); + + final List _healthMetrics = [ + HealthDataType.HEART_RATE, + // HealthDataType.STEPS, + // HealthDataType.BLOOD_OXYGEN, + // HealthDataType.BLOOD_PRESSURE_SYSTOLIC, + // HealthDataType.BLOOD_PRESSURE_DIASTOLIC, + // HealthDataType.BODY_TEMPERATURE, + // HealthDataType.DISTANCE_WALKING_RUNNING, + // HealthDataType.ACTIVE_ENERGY_BURNED, + ]; + + final List _healthMetricsAndroid = [ + HealthDataType.HEART_RATE, + HealthDataType.STEPS, + HealthDataType.BLOOD_OXYGEN, + // HealthDataType.BLOOD_PRESSURE_SYSTOLIC, + // HealthDataType.BLOOD_PRESSURE_DIASTOLIC, + // HealthDataType.BODY_TEMPERATURE, + HealthDataType.DISTANCE_DELTA, + HealthDataType.ACTIVE_ENERGY_BURNED, + HealthDataType.BASAL_ENERGY_BURNED, + HealthDataType.TOTAL_CALORIES_BURNED + ]; + + final List _healthPermissions = [ + HealthDataType.HEART_RATE, + HealthDataType.STEPS, + HealthDataType.BLOOD_OXYGEN, + // HealthDataType.BLOOD_PRESSURE_SYSTOLIC, + // HealthDataType.BLOOD_PRESSURE_DIASTOLIC, + // HealthDataType.BODY_TEMPERATURE, + Platform.isAndroid ? HealthDataType.DISTANCE_DELTA : HealthDataType.DISTANCE_WALKING_RUNNING, + HealthDataType.ACTIVE_ENERGY_BURNED, + HealthDataType.BASAL_ENERGY_BURNED, + HealthDataType.TOTAL_CALORIES_BURNED + ]; + + final List _healthMetricsCumulative = [ + HealthDataType.BLOOD_OXYGEN, + HealthDataType.STEPS, + Platform.isAndroid ? HealthDataType.DISTANCE_DELTA : HealthDataType.DISTANCE_WALKING_RUNNING, + HealthDataType.ACTIVE_ENERGY_BURNED, + HealthDataType.BASAL_ENERGY_BURNED, + HealthDataType.TOTAL_CALORIES_BURNED + ]; + + Future requestAuthorization() async { + try { + final types = (Platform.isAndroid) ? dataTypesAndroid : _healthPermissions; + final granted = await health.requestAuthorization(types); + await Permission.activityRecognition.request(); + await Permission.location.request(); + // request access to read historic data + await Health().requestHealthDataHistoryAuthorization(); + // await authorize(); + return granted; + } catch (e) { + print('Authorization error: $e'); + return false; + } + } + + Future>> getAllHealthData( + DateTime startTime, + DateTime endTime, + ) async { + final Map> allData = {}; + + try { + for (var type in _healthMetricsCumulative) { + try { + final data = await health.getHealthIntervalDataFromTypes( + startDate: startTime, + endDate: endTime, + types: [type], + interval: 86400, + ); + + if (type == HealthDataType.BLOOD_OXYGEN) { + for (var point in data) { + if (point.value is NumericHealthValue) { + final numericValue = (point.value as NumericHealthValue).numericValue; + point.value = NumericHealthValue( + numericValue: numericValue * 100, + ); + } + } + } + + if (type == HealthDataType.DISTANCE_WALKING_RUNNING) { + for (var point in data) { + if (point.value is NumericHealthValue) { + final numericValue = (point.value as NumericHealthValue).numericValue; + point.value = NumericHealthValue( + numericValue: numericValue / 1000, + ); + } + } + } + + allData[type] = data; + } catch (e) { + print('Error fetching $type: $e'); + allData[type] = []; + } + } + + for (var type in Platform.isIOS ? _healthMetrics : _healthMetricsAndroid) { + try { + final data = await health.getHealthDataFromTypes( + startTime: startTime, + endTime: endTime, + types: [type], + // includeManualEntry: false + // interval: 86400, + ); + + allData[type] = data; + } catch (e) { + print('Error fetching $type: $e'); + allData[type] = []; + } + } + } catch (e) { + print('Error fetching health data: $e'); + } + + return allData; + } + + Future> getSpecificHealthData( + HealthDataType type, + DateTime startTime, + DateTime endTime, + ) async { + try { + final data = await health.getHealthDataFromTypes( + startTime: startTime, + endTime: endTime, + types: [type], + ); + return data; + } catch (e) { + print('Error fetching $type: $e'); + return []; + } + } +} diff --git a/lib/features/smartwatch_health_data/health_utils.dart b/lib/features/smartwatch_health_data/health_utils.dart new file mode 100644 index 0000000..3d3588e --- /dev/null +++ b/lib/features/smartwatch_health_data/health_utils.dart @@ -0,0 +1,109 @@ +import 'package:health/health.dart'; + +/// Data types available on iOS via Apple Health. +const List dataTypesIOS = [ + HealthDataType.ACTIVE_ENERGY_BURNED, + HealthDataType.APPLE_STAND_TIME, + HealthDataType.APPLE_STAND_HOUR, + HealthDataType.APPLE_MOVE_TIME, + HealthDataType.AUDIOGRAM, + HealthDataType.BASAL_ENERGY_BURNED, + HealthDataType.BLOOD_GLUCOSE, + HealthDataType.BLOOD_OXYGEN, + HealthDataType.BLOOD_PRESSURE_DIASTOLIC, + HealthDataType.BLOOD_PRESSURE_SYSTOLIC, + HealthDataType.BODY_FAT_PERCENTAGE, + HealthDataType.BODY_MASS_INDEX, + HealthDataType.BODY_TEMPERATURE, + HealthDataType.DIETARY_CARBS_CONSUMED, + HealthDataType.DIETARY_CAFFEINE, + HealthDataType.DIETARY_ENERGY_CONSUMED, + HealthDataType.DIETARY_FATS_CONSUMED, + HealthDataType.DIETARY_PROTEIN_CONSUMED, + HealthDataType.ELECTRODERMAL_ACTIVITY, + HealthDataType.FORCED_EXPIRATORY_VOLUME, + HealthDataType.HEART_RATE, + HealthDataType.HEART_RATE_VARIABILITY_SDNN, + HealthDataType.HEIGHT, + HealthDataType.INSULIN_DELIVERY, + HealthDataType.RESPIRATORY_RATE, + HealthDataType.PERIPHERAL_PERFUSION_INDEX, + HealthDataType.STEPS, + HealthDataType.WAIST_CIRCUMFERENCE, + HealthDataType.WEIGHT, + HealthDataType.FLIGHTS_CLIMBED, + HealthDataType.DISTANCE_WALKING_RUNNING, + HealthDataType.WALKING_SPEED, + HealthDataType.MINDFULNESS, + HealthDataType.SLEEP_AWAKE, + HealthDataType.SLEEP_ASLEEP, + HealthDataType.SLEEP_IN_BED, + HealthDataType.SLEEP_LIGHT, + HealthDataType.SLEEP_DEEP, + HealthDataType.SLEEP_REM, + HealthDataType.WATER, + HealthDataType.EXERCISE_TIME, + HealthDataType.WORKOUT, + HealthDataType.HEADACHE_NOT_PRESENT, + HealthDataType.HEADACHE_MILD, + HealthDataType.HEADACHE_MODERATE, + HealthDataType.HEADACHE_SEVERE, + HealthDataType.HEADACHE_UNSPECIFIED, + HealthDataType.LEAN_BODY_MASS, + + // note that a phone cannot write these ECG-based types - only read them + // HealthDataType.ELECTROCARDIOGRAM, + // HealthDataType.HIGH_HEART_RATE_EVENT, + // HealthDataType.IRREGULAR_HEART_RATE_EVENT, + // HealthDataType.LOW_HEART_RATE_EVENT, + // HealthDataType.RESTING_HEART_RATE, + // HealthDataType.WALKING_HEART_RATE, + // HealthDataType.ATRIAL_FIBRILLATION_BURDEN, + + HealthDataType.NUTRITION, + HealthDataType.GENDER, + HealthDataType.BLOOD_TYPE, + HealthDataType.BIRTH_DATE, + HealthDataType.MENSTRUATION_FLOW, + HealthDataType.WATER_TEMPERATURE, + HealthDataType.UNDERWATER_DEPTH, + HealthDataType.UV_INDEX, +]; + +/// Data types available on Android via the Google Health Connect API. +const List dataTypesAndroid = [ + HealthDataType.ACTIVE_ENERGY_BURNED, + // HealthDataType.BASAL_ENERGY_BURNED, + // HealthDataType.BLOOD_GLUCOSE, + HealthDataType.BLOOD_OXYGEN, + // HealthDataType.BLOOD_PRESSURE_DIASTOLIC, + // HealthDataType.BLOOD_PRESSURE_SYSTOLIC, + // HealthDataType.BODY_FAT_PERCENTAGE, + // HealthDataType.HEIGHT, + // HealthDataType.WEIGHT, + // HealthDataType.LEAN_BODY_MASS, + // HealthDataType.BODY_MASS_INDEX, + // HealthDataType.BODY_TEMPERATURE, + HealthDataType.HEART_RATE, + // HealthDataType.HEART_RATE_VARIABILITY_RMSSD, + HealthDataType.STEPS, + HealthDataType.DISTANCE_DELTA, + // HealthDataType.SPEED, + HealthDataType.RESPIRATORY_RATE, + // HealthDataType.SLEEP_ASLEEP, + // HealthDataType.SLEEP_AWAKE_IN_BED, + // HealthDataType.SLEEP_AWAKE, + // HealthDataType.SLEEP_DEEP, + // HealthDataType.SLEEP_LIGHT, + // HealthDataType.SLEEP_OUT_OF_BED, + // HealthDataType.SLEEP_REM, + // HealthDataType.SLEEP_UNKNOWN, + // HealthDataType.SLEEP_SESSION, + // HealthDataType.WATER, + // HealthDataType.WORKOUT, + HealthDataType.RESTING_HEART_RATE, + // HealthDataType.FLIGHTS_CLIMBED, + // HealthDataType.NUTRITION, + HealthDataType.TOTAL_CALORIES_BURNED, + // HealthDataType.MENSTRUATION_FLOW, +]; \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 30714c6..409503e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,6 +28,7 @@ import 'package:hmg_patient_app_new/features/payfort/payfort_view_model.dart'; import 'package:hmg_patient_app_new/features/prescriptions/prescriptions_view_model.dart'; import 'package:hmg_patient_app_new/features/profile_settings/profile_settings_view_model.dart'; import 'package:hmg_patient_app_new/features/radiology/radiology_view_model.dart'; +import 'package:hmg_patient_app_new/features/smartwatch_health_data/health_provider.dart'; import 'package:hmg_patient_app_new/features/todo_section/todo_section_view_model.dart'; import 'package:hmg_patient_app_new/features/symptoms_checker/symptoms_checker_view_model.dart'; import 'package:hmg_patient_app_new/routes/app_routes.dart'; @@ -153,6 +154,9 @@ void main() async { ), ChangeNotifierProvider( create: (_) => getIt.get(), + ), + ChangeNotifierProvider( + create: (_) => getIt.get(), ) ], child: MyApp()), ), diff --git a/lib/presentation/book_appointment/book_appointment_page.dart b/lib/presentation/book_appointment/book_appointment_page.dart index 0e60a28..a27e76d 100644 --- a/lib/presentation/book_appointment/book_appointment_page.dart +++ b/lib/presentation/book_appointment/book_appointment_page.dart @@ -118,6 +118,7 @@ class _BookAppointmentPageState extends State { : myAppointmentsVM.patientMyDoctorsList.isEmpty ? SizedBox() : Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ if (appState.isAuthenticated) ...[], "Recent Visits".needTranslation.toText18(isBold: true).paddingSymmetrical(24.w, 0.h), diff --git a/lib/presentation/hmg_services/services_page.dart b/lib/presentation/hmg_services/services_page.dart index 85ccdac..1d4131a 100644 --- a/lib/presentation/hmg_services/services_page.dart +++ b/lib/presentation/hmg_services/services_page.dart @@ -120,6 +120,45 @@ class ServicesPage extends StatelessWidget { // ) ]; + late final List hmgHealthToolServices = [ + HmgServicesComponentModel( + 11, + "Daily Water Monitor".needTranslation, + "".needTranslation, + AppAssets.daily_water_monitor_icon, + bgColor: AppColors.whiteColor, + true, + route: AppRoutes.eReferralPage, + ), + HmgServicesComponentModel( + 11, + "Health\nCalculators".needTranslation, + "".needTranslation, + AppAssets.health_calculators_services_icon, + bgColor: AppColors.whiteColor, + true, + route: AppRoutes.eReferralPage, + ), + HmgServicesComponentModel( + 5, + "Health\nConverters".needTranslation, + "".needTranslation, + AppAssets.health_converters_icon, + bgColor: AppColors.whiteColor, + true, + route: AppRoutes.comprehensiveCheckupPage, + ), + HmgServicesComponentModel( + 11, + "Smart\nWatches".needTranslation, + "".needTranslation, + AppAssets.smartwatch_icon, + bgColor: AppColors.whiteColor, + true, + route: AppRoutes.smartWatches, + ), + ]; + @override Widget build(BuildContext context) { bloodDonationViewModel = Provider.of(context); @@ -149,7 +188,7 @@ class ServicesPage extends StatelessWidget { itemCount: hmgServices.length, padding: EdgeInsets.zero, itemBuilder: (BuildContext context, int index) { - return ServiceGridViewItem(hmgServices[index], index, false); + return ServiceGridViewItem(hmgServices[index], index, false, isHealthToolIcon: false); }, ), SizedBox(height: 24.h), @@ -298,6 +337,29 @@ class ServicesPage extends StatelessWidget { ], ), SizedBox(height: 24.h), + "Health Tools".needTranslation.toText18(isBold: true), + SizedBox(height: 16.h), + GridView.builder( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, // 4 icons per row + crossAxisSpacing: 12.w, + mainAxisSpacing: 18.h, + childAspectRatio: 0.8, + ), + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: hmgHealthToolServices.length, + padding: EdgeInsets.zero, + itemBuilder: (BuildContext context, int index) { + return ServiceGridViewItem( + hmgHealthToolServices[index], + index, + false, + isHealthToolIcon: true, + ); + }, + ), + SizedBox(height: 24.h), "Support Services".needTranslation.toText18(isBold: true), SizedBox(height: 16.h), Column( diff --git a/lib/presentation/hmg_services/services_view.dart b/lib/presentation/hmg_services/services_view.dart index b24b0b4..3f0c44e 100644 --- a/lib/presentation/hmg_services/services_view.dart +++ b/lib/presentation/hmg_services/services_view.dart @@ -13,8 +13,10 @@ class ServiceGridViewItem extends StatelessWidget { final int index; final bool isHomePage; final bool isLocked; + final bool isHealthToolIcon; final Function? onTap; - const ServiceGridViewItem(this.hmgServiceComponentModel, this.index, this.isHomePage, {super.key, this.isLocked = false, this.onTap}); + + const ServiceGridViewItem(this.hmgServiceComponentModel, this.index, this.isHomePage, {super.key, this.isLocked = false, this.onTap, this.isHealthToolIcon = false}); @override Widget build(BuildContext context) { @@ -42,7 +44,7 @@ class ServiceGridViewItem extends StatelessWidget { padding: EdgeInsets.all(12.h), child: Utils.buildSvgWithAssets( icon: hmgServiceComponentModel.icon, - iconColor: AppColors.whiteColor, + iconColor: isHealthToolIcon ? null : AppColors.whiteColor, fit: BoxFit.contain, ), ), diff --git a/lib/presentation/smartwatches/health_dashboard/health_dashboard.dart b/lib/presentation/smartwatches/health_dashboard/health_dashboard.dart new file mode 100644 index 0000000..7ede201 --- /dev/null +++ b/lib/presentation/smartwatches/health_dashboard/health_dashboard.dart @@ -0,0 +1,422 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:hmg_patient_app_new/core/app_state.dart'; +import 'package:hmg_patient_app_new/core/dependencies.dart'; +import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; +import 'package:hmg_patient_app_new/core/utils/utils.dart'; +import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; +import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; +import 'package:hmg_patient_app_new/features/smartwatch_health_data/health_provider.dart'; +import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/presentation/smartwatches/widgets/health_metric.dart'; +import 'package:hmg_patient_app_new/presentation/smartwatches/widgets/health_metric_card.dart'; +import 'package:hmg_patient_app_new/theme/colors.dart'; +import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; +import 'package:hmg_patient_app_new/widgets/custom_tab_bar.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:provider/provider.dart'; +import 'package:health/health.dart'; +import 'package:intl/intl.dart'; + +class HealthDashboard extends StatefulWidget { + const HealthDashboard({Key? key}) : super(key: key); + + @override + _HealthDashboardState createState() => _HealthDashboardState(); +} + +class _HealthDashboardState extends State with SingleTickerProviderStateMixin { + late TabController _tabController; + final dateFormat = DateFormat('MMM dd, yyyy'); + final timeFormat = DateFormat('hh:mm a'); + + @override + void initState() { + super.initState(); + _tabController = TabController(length: 2, vsync: this); + Future.microtask( + () async { + await Health().configure(); + context.read().fetchHealthData(); + }, + ); + } + + @override + void dispose() { + _tabController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: AppColors.bgScaffoldColor, + body: Consumer( + builder: (context, healthProvider, child) { + return SingleChildScrollView( + child: Column( + children: [ + SizedBox(height: 96.h), + CustomTabBar( + activeTextColor: Color(0xffED1C2B), + activeBackgroundColor: Color(0xffED1C2B).withValues(alpha: .1), + tabs: [ + CustomTabBarModel(null, "Overview".needTranslation), + CustomTabBarModel(null, "Details".needTranslation), + ], + onTabChange: (index) { + healthProvider.onTabChanged(index); + }, + ).paddingSymmetrical(24.h, 0.h), + SizedBox(height: 24.h), + getSelectedTabData(healthProvider.selectedTabIndex, healthProvider).paddingSymmetrical(24.w, 0), + ], + ), + ); + }, + ), + floatingActionButton: FloatingActionButton( + onPressed: () => context.read().fetchHealthData(), + tooltip: 'Refresh health data', + child: Icon(Icons.refresh), + ), + ); + } + + Widget getSelectedTabData(int index, HealthProvider healthProvider) { + switch (index) { + case 0: + return _buildOverviewTab(healthProvider); + case 1: + return _buildDetailsTab(healthProvider); + default: + SizedBox.shrink(); + } + return Container(); + } + + Widget _buildOverviewTab(HealthProvider healthProvider) { + if (healthProvider.isLoading) { + return _buildLoadingState(); + } + + if (healthProvider.error != null) { + return _buildErrorState(healthProvider.error!); + } + return CustomScrollView( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + slivers: [ + SliverToBoxAdapter( + child: _buildTimeRangeSelector(healthProvider), + ), + SliverPadding( + padding: EdgeInsets.symmetric(vertical: 12.w), + sliver: SliverGrid( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + mainAxisSpacing: 16, + crossAxisSpacing: 16, + childAspectRatio: 0.62, + ), + delegate: SliverChildBuilderDelegate( + (context, index) { + final metric = HealthMetrics.metrics[index]; + return HealthMetricCard( + metric: metric, + data: healthProvider.healthData[metric.type] ?? [], + onTap: () => _showMetricDetails(context, metric, healthProvider), + ); + }, + childCount: HealthMetrics.metrics.length, + ), + ), + ), + ], + ); + } + + Widget _buildDetailsTab(HealthProvider healthProvider) { + return ListView.builder( + padding: const EdgeInsets.all(16), + itemCount: HealthMetrics.metrics.length, + shrinkWrap: true, + itemBuilder: (context, index) { + final metric = HealthMetrics.metrics[index]; + final data = healthProvider.healthData[metric.type] ?? []; + + return Card( + color: AppColors.whiteColor, + margin: EdgeInsets.only(bottom: 16), + child: ExpansionTile( + leading: Icon( + metric.icon, + color: metric.color, + size: 32.h, + ), + // title: Text(metric.name), + title: (getIt.get().isArabic() ? metric.nameAr : metric.nameEn).toText14(isBold: true), + subtitle: Text( + data.isEmpty ? LocaleKeys.noDataAvailable.tr(context: context) : '${_getValueAsDouble(data.last.value, metric.type).toStringAsFixed(1)} ${metric.unit}', + ), + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + metric.description.toText13(), + SizedBox(height: 16.h), + if (data.isNotEmpty) ...[ + Text( + 'History', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + SizedBox(height: 8), + ...data.reversed + .take(5) + .map((point) => Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + dateFormat.format(point.dateFrom), + style: TextStyle(color: Colors.grey[600]), + ), + Text( + '${_getValueAsDouble(point.value, metric.type).toStringAsFixed(1)} ${metric.unit}', + style: TextStyle(fontWeight: FontWeight.bold), + ), + ], + ), + )) + .toList(), + ], + ], + ), + ), + ], + ), + ); + }, + ); + } + + Widget _buildTimeRangeSelector(HealthProvider provider) { + return Container( + height: 40, + child: ListView( + scrollDirection: Axis.horizontal, + children: [ + for (final range in ['1D', '7D', '1M', '3M', '1Y']) + Padding( + padding: const EdgeInsets.only(right: 8), + child: ChoiceChip( + label: Text(range), + labelStyle: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + checkmarkColor: AppColors.primaryRedColor, + selected: provider.selectedTimeRange == range, + selectedColor: AppColors.secondaryLightRedColor, + onSelected: (selected) { + if (selected) { + provider.updateTimeRange(range); + } + }, + ), + ), + ], + ), + ); + } + + Widget _buildLoadingState() { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator(), + SizedBox(height: 16), + Text('Loading health data...'), + ], + ), + ); + } + + Widget _buildErrorState(String error) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.error_outline, + size: 48, + color: Colors.red, + ), + SizedBox(height: 16), + Text( + 'Error loading health data', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + SizedBox(height: 8), + Text( + error, + textAlign: TextAlign.center, + style: TextStyle(color: Colors.grey[600]), + ), + SizedBox(height: 24), + ElevatedButton( + onPressed: () => context.read().fetchHealthData(), + child: Text('Try Again'), + ), + ], + ), + ); + } + + void _showMetricDetails( + BuildContext context, + HealthMetricInfo metric, + HealthProvider provider, + ) { + final data = provider.healthData[metric.type] ?? []; + + showModalBottomSheet( + context: context, + isScrollControlled: true, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(20)), + ), + builder: (context) => DraggableScrollableSheet( + initialChildSize: 0.7, + minChildSize: 0.5, + maxChildSize: 0.95, + expand: false, + builder: (context, scrollController) => Container( + padding: EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Center( + child: Container( + width: 40, + height: 4, + margin: EdgeInsets.only(bottom: 16), + decoration: BoxDecoration( + color: Colors.grey[300], + borderRadius: BorderRadius.circular(2), + ), + ), + ), + Row( + children: [ + Icon(metric.icon, color: metric.color, size: 30), + SizedBox(width: 16), + (getIt.get().isArabic() ? metric.nameAr : metric.nameEn).toText24(isBold: true), + // Text( + // metric.name, + // style: TextStyle( + // fontSize: 24, + // fontWeight: FontWeight.bold, + // ), + // ), + ], + ), + SizedBox(height: 16), + Text( + metric.description, + style: TextStyle( + color: Colors.grey[600], + fontSize: 16, + ), + ), + SizedBox(height: 24), + Text( + 'Healthy Range', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + SizedBox(height: 8), + '${metric.minHealthyValue} - ${metric.maxHealthyValue} ${metric.unit}'.toText16(isBold: true, color: AppColors.primaryRedColor), + // Text( + // '${metric.minHealthyValue} - ${metric.maxHealthyValue} ${metric.unit}', + // style: TextStyle( + // color: mainPurple, + // fontSize: 16, + // ), + // ), + SizedBox(height: 24), + if (data.isNotEmpty) ...[ + Text( + 'History', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + SizedBox(height: 16), + Expanded( + child: ListView.builder( + controller: scrollController, + itemCount: data.length, + itemBuilder: (context, index) { + final point = data[data.length - 1 - index]; + final value = _getValueAsDouble(point.value, metric.type); + return Card( + child: ListTile( + title: Text( + '${value.toStringAsFixed(1)} ${metric.unit}', + style: TextStyle(fontWeight: FontWeight.bold), + ), + subtitle: Text( + // dateFormat.format(point.dateFrom), + Utils.getMonthDayYearDateFormatted(point.dateFrom) + // dateFormat.format(point.dateFrom), + ), + trailing: Icon( + value >= metric.minHealthyValue && value <= metric.maxHealthyValue ? Icons.check_circle : Icons.warning, + color: value >= metric.minHealthyValue && value <= metric.maxHealthyValue ? AppColors.textColor : Colors.orange, + ), + ), + ); + }, + ), + ), + ] else + Center( + child: Text( + 'No data available', + style: TextStyle(color: Colors.grey[600]), + ), + ), + ], + ), + ), + ), + ); + } + + // Add this helper method to the _HealthDashboardState class + double _getValueAsDouble(HealthValue value, HealthDataType type) { + if (value is NumericHealthValue) { + // if(type == HealthDataType.BLOOD_OXYGEN) { + // return (value.numericValue.toDouble() * 100); + // } else { + return value.numericValue.toDouble(); + // } + } + return 0.0; + } +} diff --git a/lib/presentation/smartwatches/smartwatch_instructions_page.dart b/lib/presentation/smartwatches/smartwatch_instructions_page.dart new file mode 100644 index 0000000..357f5f5 --- /dev/null +++ b/lib/presentation/smartwatches/smartwatch_instructions_page.dart @@ -0,0 +1,464 @@ +import 'dart:io'; + +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:health/health.dart'; +import 'package:hmg_patient_app_new/core/app_assets.dart'; +import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; +import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; +import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; +import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/presentation/smartwatches/health_dashboard/health_dashboard.dart'; +import 'package:hmg_patient_app_new/theme/colors.dart'; +import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; +import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; +import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart'; + +class SmartwatchInstructionsPage extends StatelessWidget { + const SmartwatchInstructionsPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: AppColors.bgScaffoldColor, + body: CollapsingListView( + title: LocaleKeys.smartWatches.tr(), + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 24.h), + child: SingleChildScrollView( + child: Platform.isIOS ? getIOSInstructionsUI(context) : getAndroidInstructionsUI(context), + ), + ), + ), + ); + } + + Widget getAndroidInstructionsUI(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + "Supported Smart Watches".needTranslation.toText20(isBold: true), + SizedBox(height: 16.h), + Row( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/galaxy_watch_ultra.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Galaxy Watch Ultra", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/galaxy_watch_8_classic.jpeg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Galaxy Watch 8 Classic", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + ], + ), + Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/galaxy_watch_8.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Galaxy Watch 8", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/galaxy_watch_7_classic.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Galaxy Watch 7 Classic", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + ], + ), + ), + Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/galaxy_watch_7.webp", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Galaxy Watch 7", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/galaxy_fit_3.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Galaxy Fit3", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + ], + ), + ), + SizedBox(height: 12), + "Please make sure that your Samsung Watch is connected to your Phone, is actively synced & updated.".needTranslation.toText14(isBold: true), + SizedBox(height: 12), + "Before syncing data, please make sure that you have followed the instructions properly.".needTranslation.toText14(isBold: true), + SizedBox(height: 12), + InkWell( + onTap: () { + showInstructionsDialog(context); + }, + child: "View watch instructions".needTranslation.toText12(isBold: true, color: AppColors.textColor, isUnderLine: true)), + SizedBox( + height: 130.h, + ), + CustomButton( + text: LocaleKeys.confirm.tr(context: context), + onPressed: () async { + await Health().getHealthConnectSdkStatus().then((val) { + print('Health Connect SDK Status: $val'); + if (val == HealthConnectSdkStatus.sdkAvailable) { + // Navigator.of(context).push( + // FadePage( + // page: HealthDashboard(), // Replace with the actual vital signs page + // // page: HealthApp(), // Replace with the actual vital signs page + // ), + // ); + } else { + // Utils.showAppDialog(context, LocaleKeys.error.tr(context: context), LocaleKeys.healthConnectNotInstalled.tr(), () { + // Navigator.pop(context); + // Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.apps.healthdata"); + // launchUrl(uri, mode: LaunchMode.externalApplication); + // }); + // return; + } + }); + }, + backgroundColor: AppColors.primaryRedColor, + borderColor: AppColors.primaryRedColor, + textColor: AppColors.whiteColor, + fontSize: 16.f, + fontWeight: FontWeight.w500, + borderRadius: 10.r, + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + height: 50.h, + iconColor: AppColors.whiteColor, + iconSize: 18.h, + ), + // DefaultButton( + // LocaleKeys.confirm.tr(context: context), + // () async { + // await Health().getHealthConnectSdkStatus().then((val) { + // print('Health Connect SDK Status: $val'); + // if (val == HealthConnectSdkStatus.sdkAvailable) { + // Navigator.of(context).push( + // FadePage( + // page: HealthDashboard(), // Replace with the actual vital signs page + // // page: HealthApp(), // Replace with the actual vital signs page + // ), + // ); + // } else { + // Utils.showAppDialog(context, LocaleKeys.error.tr(context: context), LocaleKeys.healthConnectNotInstalled.tr(), () { + // Navigator.pop(context); + // Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.apps.healthdata"); + // launchUrl(uri, mode: LaunchMode.externalApplication); + // }); + // return; + // } + // }); + // }, + // ) + ], + ); + } + + Widget getIOSInstructionsUI(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + "Supported Smart Watches".needTranslation.toText20(isBold: true), + SizedBox(height: 16.h), + Row( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/apple-watch-1.jpeg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Apple Watch Series 5", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/apple-watch-2.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Apple Watch Series 6", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + ], + ), + Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/apple-watch-3.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Apple Watch Series 7", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/apple-watch-4.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Apple Watch Series 8", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + ], + ), + ), + Container( + margin: EdgeInsets.only(top: 10.0), + child: Row( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/apple-watch-5.jpg", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Apple Watch Series 9", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 15.0), + child: Row( + children: [ + Image.asset("assets/images/png/smartwatches/Apple-Watch-6.png", width: 70.0, height: 70.0), + Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Container( + width: MediaQuery.of(context).size.width * 0.21, + child: Text("Apple Watch Series 10", overflow: TextOverflow.clip, style: TextStyle(fontSize: 12.0)), + ), + ) + ], + ), + ), + ), + ], + ), + ), + SizedBox(height: 12), + "Please make sure that your Apple Watch is connected to your iPhone, is actively synced & updated.".toText14(isBold: true), + SizedBox(height: 12), + "Before syncing data, please make sure that you have followed the instructions properly.".toText14(isBold: true), + SizedBox(height: 12), + InkWell( + onTap: () { + showInstructionsDialog(context); + }, + child: "View watch instructions".toText12(isBold: true, color: AppColors.textColor, isUnderLine: true), + ), + SizedBox( + height: 130.h, + ), + CustomButton( + text: LocaleKeys.confirm.tr(context: context), + onPressed: () async { + Navigator.of(context).push( + CustomPageRoute( + page: HealthDashboard(), + ), + ); + }, + backgroundColor: AppColors.primaryRedColor, + borderColor: AppColors.primaryRedColor, + textColor: AppColors.whiteColor, + fontSize: 16.f, + fontWeight: FontWeight.w500, + borderRadius: 10.r, + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + height: 50.h, + iconColor: AppColors.whiteColor, + iconSize: 18.h, + ), + ], + ); + } + + showInstructionsDialog(BuildContext context) { + showGeneralDialog( + barrierColor: Colors.black.withOpacity(0.5), + transitionBuilder: (context, a1, a2, widget) { + final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0; + return Transform( + transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0), + child: Opacity( + opacity: a1.value, + child: Dialog( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 350.0, + padding: EdgeInsets.all(21), + color: Colors.white, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + "SmartWatch Tracker".toText18(), + IconButton( + icon: Icon( + Icons.close, + color: Color(0xff2E303A), + ), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (Platform.isIOS + ? "Make sure that you have installed 'Health' App & 'Watch' App from Apple Store." + : "Please make sure that your Samsung Watch is connected to your Phone, is actively synced & updated.") + .needTranslation + .toText14(), + SizedBox(height: 12), + ], + ) + ], + ), + ), + ], + ), + ), + ), + ); + }, + transitionDuration: Duration(milliseconds: 500), + barrierDismissible: true, + barrierLabel: '', + context: context, + pageBuilder: (context, animation1, animation2) { + return SizedBox(); + //Chanbged By Aamir + }); + } +} diff --git a/lib/presentation/smartwatches/widgets/health_chart.dart b/lib/presentation/smartwatches/widgets/health_chart.dart new file mode 100644 index 0000000..fe6ae78 --- /dev/null +++ b/lib/presentation/smartwatches/widgets/health_chart.dart @@ -0,0 +1,87 @@ +import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter/material.dart'; + +class HealthChart extends StatelessWidget { + final List spots; + final String title; + final Color gradientColor; + + const HealthChart({ + Key? key, + required this.spots, + required this.title, + required this.gradientColor, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + height: 200, + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(16), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.1), + spreadRadius: 5, + blurRadius: 7, + offset: const Offset(0, 3), + ), + ], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 16), + Expanded( + child: LineChart( + LineChartData( + gridData: FlGridData(show: false), + titlesData: FlTitlesData(show: false), + borderData: FlBorderData(show: false), + minX: 0, + maxX: spots.length.toDouble() - 1, + minY: spots.map((e) => e.y).reduce((a, b) => a < b ? a : b), + maxY: spots.map((e) => e.y).reduce((a, b) => a > b ? a : b), + lineBarsData: [ + LineChartBarData( + spots: spots, + isCurved: true, + gradient: LinearGradient( + colors: [ + gradientColor.withOpacity(0.5), + gradientColor, + ], + ), + barWidth: 3, + isStrokeCapRound: true, + dotData: FlDotData(show: false), + belowBarData: BarAreaData( + show: true, + gradient: LinearGradient( + colors: [ + gradientColor.withOpacity(0.1), + gradientColor.withOpacity(0.2), + ], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + ), + ], + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/presentation/smartwatches/widgets/health_metric.dart b/lib/presentation/smartwatches/widgets/health_metric.dart new file mode 100644 index 0000000..13e65ad --- /dev/null +++ b/lib/presentation/smartwatches/widgets/health_metric.dart @@ -0,0 +1,97 @@ +import 'dart:io'; + +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:health/health.dart'; +import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; +import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/theme/colors.dart'; + +class HealthMetricInfo { + final HealthDataType type; + final String nameEn; + final String nameAr; + final String unit; + final Color color; + final IconData icon; + final String description; + final double minHealthyValue; + final double maxHealthyValue; + final String svgIcon; + + const HealthMetricInfo( + {required this.type, + required this.nameEn, + required this.nameAr, + required this.unit, + required this.color, + required this.icon, + required this.description, + required this.minHealthyValue, + required this.maxHealthyValue, + required this.svgIcon}); +} + +class HealthMetrics { + static final metrics = [ + HealthMetricInfo( + type: HealthDataType.HEART_RATE, + nameEn: "Heart Rate", + nameAr: "معدل النبض", + unit: 'BPM', + color: AppColors.primaryRedColor, + icon: Icons.favorite, + description: "Your heart rate indicates how many times your heart beats per minute".needTranslation, + minHealthyValue: 60, + maxHealthyValue: 100, + svgIcon: "assets/images/smartwatches/heartrate_icon.svg"), + HealthMetricInfo( + type: HealthDataType.BLOOD_OXYGEN, + nameEn: "Blood Oxygen", + nameAr: "أكسجين الدم", + unit: '%', + // color: Colors.blue, + color: Color(0xff3A3558), + icon: Icons.air, + description: "Blood oxygen level indicates how much oxygen your red blood cells are carrying".needTranslation, + minHealthyValue: 95, + maxHealthyValue: 100, + svgIcon: "assets/images/smartwatches/bloodoxygen_icon.svg"), + HealthMetricInfo( + type: HealthDataType.STEPS, + nameEn: "Steps", + nameAr: "خطوات", + unit: 'steps', + // color: Colors.green, + color: Color(0xff3263B8), + icon: Icons.directions_walk, + description: "Number of steps taken throughout the day".needTranslation, + minHealthyValue: 7000, + maxHealthyValue: 15000, + svgIcon: "assets/images/smartwatches/steps_icon.svg"), + HealthMetricInfo( + type: Platform.isIOS ? HealthDataType.ACTIVE_ENERGY_BURNED : HealthDataType.TOTAL_CALORIES_BURNED, + nameEn: "Active Calories", + nameAr: "السعرات الحرارية النشطة", + unit: 'kcal', + color: Color(0xffD59E95), + icon: Icons.local_fire_department, + description: "Calories burned during physical activity".needTranslation, + minHealthyValue: 300, + maxHealthyValue: 1000, + svgIcon: "assets/images/smartwatches/calories_icon.svg"), + HealthMetricInfo( + type: Platform.isIOS ? HealthDataType.DISTANCE_WALKING_RUNNING : HealthDataType.DISTANCE_DELTA, + nameEn: "Distance Covered", + nameAr: "المسافة المغطاة", + unit: 'KMs', + // color: mainPurple, + color: Color(0xff6A46F5), + icon: Icons.directions_run, + description: "Distance covered throughout the day".needTranslation, + minHealthyValue: 3, + maxHealthyValue: 10, + svgIcon: "assets/images/smartwatches/distance_icon.svg"), + // Add more metrics as needed + ]; +} diff --git a/lib/presentation/smartwatches/widgets/health_metric_card.dart b/lib/presentation/smartwatches/widgets/health_metric_card.dart new file mode 100644 index 0000000..023f41b --- /dev/null +++ b/lib/presentation/smartwatches/widgets/health_metric_card.dart @@ -0,0 +1,151 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:health/health.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'package:hmg_patient_app_new/core/app_state.dart'; +import 'package:hmg_patient_app_new/core/dependencies.dart'; +import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; +import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; +import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/presentation/smartwatches/widgets/health_metric.dart'; +import 'package:hmg_patient_app_new/theme/colors.dart'; + +class HealthMetricCard extends StatelessWidget { + final HealthMetricInfo metric; + final List data; + final VoidCallback onTap; + + const HealthMetricCard({ + Key? key, + required this.metric, + required this.data, + required this.onTap, + }) : super(key: key); + + // Helper method to convert HealthValue to double + double _getValueAsDouble(HealthValue value, HealthDataType type) { + if (value is NumericHealthValue) { + return value.numericValue.toDouble(); + } + return 0.0; + } + + @override + Widget build(BuildContext context) { + final latestValue = data.isNotEmpty ? _getValueAsDouble(data.last.value, data.last.type) : 0.0; + final isHealthy = latestValue >= metric.minHealthyValue && latestValue <= metric.maxHealthyValue; + + return Card( + color: AppColors.whiteColor, + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + child: InkWell( + onTap: onTap, + borderRadius: BorderRadius.circular(20), + child: Container( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SvgPicture.asset( + metric.svgIcon, + height: 30.h, + width: 30.h, + fit: BoxFit.contain, + // color: color, + ), + // Icon( + // metric.icon, + // color: metric.color, + // size: 30, + // ), + if (data.isNotEmpty) + Container( + padding: const EdgeInsets.symmetric( + horizontal: 8, + vertical: 4, + ), + decoration: BoxDecoration( + color: isHealthy ? Colors.green[100] : Color(0xffD7D2F3), + borderRadius: BorderRadius.circular(12), + ), + child: Text( + isHealthy ? "Healthy".needTranslation : 'Warning'.needTranslation, + style: TextStyle( + color: isHealthy ? Colors.green[700] : AppColors.blackColor, + fontWeight: FontWeight.bold, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + (getIt.get().isArabic() ? metric.nameAr : metric.nameEn).toText18(isBold: true, maxlines: 1), + // Text( + // metric.name, + // style: const TextStyle( + // fontSize: 18, + // fontWeight: FontWeight.bold, + // ), + // ), + const SizedBox(height: 8), + Text( + data.isEmpty ? LocaleKeys.noDataAvailable.tr(context: context) : '${latestValue.toStringAsFixed(metric.type == HealthDataType.STEPS ? 0 : 1)} ${metric.unit}', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: metric.color, + ), + ), + if (data.isNotEmpty) ...[ + const SizedBox(height: 16), + SizedBox( + height: 100, + child: LineChart( + LineChartData( + gridData: FlGridData(show: false), + titlesData: FlTitlesData(show: false), + borderData: FlBorderData(show: false), + lineBarsData: [ + LineChartBarData( + spots: _convertToSpots(data), + isCurved: true, + color: metric.color, + barWidth: 3, + isStrokeCapRound: true, + dotData: FlDotData(show: false), + belowBarData: BarAreaData( + show: true, + color: metric.color.withOpacity(0.1), + ), + ), + ], + ), + ), + ), + ], + ], + ), + ), + ), + ); + } + + List _convertToSpots(List data) { + if (data.isEmpty) return []; + + return List.generate( + data.length, + (index) => FlSpot( + index.toDouble(), + _getValueAsDouble(data[index].value, data[index].type), + ), + ); + } +} diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 183c2a0..f356310 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -9,6 +9,7 @@ import 'package:hmg_patient_app_new/presentation/e_referral/new_e_referral.dart' import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; import 'package:hmg_patient_app_new/presentation/home_health_care/hhc_procedures_page.dart'; import 'package:hmg_patient_app_new/presentation/medical_file/medical_file_page.dart'; +import 'package:hmg_patient_app_new/presentation/smartwatches/smartwatch_instructions_page.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/organ_selector_screen.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/possible_conditions_screen.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/risk_factors_screen.dart'; @@ -32,6 +33,7 @@ class AppRoutes { static const String homeHealthCarePage = '/homeHealthCarePage'; static const String zoomCallPage = '/zoomCallPage'; static const String bloodDonationPage = '/bloodDonationPage'; + static const String smartWatches = '/smartWatches'; //appointments static const String bookAppointmentPage = '/bookAppointmentPage'; @@ -69,6 +71,7 @@ class AppRoutes { bookAppointmentPage: (context) => BookAppointmentPage(), userInfoSelection: (context) => UserInfoSelectionScreen(), userInfoFlowManager: (context) => UserInfoFlowManager(), + smartWatches: (context) => SmartwatchInstructionsPage(), // }; diff --git a/pubspec.yaml b/pubspec.yaml index c4fa97b..ecfc5ef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -114,6 +114,7 @@ flutter: - assets/images/svg/ - assets/images/png/ - assets/images/png/zoom/ + - assets/images/png/smartwatches/ - assets/animations/ - assets/animations/lottie/