From 6974e031a8b50eeffe1ee7cb70096d0d0843230c Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 21 Nov 2025 09:36:20 +0700 Subject: [PATCH] Show UpgradeStorageWidget only when premium is available or quota exceeds 90% --- .../presentation/storage/storage_view.dart | 23 ++-- .../widgets/upgrade_storage_widget.dart | 108 +++++++++++------- 2 files changed, 77 insertions(+), 54 deletions(-) diff --git a/lib/features/manage_account/presentation/storage/storage_view.dart b/lib/features/manage_account/presentation/storage/storage_view.dart index dd88032f2..584ff48fc 100644 --- a/lib/features/manage_account/presentation/storage/storage_view.dart +++ b/lib/features/manage_account/presentation/storage/storage_view.dart @@ -68,6 +68,10 @@ class StorageView extends GetWidget with AppLoaderMixin { .value; if (octetsQuota != null && octetsQuota.storageAvailable) { + final isPremiumAvailable = PlatformInfo.isWeb && + !controller.isUpgradeStorageIsDisabled; + final isQuotaExceeds90Percent = octetsQuota.allowedDisplayToQuotaBanner; + return SingleChildScrollView( child: Padding( padding: _getPadding( @@ -83,16 +87,15 @@ class StorageView extends GetWidget with AppLoaderMixin { quota: octetsQuota, isMobile: isMobile, ), - UpgradeStorageWidget( - imagePaths: controller.imagePaths, - isMobile: isMobile, - isPremiumAvailable: PlatformInfo.isWeb && - !controller.isUpgradeStorageIsDisabled, - isQuotaExceeds90Percent: - octetsQuota.allowedDisplayToQuotaBanner, - onUpgradeStorageAction: - controller.onUpgradeStorage, - ), + if (isPremiumAvailable || isQuotaExceeds90Percent) + UpgradeStorageWidget( + imagePaths: controller.imagePaths, + isMobile: isMobile, + isPremiumAvailable: isPremiumAvailable, + isQuotaExceeds90Percent: isQuotaExceeds90Percent, + onUpgradeStorageAction: + controller.onUpgradeStorage, + ), ], ), ), diff --git a/lib/features/manage_account/presentation/storage/widgets/upgrade_storage_widget.dart b/lib/features/manage_account/presentation/storage/widgets/upgrade_storage_widget.dart index 4f4bd965f..71a707f86 100644 --- a/lib/features/manage_account/presentation/storage/widgets/upgrade_storage_widget.dart +++ b/lib/features/manage_account/presentation/storage/widgets/upgrade_storage_widget.dart @@ -25,51 +25,71 @@ class UpgradeStorageWidget extends StatelessWidget { @override Widget build(BuildContext context) { final appLocalizations = AppLocalizations.of(context); - return SizedBox( - width: isMobile ? double.infinity : 439, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (isQuotaExceeds90Percent) - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SvgPicture.asset( - imagePaths.icWarning, - width: 16, - height: 16, - fit: BoxFit.fill, - ), - const SizedBox(width: 7), - Expanded( - child: Text( - appLocalizations.storageIsAlmostFullMessage, - style: ThemeUtils.textStyleInter600().copyWith( - color: AppColor.m3Neutral40, - fontSize: 12, - height: 16 / 12, - letterSpacing: 0.4, - ), - ), - ), - ], + + final widgets = [ + if (isQuotaExceeds90Percent) _buildWarning(context, appLocalizations), + if (isPremiumAvailable) _buildUpgradeButton(appLocalizations), + ]; + + if (widgets.isEmpty) return const SizedBox.shrink(); + + final body = widgets.length == 1 + ? widgets.first + : Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: widgets, + ); + + return isQuotaExceeds90Percent + ? SizedBox( + width: isMobile ? double.infinity : 439, + child: body, + ) + : body; + } + + Widget _buildWarning( + BuildContext context, + AppLocalizations appLocalizations, + ) { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SvgPicture.asset( + imagePaths.icWarning, + width: 16, + height: 16, + fit: BoxFit.fill, + ), + const SizedBox(width: 7), + Expanded( + child: Text( + appLocalizations.storageIsAlmostFullMessage, + style: ThemeUtils.textStyleInter600().copyWith( + color: AppColor.m3Neutral40, + fontSize: 12, + height: 16 / 12, + letterSpacing: 0.4, ), - if (isPremiumAvailable) - Container( - constraints: const BoxConstraints(minWidth: 179), - margin: isQuotaExceeds90Percent - ? const EdgeInsetsDirectional.only(start: 16) - : null, - height: 48, - child: ConfirmDialogButton( - label: appLocalizations.upgradeStorage, - backgroundColor: AppColor.primaryMain, - textColor: Colors.white, - onTapAction: onUpgradeStorageAction, - ), - ), - ], + ), + ), + ], + ); + } + + Widget _buildUpgradeButton(AppLocalizations appLocalizations) { + return Container( + margin: isQuotaExceeds90Percent + ? const EdgeInsetsDirectional.only(top: 16) + : null, + height: 48, + constraints: const BoxConstraints(minWidth: 179), + child: ConfirmDialogButton( + label: appLocalizations.upgradeStorage, + backgroundColor: AppColor.primaryMain, + textColor: Colors.white, + onTapAction: onUpgradeStorageAction, ), ); }