Skip to content

Commit

Permalink
refactor(neon_framework): Separate account settings sections
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Aug 4, 2024
1 parent 68b75c8 commit e883c3e
Showing 1 changed file with 65 additions and 52 deletions.
117 changes: 65 additions & 52 deletions packages/neon_framework/lib/src/pages/account_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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';
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';
Expand Down Expand Up @@ -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),
],
);

Expand All @@ -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,
);
},
),
],
);
}
}

0 comments on commit e883c3e

Please sign in to comment.