Skip to content

Commit

Permalink
feat: remove AppUpdateHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-hector committed Dec 30, 2024
1 parent a5e6453 commit f94cddb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 51 deletions.
33 changes: 0 additions & 33 deletions lib/app/components/app_update_handler/app_update_handler.dart

This file was deleted.

28 changes: 20 additions & 8 deletions lib/app/components/app_update_handler/hooks/use_app_update.dart
Original file line number Diff line number Diff line change
@@ -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<void>(
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;
}
19 changes: 9 additions & 10 deletions lib/app/router/components/app_router_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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(),
),
],
),
),
);
Expand Down

0 comments on commit f94cddb

Please sign in to comment.