From f94cddb615c86e2c7d7a9b3422e006812ce49cb7 Mon Sep 17 00:00:00 2001 From: ice-hector <96414297+ice-hector@users.noreply.github.com> Date: Mon, 30 Dec 2024 18:03:39 +0200 Subject: [PATCH] feat: remove AppUpdateHandler --- .../app_update_handler.dart | 33 ------------------- .../hooks/use_app_update.dart | 28 +++++++++++----- .../router/components/app_router_builder.dart | 19 +++++------ 3 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 lib/app/components/app_update_handler/app_update_handler.dart diff --git a/lib/app/components/app_update_handler/app_update_handler.dart b/lib/app/components/app_update_handler/app_update_handler.dart deleted file mode 100644 index bb1b4ce53..000000000 --- a/lib/app/components/app_update_handler/app_update_handler.dart +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: ice License 1.0 - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:ion/app/components/app_update_handler/hooks/use_app_update.dart'; -import 'package:ion/app/features/core/model/app_update_type.dart'; -import 'package:ion/app/features/core/views/pages/app_update_modal.dart'; -import 'package:ion/app/router/app_routes.c.dart'; -import 'package:ion/app/router/utils/show_simple_bottom_sheet.dart'; - -class AppUpdateHandler extends HookConsumerWidget { - const AppUpdateHandler({required this.child, super.key}); - final Widget child; - - @override - Widget build(BuildContext context, WidgetRef ref) { - final isModalShown = useAppUpdate(ref); - - if (!isModalShown) { - WidgetsBinding.instance.addPostFrameCallback((_) { - showSimpleBottomSheet( - isDismissible: false, - context: rootNavigatorKey.currentContext!, - child: const AppUpdateModal( - appUpdateType: AppUpdateType.updateRequired, - ), - ); - }); - } - - return child; - } -} diff --git a/lib/app/components/app_update_handler/hooks/use_app_update.dart b/lib/app/components/app_update_handler/hooks/use_app_update.dart index b96b4a327..5895f3454 100644 --- a/lib/app/components/app_update_handler/hooks/use_app_update.dart +++ b/lib/app/components/app_update_handler/hooks/use_app_update.dart @@ -1,24 +1,36 @@ // SPDX-License-Identifier: ice License 1.0 +import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:ion/app/features/config/providers/force_update_provider.c.dart'; +import 'package:ion/app/features/core/model/app_update_type.dart'; +import 'package:ion/app/features/core/views/pages/app_update_modal.dart'; +import 'package:ion/app/router/app_routes.c.dart'; +import 'package:ion/app/router/utils/show_simple_bottom_sheet.dart'; -bool useAppUpdate(WidgetRef ref) { - final isModalShown = useState(false); +void useAppUpdate(WidgetRef ref) { + final isUpdateModalVisible = useState(false); final forceUpdateState = ref.watch(forceUpdateProvider); useEffect( () { - if (forceUpdateState.shouldShowUpdateModal && !isModalShown.value) { - isModalShown.value = true; - } else if (!forceUpdateState.shouldShowUpdateModal && isModalShown.value) { - isModalShown.value = false; + if (forceUpdateState.shouldShowUpdateModal && !isUpdateModalVisible.value) { + isUpdateModalVisible.value = true; + + showSimpleBottomSheet( + isDismissible: false, + context: rootNavigatorKey.currentContext!, + child: const AppUpdateModal( + appUpdateType: AppUpdateType.updateRequired, + ), + ); + } else if (!forceUpdateState.shouldShowUpdateModal && isUpdateModalVisible.value) { + Navigator.of(rootNavigatorKey.currentContext!).pop(); + isUpdateModalVisible.value = false; } return null; }, [forceUpdateState], ); - - return isModalShown.value; } diff --git a/lib/app/router/components/app_router_builder.dart b/lib/app/router/components/app_router_builder.dart index 67b1e547e..b45103b66 100644 --- a/lib/app/router/components/app_router_builder.dart +++ b/lib/app/router/components/app_router_builder.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:ion/app/components/app_update_handler/app_update_handler.dart'; +import 'package:ion/app/components/app_update_handler/hooks/use_app_update.dart'; import 'package:ion/app/components/global_notification_bar/global_notification_bar.dart'; import 'package:ion/app/components/global_notification_bar/providers/global_notification_provider.c.dart'; import 'package:ion/app/extensions/extensions.dart'; @@ -18,6 +18,7 @@ class AppRouterBuilder extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final notification = ref.watch(globalNotificationProvider); final isShowSafeArea = useState(false); + useAppUpdate(ref); if (notification.isShow) { isShowSafeArea.value = true; @@ -35,15 +36,13 @@ class AppRouterBuilder extends HookConsumerWidget { child: SafeArea( top: isShowSafeArea.value, bottom: false, - child: AppUpdateHandler( - child: Column( - children: [ - const GlobalNotificationBar(), - Expanded( - child: child ?? const SizedBox.shrink(), - ), - ], - ), + child: Column( + children: [ + const GlobalNotificationBar(), + Expanded( + child: child ?? const SizedBox.shrink(), + ), + ], ), ), );