From e883c3eefa46cd78be0071b6c8c461086efd8be0 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 10 May 2024 18:33:16 +0200 Subject: [PATCH] refactor(neon_framework): Separate account settings sections Signed-off-by: provokateurin --- .../lib/src/pages/account_settings.dart | 117 ++++++++++-------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/packages/neon_framework/lib/src/pages/account_settings.dart b/packages/neon_framework/lib/src/pages/account_settings.dart index 67ab9fccaa6..bc16425e3d1 100644 --- a/packages/neon_framework/lib/src/pages/account_settings.dart +++ b/packages/neon_framework/lib/src/pages/account_settings.dart @@ -4,6 +4,7 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart import 'package:meta/meta.dart'; import 'package:neon_framework/src/bloc/result.dart'; import 'package:neon_framework/src/blocs/accounts.dart'; +import 'package:neon_framework/src/blocs/user_details.dart'; import 'package:neon_framework/src/models/account.dart'; import 'package:neon_framework/src/router.dart'; import 'package:neon_framework/src/settings/widgets/custom_settings_tile.dart'; @@ -11,6 +12,7 @@ import 'package:neon_framework/src/settings/widgets/option_settings_tile.dart'; import 'package:neon_framework/src/settings/widgets/settings_category.dart'; import 'package:neon_framework/src/settings/widgets/settings_list.dart'; import 'package:neon_framework/src/theme/dialog.dart'; +import 'package:neon_framework/src/utils/account_options.dart'; import 'package:neon_framework/src/widgets/dialog.dart'; import 'package:neon_framework/src/widgets/error.dart'; import 'package:neon_framework/utils.dart'; @@ -104,58 +106,8 @@ class AccountSettingsPage extends StatelessWidget { final body = SettingsList( categories: [ - SettingsCategory( - title: Text(NeonLocalizations.of(context).accountOptionsCategoryStorageInfo), - tiles: [ - ResultBuilder.behaviorSubject( - subject: userDetailsBloc.userDetails, - builder: (context, userDetails) { - if (userDetails.hasError) { - return NeonError( - userDetails.error ?? 'Something went wrong', - type: NeonErrorType.listTile, - onRetry: userDetailsBloc.refresh, - ); - } - - double? value; - Widget? subtitle; - if (userDetails.hasData) { - final quotaRelative = userDetails.data?.quota.relative ?? 0; - final quotaTotal = userDetails.data?.quota.total ?? 0; - final quotaUsed = userDetails.data?.quota.used ?? 0; - - value = quotaRelative / 100; - subtitle = Text( - NeonLocalizations.of(context).accountOptionsQuotaUsedOf( - filesize(quotaUsed, 1), - filesize(quotaTotal, 1), - quotaRelative.toString(), - ), - ); - } - - return CustomSettingsTile( - title: LinearProgressIndicator( - value: value, - minHeight: isCupertino(context) ? 15 : null, - borderRadius: BorderRadius.circular(isCupertino(context) ? 5 : 3), - backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.3), - ), - subtitle: subtitle, - ); - }, - ), - ], - ), - SettingsCategory( - title: Text(NeonLocalizations.of(context).optionsCategoryGeneral), - tiles: [ - SelectSettingsTile( - option: options.initialApp, - ), - ], - ), + _buildGeneralSection(context, options), + _buildStorageSection(context, userDetailsBloc), ], ); @@ -172,4 +124,65 @@ class AccountSettingsPage extends StatelessWidget { ), ); } + + Widget _buildGeneralSection(BuildContext context, AccountOptions options) { + return SettingsCategory( + title: Text(NeonLocalizations.of(context).optionsCategoryGeneral), + tiles: [ + SelectSettingsTile( + option: options.initialApp, + ), + ], + ); + } + + Widget _buildStorageSection( + BuildContext context, + UserDetailsBloc userDetailsBloc, + ) { + return SettingsCategory( + title: Text(NeonLocalizations.of(context).accountOptionsCategoryStorageInfo), + tiles: [ + ResultBuilder.behaviorSubject( + subject: userDetailsBloc.userDetails, + builder: (context, userDetails) { + if (userDetails.hasError) { + return NeonError( + userDetails.error, + type: NeonErrorType.listTile, + onRetry: userDetailsBloc.refresh, + ); + } + + double? value; + Widget? subtitle; + if (userDetails.hasData) { + final quotaRelative = userDetails.data?.quota.relative ?? 0; + final quotaTotal = userDetails.data?.quota.total ?? 0; + final quotaUsed = userDetails.data?.quota.used ?? 0; + + value = quotaRelative / 100; + subtitle = Text( + NeonLocalizations.of(context).accountOptionsQuotaUsedOf( + filesize(quotaUsed, 1), + filesize(quotaTotal, 1), + quotaRelative.toString(), + ), + ); + } + + return CustomSettingsTile( + title: LinearProgressIndicator( + value: value, + minHeight: isCupertino(context) ? 15 : null, + borderRadius: BorderRadius.circular(isCupertino(context) ? 5 : 3), + backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.3), + ), + subtitle: subtitle, + ); + }, + ), + ], + ); + } }