2 changed files with 94 additions and 94 deletions
			
			
		@ -1,114 +1,115 @@
					 | 
				
			||||
part of '../../neon.dart'; | 
				
			||||
 | 
				
			||||
class AccountSettingsPage extends StatelessWidget { | 
				
			||||
  AccountSettingsPage({ | 
				
			||||
    required this.bloc, | 
				
			||||
  const AccountSettingsPage({ | 
				
			||||
    required this.account, | 
				
			||||
    super.key, | 
				
			||||
  }); | 
				
			||||
 | 
				
			||||
  final AccountsBloc bloc; | 
				
			||||
  final Account account; | 
				
			||||
 | 
				
			||||
  late final _options = bloc.getOptionsFor(account); | 
				
			||||
  late final _userDetailsBloc = bloc.getUserDetailsBlocFor(account); | 
				
			||||
  late final _name = account.client.humanReadableID; | 
				
			||||
 | 
				
			||||
  @override | 
				
			||||
  Widget build(final BuildContext context) => Scaffold( | 
				
			||||
        resizeToAvoidBottomInset: false, | 
				
			||||
        appBar: AppBar( | 
				
			||||
          title: Text(_name), | 
				
			||||
          actions: [ | 
				
			||||
            IconButton( | 
				
			||||
              onPressed: () async { | 
				
			||||
  Widget build(final BuildContext context) { | 
				
			||||
    final accountsBloc = Provider.of<AccountsBloc>(context, listen: false); | 
				
			||||
    final options = accountsBloc.getOptionsFor(account); | 
				
			||||
    final userDetailsBloc = accountsBloc.getUserDetailsBlocFor(account); | 
				
			||||
    final name = account.client.humanReadableID; | 
				
			||||
 | 
				
			||||
    return Scaffold( | 
				
			||||
      resizeToAvoidBottomInset: false, | 
				
			||||
      appBar: AppBar( | 
				
			||||
        title: Text(name), | 
				
			||||
        actions: [ | 
				
			||||
          IconButton( | 
				
			||||
            onPressed: () async { | 
				
			||||
              // ignore: use_build_context_synchronously | 
				
			||||
              if (await showConfirmationDialog( | 
				
			||||
                context, | 
				
			||||
                // ignore: use_build_context_synchronously | 
				
			||||
                if (await showConfirmationDialog( | 
				
			||||
                  context, | 
				
			||||
                  // ignore: use_build_context_synchronously | 
				
			||||
                  AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), | 
				
			||||
                )) { | 
				
			||||
                  final isActive = bloc.activeAccount.value == account; | 
				
			||||
                AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), | 
				
			||||
              )) { | 
				
			||||
                final isActive = accountsBloc.activeAccount.value == account; | 
				
			||||
 | 
				
			||||
                  bloc.removeAccount(account); | 
				
			||||
                accountsBloc.removeAccount(account); | 
				
			||||
 | 
				
			||||
                  if (isActive) { | 
				
			||||
                    // ignore: use_build_context_synchronously | 
				
			||||
                    const HomeRoute().go(context); | 
				
			||||
                  } else { | 
				
			||||
                    // ignore: use_build_context_synchronously | 
				
			||||
                    Navigator.of(context).pop(); | 
				
			||||
                  } | 
				
			||||
                } | 
				
			||||
              }, | 
				
			||||
              tooltip: AppLocalizations.of(context).accountOptionsRemove, | 
				
			||||
              icon: const Icon(MdiIcons.delete), | 
				
			||||
            ), | 
				
			||||
            IconButton( | 
				
			||||
              onPressed: () async { | 
				
			||||
                // ignore: use_build_context_synchronously | 
				
			||||
                if (await showConfirmationDialog( | 
				
			||||
                  context, | 
				
			||||
                if (isActive) { | 
				
			||||
                  // ignore: use_build_context_synchronously | 
				
			||||
                  AppLocalizations.of(context).settingsResetForConfirmation(_name), | 
				
			||||
                )) { | 
				
			||||
                  await _options.reset(); | 
				
			||||
                  const HomeRoute().go(context); | 
				
			||||
                } else { | 
				
			||||
                  // ignore: use_build_context_synchronously | 
				
			||||
                  Navigator.of(context).pop(); | 
				
			||||
                } | 
				
			||||
              }, | 
				
			||||
              tooltip: AppLocalizations.of(context).settingsResetFor(_name), | 
				
			||||
              icon: const Icon(MdiIcons.cogRefresh), | 
				
			||||
            ), | 
				
			||||
          ], | 
				
			||||
        ), | 
				
			||||
        body: ResultBuilder<NextcloudProvisioningApiUserDetails>( | 
				
			||||
          stream: _userDetailsBloc.userDetails, | 
				
			||||
          builder: (final context, final userDetails) => SettingsList( | 
				
			||||
            categories: [ | 
				
			||||
              SettingsCategory( | 
				
			||||
                title: Text(AppLocalizations.of(context).accountOptionsCategoryStorageInfo), | 
				
			||||
                tiles: [ | 
				
			||||
                  CustomSettingsTile( | 
				
			||||
                    title: Column( | 
				
			||||
                      crossAxisAlignment: CrossAxisAlignment.start, | 
				
			||||
                      children: [ | 
				
			||||
                        if (userDetails.data != null) ...[ | 
				
			||||
                          LinearProgressIndicator( | 
				
			||||
                            value: userDetails.data!.quota.relative / 100, | 
				
			||||
                            backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.3), | 
				
			||||
                          ), | 
				
			||||
                          const SizedBox( | 
				
			||||
                            height: 10, | 
				
			||||
                          ), | 
				
			||||
                          Text( | 
				
			||||
                            AppLocalizations.of(context).accountOptionsQuotaUsedOf( | 
				
			||||
                              filesize(userDetails.data!.quota.used, 1), | 
				
			||||
                              filesize(userDetails.data!.quota.total, 1), | 
				
			||||
                              userDetails.data!.quota.relative.toString(), | 
				
			||||
                            ), | 
				
			||||
                          ), | 
				
			||||
                        ], | 
				
			||||
                        NeonException( | 
				
			||||
                          userDetails.error, | 
				
			||||
                          onRetry: _userDetailsBloc.refresh, | 
				
			||||
              } | 
				
			||||
            }, | 
				
			||||
            tooltip: AppLocalizations.of(context).accountOptionsRemove, | 
				
			||||
            icon: const Icon(MdiIcons.delete), | 
				
			||||
          ), | 
				
			||||
          IconButton( | 
				
			||||
            onPressed: () async { | 
				
			||||
              // ignore: use_build_context_synchronously | 
				
			||||
              if (await showConfirmationDialog( | 
				
			||||
                context, | 
				
			||||
                // ignore: use_build_context_synchronously | 
				
			||||
                AppLocalizations.of(context).settingsResetForConfirmation(name), | 
				
			||||
              )) { | 
				
			||||
                await options.reset(); | 
				
			||||
              } | 
				
			||||
            }, | 
				
			||||
            tooltip: AppLocalizations.of(context).settingsResetFor(name), | 
				
			||||
            icon: const Icon(MdiIcons.cogRefresh), | 
				
			||||
          ), | 
				
			||||
        ], | 
				
			||||
      ), | 
				
			||||
      body: ResultBuilder<NextcloudProvisioningApiUserDetails>( | 
				
			||||
        stream: userDetailsBloc.userDetails, | 
				
			||||
        builder: (final context, final userDetails) => SettingsList( | 
				
			||||
          categories: [ | 
				
			||||
            SettingsCategory( | 
				
			||||
              title: Text(AppLocalizations.of(context).accountOptionsCategoryStorageInfo), | 
				
			||||
              tiles: [ | 
				
			||||
                CustomSettingsTile( | 
				
			||||
                  title: Column( | 
				
			||||
                    crossAxisAlignment: CrossAxisAlignment.start, | 
				
			||||
                    children: [ | 
				
			||||
                      if (userDetails.data != null) ...[ | 
				
			||||
                        LinearProgressIndicator( | 
				
			||||
                          value: userDetails.data!.quota.relative / 100, | 
				
			||||
                          backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.3), | 
				
			||||
                        ), | 
				
			||||
                        const SizedBox( | 
				
			||||
                          height: 10, | 
				
			||||
                        ), | 
				
			||||
                        NeonLinearProgressIndicator( | 
				
			||||
                          visible: userDetails.loading, | 
				
			||||
                        Text( | 
				
			||||
                          AppLocalizations.of(context).accountOptionsQuotaUsedOf( | 
				
			||||
                            filesize(userDetails.data!.quota.used, 1), | 
				
			||||
                            filesize(userDetails.data!.quota.total, 1), | 
				
			||||
                            userDetails.data!.quota.relative.toString(), | 
				
			||||
                          ), | 
				
			||||
                        ), | 
				
			||||
                      ], | 
				
			||||
                    ), | 
				
			||||
                      NeonException( | 
				
			||||
                        userDetails.error, | 
				
			||||
                        onRetry: userDetailsBloc.refresh, | 
				
			||||
                      ), | 
				
			||||
                      NeonLinearProgressIndicator( | 
				
			||||
                        visible: userDetails.loading, | 
				
			||||
                      ), | 
				
			||||
                    ], | 
				
			||||
                  ), | 
				
			||||
                ], | 
				
			||||
              ), | 
				
			||||
              SettingsCategory( | 
				
			||||
                title: Text(AppLocalizations.of(context).optionsCategoryGeneral), | 
				
			||||
                tiles: [ | 
				
			||||
                  DropdownButtonSettingsTile( | 
				
			||||
                    option: _options.initialApp, | 
				
			||||
                  ), | 
				
			||||
                ], | 
				
			||||
              ), | 
				
			||||
            ], | 
				
			||||
          ), | 
				
			||||
                ), | 
				
			||||
              ], | 
				
			||||
            ), | 
				
			||||
            SettingsCategory( | 
				
			||||
              title: Text(AppLocalizations.of(context).optionsCategoryGeneral), | 
				
			||||
              tiles: [ | 
				
			||||
                DropdownButtonSettingsTile( | 
				
			||||
                  option: options.initialApp, | 
				
			||||
                ), | 
				
			||||
              ], | 
				
			||||
            ), | 
				
			||||
          ], | 
				
			||||
        ), | 
				
			||||
      ); | 
				
			||||
      ), | 
				
			||||
    ); | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
					 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue