diff --git a/lib/features/smartwatch_health_data/health_provider.dart b/lib/features/smartwatch_health_data/health_provider.dart index 8abb8c49..1397703f 100644 --- a/lib/features/smartwatch_health_data/health_provider.dart +++ b/lib/features/smartwatch_health_data/health_provider.dart @@ -120,13 +120,17 @@ class HealthProvider with ChangeNotifier { void initDevice() async { LoaderBottomSheet.showLoader(); notifyListeners(); + error = null; final result = await _healthService.initDevice(); isLoading = false; // LoaderBottomSheet.hideLoader(); if (result.isError) { LoaderBottomSheet.hideLoader(); - if(result.asError?.error is PlatformException) { - error = 'Error initializing device: ${(result.asError?.error as PlatformException)?.message}'; + final rawError = result.asError?.error; + if (rawError is PlatformException) { + error = 'Error initializing device: ${rawError.message ?? rawError.toString()}'; + } else { + error = 'Error initializing device: ${rawError?.toString() ?? 'Unknown error'}'; } } else { // LoaderBottomSheet.showLoader(); @@ -293,5 +297,6 @@ class HealthProvider with ChangeNotifier { void clearError(){ error = null; + notifyListeners(); } } diff --git a/lib/presentation/hmg_services/services_page.dart b/lib/presentation/hmg_services/services_page.dart index bdc69300..582fd6fc 100644 --- a/lib/presentation/hmg_services/services_page.dart +++ b/lib/presentation/hmg_services/services_page.dart @@ -368,20 +368,19 @@ class _ServicesPageState extends State { true, route: null, onTap: () async { - getIt.get().pushPageRoute(AppRoutes.smartWatches); - - // if (getIt.get().isAuthenticated) { - // } else { - // Navigator.of(getIt().navigatorKey.currentContext!).push( - // CustomPageRoute( - // page: ServiceInfoPage( - // serviceName: LocaleKeys.smartWatches.tr(), - // serviceHeader: LocaleKeys.smartWatchServiceHeader.tr(), - // serviceDescription: LocaleKeys.smartWatchServiceDescription.tr(), - // serviceImage: AppAssets.smartWatchService), - // ), - // ); - // } + if (getIt.get().isAuthenticated) { + getIt.get().pushPageRoute(AppRoutes.smartWatches); + } else { + Navigator.of(getIt().navigatorKey.currentContext!).push( + CustomPageRoute( + page: ServiceInfoPage( + serviceName: LocaleKeys.smartWatches.tr(), + serviceHeader: LocaleKeys.smartWatchServiceHeader.tr(), + serviceDescription: LocaleKeys.smartWatchServiceDescription.tr(), + serviceImage: AppAssets.smartWatchService), + ), + ); + } // if (getIt.get().isAuthenticated) { // getIt.get().pushPageRoute(AppRoutes.smartWatches); // } else { diff --git a/lib/presentation/smartwatches/smartwatch_home_page.dart b/lib/presentation/smartwatches/smartwatch_home_page.dart index d1ca0c77..2c3c88ae 100644 --- a/lib/presentation/smartwatches/smartwatch_home_page.dart +++ b/lib/presentation/smartwatches/smartwatch_home_page.dart @@ -26,11 +26,7 @@ class SmartwatchHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Consumer(builder: (context, healthProvider, child) { - if (healthProvider.error != null && - healthProvider.error?.isNotEmpty == true) { - Utils.showToast(healthProvider.error!); - healthProvider.clearError(); - } + return Scaffold( backgroundColor: AppColors.bgScaffoldColor, body: CollapsingListView( diff --git a/lib/presentation/smartwatches/smartwatch_instructions_page.dart b/lib/presentation/smartwatches/smartwatch_instructions_page.dart index 8636e94e..0d14fa90 100644 --- a/lib/presentation/smartwatches/smartwatch_instructions_page.dart +++ b/lib/presentation/smartwatches/smartwatch_instructions_page.dart @@ -21,65 +21,75 @@ class SmartwatchInstructionsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - backgroundColor: AppColors.bgScaffoldColor, - body: CollapsingListView( - title: "smartwatchHowItWorks".tr(context: context), - bottomChild: Container( - decoration: RoundedRectangleBorder().toSmoothCornerDecoration( - color: AppColors.whiteColor, - borderRadius: 24.r, - ), - child: CustomButton( - text: LocaleKeys.getStarted.tr(context: context), - onPressed: () { - context.read().initDevice(); - }, - backgroundColor: AppColors.primaryRedColor, - borderColor: AppColors.primaryRedColor, - textColor: AppColors.whiteColor, - fontSize: 16.f, - isBold: true, - borderRadius: 12.r, - height: 50.h, - ).paddingSymmetrical(24.w, 30.h), - ), - child: Column( - mainAxisSize: MainAxisSize.max, - spacing: 18.h, - children: [ - Utils.buildImgWithAssets( - icon: smartwatchDetails.watchIcon, - fit: BoxFit.contain, - height: 280.h, - width: 280.w, + return Consumer(builder: (context, healthProvider, child) { + final errorMessage = healthProvider.error; + if (errorMessage != null && errorMessage.isNotEmpty) { + WidgetsBinding.instance.addPostFrameCallback((_) { + Utils.showToast(errorMessage, longDuration: false); + healthProvider.clearError(); + }); + } + return Scaffold( + backgroundColor: AppColors.bgScaffoldColor, + body: CollapsingListView( + title: "smartwatchHowItWorks".tr(context: context), + bottomChild: Container( + decoration: RoundedRectangleBorder().toSmoothCornerDecoration( + color: AppColors.whiteColor, + borderRadius: 24.r, + ), + child: CustomButton( + text: LocaleKeys.getStarted.tr(context: context), + onPressed: () { + context.read().initDevice(); + }, + backgroundColor: AppColors.primaryRedColor, + borderColor: AppColors.primaryRedColor, + textColor: AppColors.whiteColor, + fontSize: 16.f, + isBold: true, + borderRadius: 12.r, + height: 50.h, + ).paddingSymmetrical(24.w, 30.h), ), - DecoratedBox( - decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 12.h), - child: Column( - children: [ - watchContentDetails( - title: smartwatchDetails.detailsTitle, - description: smartwatchDetails.details, - icon: smartwatchDetails.smallIcon, - descriptionTextColor: AppColors.primaryRedColor, - ), - Divider( - color: AppColors.dividerColor, - thickness: 1.h, - ).paddingOnly(top: 16.h, bottom: 16.h), - watchContentDetails( - title: smartwatchDetails.secondTitle, - description: LocaleKeys.updatetheinformation.tr(), - icon: AppAssets.bluetooth, - descriptionTextColor: AppColors.greyTextColor, - ), - ], - ).paddingSymmetrical(16.w, 16.h), - ) - ], - ).paddingSymmetrical(24.w, 16.h), - ), + child: Column( + mainAxisSize: MainAxisSize.max, + spacing: 18.h, + children: [ + Utils.buildImgWithAssets( + icon: smartwatchDetails.watchIcon, + fit: BoxFit.contain, + height: 280.h, + width: 280.w, + ), + DecoratedBox( + decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 12.h), + child: Column( + children: [ + watchContentDetails( + title: smartwatchDetails.detailsTitle, + description: smartwatchDetails.details, + icon: smartwatchDetails.smallIcon, + descriptionTextColor: AppColors.primaryRedColor, + ), + Divider( + color: AppColors.dividerColor, + thickness: 1.h, + ).paddingOnly(top: 16.h, bottom: 16.h), + watchContentDetails( + title: smartwatchDetails.secondTitle, + description: LocaleKeys.updatetheinformation.tr(), + icon: AppAssets.bluetooth, + descriptionTextColor: AppColors.greyTextColor, + ), + ], + ).paddingSymmetrical(16.w, 16.h), + ) + ], + ).paddingSymmetrical(24.w, 16.h), + ), + ); + } ); }