From d242f5141ea386a49eeecd122344744bc2af73d7 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Fri, 31 Mar 2023 17:17:22 +0300 Subject: [PATCH] refactor(ui): Remove brand alert dialogs and bottom sheet --- .../components/brand_alert/brand_alert.dart | 13 -- .../brand_bottom_sheet.dart | 55 -------- .../pre_styled_buttons/flash_fab.dart | 9 +- lib/ui/helpers/modals.dart | 20 +-- lib/ui/layouts/brand_hero_screen.dart | 9 +- .../pages/more/app_settings/app_settings.dart | 13 +- .../binds_migration/services_migration.dart | 9 +- .../recovery_confirm_backblaze.dart | 6 +- .../recovery_confirm_cloudflare.dart | 22 ++-- .../recovery_server_provider_connected.dart | 22 ++-- lib/ui/pages/users/reset_password.dart | 120 +++++++++--------- lib/ui/pages/users/user_details.dart | 116 +++++++++-------- lib/ui/pages/users/users.dart | 1 - 13 files changed, 150 insertions(+), 265 deletions(-) delete mode 100644 lib/ui/components/brand_alert/brand_alert.dart delete mode 100644 lib/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart diff --git a/lib/ui/components/brand_alert/brand_alert.dart b/lib/ui/components/brand_alert/brand_alert.dart deleted file mode 100644 index 352b091c..00000000 --- a/lib/ui/components/brand_alert/brand_alert.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter/material.dart'; - -class BrandAlert extends AlertDialog { - BrandAlert({ - super.key, - final String? title, - final String? contentText, - super.actions, - }) : super( - title: title != null ? Text(title) : null, - content: title != null ? Text(contentText!) : null, - ); -} diff --git a/lib/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart b/lib/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart deleted file mode 100644 index 420ba32b..00000000 --- a/lib/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:flutter/material.dart'; - -class BrandBottomSheet extends StatelessWidget { - const BrandBottomSheet({ - required this.child, - super.key, - this.isExpended = false, - }); - - final Widget child; - final bool isExpended; - - @override - Widget build(final BuildContext context) { - final double mainHeight = MediaQuery.of(context).size.height - - MediaQuery.of(context).padding.top - - 300; - late Widget innerWidget; - if (isExpended) { - innerWidget = Scaffold( - body: child, - ); - } else { - final ThemeData themeData = Theme.of(context); - - innerWidget = Material( - color: themeData.scaffoldBackgroundColor, - child: IntrinsicHeight(child: child), - ); - } - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - Center( - child: Container( - height: 4, - width: 30, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(2), - color: const Color(0xFFDDDDDD), - ), - ), - ), - const SizedBox(height: 6), - ClipRRect( - borderRadius: const BorderRadius.vertical(top: Radius.circular(20)), - child: ConstrainedBox( - constraints: BoxConstraints(maxHeight: mainHeight), - child: innerWidget, - ), - ), - ], - ); - } -} diff --git a/lib/ui/components/pre_styled_buttons/flash_fab.dart b/lib/ui/components/pre_styled_buttons/flash_fab.dart index e069bcec..2098f79e 100644 --- a/lib/ui/components/pre_styled_buttons/flash_fab.dart +++ b/lib/ui/components/pre_styled_buttons/flash_fab.dart @@ -3,9 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ionicons/ionicons.dart'; import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart'; -import 'package:selfprivacy/ui/helpers/modals.dart'; class BrandFab extends StatefulWidget { const BrandFab({ @@ -62,12 +60,9 @@ class _BrandFabState extends State child: FloatingActionButton( onPressed: () { // TODO: Make a hero animation to the screen - showBrandBottomSheet( + showModalBottomSheet( context: context, - builder: (final BuildContext context) => const BrandBottomSheet( - isExpended: true, - child: JobsContent(), - ), + builder: (final BuildContext context) => const JobsContent(), ); }, isExtended: widget.extended, diff --git a/lib/ui/helpers/modals.dart b/lib/ui/helpers/modals.dart index 77ddf2cb..b744e323 100644 --- a/lib/ui/helpers/modals.dart +++ b/lib/ui/helpers/modals.dart @@ -1,21 +1,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:selfprivacy/config/get_it_config.dart'; import 'package:selfprivacy/ui/components/buttons/dialog_action_button.dart'; -import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart'; - -Future showBrandBottomSheet({ - required final BuildContext context, - required final WidgetBuilder builder, -}) => - showCupertinoModalBottomSheet( - builder: builder, - barrierColor: Colors.black45, - context: context, - shadow: const BoxShadow(color: Colors.transparent), - backgroundColor: Colors.transparent, - ); void showPopUpAlert({ required final String description, @@ -26,9 +12,9 @@ void showPopUpAlert({ final String? cancelButtonTitle, }) { getIt.get().showPopUpDialog( - BrandAlert( - title: alertTitle ?? 'basis.alert'.tr(), - contentText: description, + AlertDialog( + title: Text(alertTitle ?? 'basis.alert'.tr()), + content: Text(description), actions: [ DialogActionButton( text: actionButtonTitle, diff --git a/lib/ui/layouts/brand_hero_screen.dart b/lib/ui/layouts/brand_hero_screen.dart index 37b1f3ea..cc916b87 100644 --- a/lib/ui/layouts/brand_hero_screen.dart +++ b/lib/ui/layouts/brand_hero_screen.dart @@ -2,9 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:ionicons/ionicons.dart'; import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart'; -import 'package:selfprivacy/ui/helpers/modals.dart'; import 'package:selfprivacy/ui/helpers/widget_size.dart'; import 'package:selfprivacy/utils/breakpoints.dart'; @@ -127,13 +125,10 @@ class _HeroSliverAppBarState extends State { duration: const Duration(milliseconds: 300), child: IconButton( onPressed: () { - showBrandBottomSheet( + showModalBottomSheet( context: context, builder: (final BuildContext context) => - const BrandBottomSheet( - isExpended: true, - child: JobsContent(), - ), + const JobsContent(), ); }, icon: Icon( diff --git a/lib/ui/pages/more/app_settings/app_settings.dart b/lib/ui/pages/more/app_settings/app_settings.dart index 7c97f373..6ab69f40 100644 --- a/lib/ui/pages/more/app_settings/app_settings.dart +++ b/lib/ui/pages/more/app_settings/app_settings.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart'; import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; import 'package:selfprivacy/ui/components/buttons/dialog_action_button.dart'; -import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -82,9 +81,9 @@ class _AppSettingsPageState extends State { : () { showDialog( context: context, - builder: (final _) => BrandAlert( - title: 'modals.are_you_sure'.tr(), - contentText: 'modals.delete_server_volume'.tr(), + builder: (final _) => AlertDialog( + title: Text('modals.are_you_sure'.tr()), + content: Text('modals.delete_server_volume'.tr()), actions: [ DialogActionButton( text: 'modals.yes'.tr(), @@ -129,9 +128,9 @@ class _ResetAppTile extends StatelessWidget { onTap: () { showDialog( context: context, - builder: (final _) => BrandAlert( - title: 'modals.are_you_sure'.tr(), - contentText: 'modals.purge_all_keys'.tr(), + builder: (final _) => AlertDialog( + title: Text('modals.are_you_sure'.tr()), + content: Text('modals.purge_all_keys'.tr()), actions: [ DialogActionButton( text: 'modals.purge_all_keys_confirm'.tr(), diff --git a/lib/ui/pages/server_storage/binds_migration/services_migration.dart b/lib/ui/pages/server_storage/binds_migration/services_migration.dart index 71471e4b..ed03e896 100644 --- a/lib/ui/pages/server_storage/binds_migration/services_migration.dart +++ b/lib/ui/pages/server_storage/binds_migration/services_migration.dart @@ -5,7 +5,6 @@ import 'package:selfprivacy/logic/cubit/server_jobs/server_jobs_cubit.dart'; import 'package:selfprivacy/logic/cubit/services/services_cubit.dart'; import 'package:selfprivacy/logic/models/disk_size.dart'; import 'package:selfprivacy/logic/models/service.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; import 'package:selfprivacy/ui/components/brand_header/brand_header.dart'; import 'package:selfprivacy/ui/components/info_box/info_box.dart'; @@ -13,7 +12,6 @@ import 'package:selfprivacy/logic/models/disk_status.dart'; import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart'; import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart'; import 'package:selfprivacy/ui/components/storage_list_items/service_migration_list_item.dart'; -import 'package:selfprivacy/ui/helpers/modals.dart'; import 'package:selfprivacy/ui/pages/root_route.dart'; import 'package:selfprivacy/utils/route_transitions/basic.dart'; @@ -182,13 +180,10 @@ class _ServicesMigrationPageState extends State { materialRoute(const RootPage()), (final predicate) => false, ); - showBrandBottomSheet( + showModalBottomSheet( context: context, builder: (final BuildContext context) => - const BrandBottomSheet( - isExpended: true, - child: JobsContent(), - ), + const JobsContent(), ); }, ), diff --git a/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart b/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart index f758f5d2..dac2d7e1 100644 --- a/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart +++ b/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart @@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; import 'package:selfprivacy/config/brand_theme.dart'; import 'package:selfprivacy/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart'; import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; import 'package:selfprivacy/ui/components/brand_md/brand_md.dart'; @@ -62,9 +61,7 @@ class RecoveryConfirmBackblaze extends StatelessWidget { context: context, isScrollControlled: true, backgroundColor: Colors.transparent, - builder: (final BuildContext context) => BrandBottomSheet( - isExpended: true, - child: Padding( + builder: (final BuildContext context) => Padding( padding: paddingH15V0, child: ListView( padding: const EdgeInsets.symmetric(vertical: 16), @@ -73,7 +70,6 @@ class RecoveryConfirmBackblaze extends StatelessWidget { fileName: 'how_backblaze', ), ], - ), ), ), ), diff --git a/lib/ui/pages/setup/recovering/recovery_confirm_cloudflare.dart b/lib/ui/pages/setup/recovering/recovery_confirm_cloudflare.dart index e8969173..8ffc6dfa 100644 --- a/lib/ui/pages/setup/recovering/recovery_confirm_cloudflare.dart +++ b/lib/ui/pages/setup/recovering/recovery_confirm_cloudflare.dart @@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; import 'package:selfprivacy/config/brand_theme.dart'; import 'package:selfprivacy/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart'; import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; import 'package:selfprivacy/ui/components/brand_md/brand_md.dart'; @@ -54,18 +53,15 @@ class RecoveryConfirmCloudflare extends StatelessWidget { context: context, isScrollControlled: true, backgroundColor: Colors.transparent, - builder: (final BuildContext context) => BrandBottomSheet( - isExpended: true, - child: Padding( - padding: paddingH15V0, - child: ListView( - padding: const EdgeInsets.symmetric(vertical: 16), - children: const [ - BrandMarkdown( - fileName: 'how_cloudflare', - ), - ], - ), + builder: (final BuildContext context) => Padding( + padding: paddingH15V0, + child: ListView( + padding: const EdgeInsets.symmetric(vertical: 16), + children: const [ + BrandMarkdown( + fileName: 'how_cloudflare', + ), + ], ), ), ), diff --git a/lib/ui/pages/setup/recovering/recovery_server_provider_connected.dart b/lib/ui/pages/setup/recovering/recovery_server_provider_connected.dart index a892efc1..4cf4bdec 100644 --- a/lib/ui/pages/setup/recovering/recovery_server_provider_connected.dart +++ b/lib/ui/pages/setup/recovering/recovery_server_provider_connected.dart @@ -2,7 +2,6 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:selfprivacy/config/brand_theme.dart'; import 'package:selfprivacy/logic/cubit/forms/setup/initializing/provider_form_cubit.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; import 'package:cubit_form/cubit_form.dart'; @@ -57,18 +56,15 @@ class RecoveryServerProviderConnected extends StatelessWidget { context: context, isScrollControlled: true, backgroundColor: Colors.transparent, - builder: (final BuildContext context) => BrandBottomSheet( - isExpended: true, - child: Padding( - padding: paddingH15V0, - child: ListView( - padding: const EdgeInsets.symmetric(vertical: 16), - children: const [ - BrandMarkdown( - fileName: 'how_hetzner', - ), - ], - ), + builder: (final BuildContext context) => Padding( + padding: paddingH15V0, + child: ListView( + padding: const EdgeInsets.symmetric(vertical: 16), + children: const [ + BrandMarkdown( + fileName: 'how_hetzner', + ), + ], ), ), ), diff --git a/lib/ui/pages/users/reset_password.dart b/lib/ui/pages/users/reset_password.dart index 87f95902..56670803 100644 --- a/lib/ui/pages/users/reset_password.dart +++ b/lib/ui/pages/users/reset_password.dart @@ -9,76 +9,74 @@ class ResetPassword extends StatelessWidget { final User user; @override - Widget build(final BuildContext context) => BrandBottomSheet( - child: BlocProvider( - create: (final BuildContext context) => UserFormCubit( - jobsCubit: context.read(), - fieldFactory: FieldCubitFactory(context), - initialUser: user, - ), - child: Builder( - builder: (final BuildContext context) { - final FormCubitState formCubitState = - context.watch().state; + Widget build(final BuildContext context) => BlocProvider( + create: (final BuildContext context) => UserFormCubit( + jobsCubit: context.read(), + fieldFactory: FieldCubitFactory(context), + initialUser: user, + ), + child: Builder( + builder: (final BuildContext context) { + final FormCubitState formCubitState = + context.watch().state; - return BlocListener( - listener: - (final BuildContext context, final FormCubitState state) { - if (state.isSubmitted) { - Navigator.pop(context); - } - }, + return BlocListener( + listener: + (final BuildContext context, final FormCubitState state) { + if (state.isSubmitted) { + Navigator.pop(context); + } + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + BrandHeader( + title: 'users.reset_password'.tr(), + ), + const SizedBox(width: 14), + Padding( + padding: paddingH15V0, child: Column( - crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - BrandHeader( - title: 'users.reset_password'.tr(), - ), - const SizedBox(width: 14), - Padding( - padding: paddingH15V0, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CubitFormTextField( - formFieldCubit: - context.read().password, - decoration: InputDecoration( - alignLabelWithHint: false, - labelText: 'basis.password'.tr(), - suffixIcon: Padding( - padding: const EdgeInsets.only(right: 8), - child: IconButton( - icon: Icon( - BrandIcons.refresh, - color: - Theme.of(context).colorScheme.secondary, - ), - onPressed: context - .read() - .genNewPassword, - ), - ), + CubitFormTextField( + formFieldCubit: + context.read().password, + decoration: InputDecoration( + alignLabelWithHint: false, + labelText: 'basis.password'.tr(), + suffixIcon: Padding( + padding: const EdgeInsets.only(right: 8), + child: IconButton( + icon: Icon( + BrandIcons.refresh, + color: + Theme.of(context).colorScheme.secondary, ), + onPressed: context + .read() + .genNewPassword, ), - const SizedBox(height: 30), - BrandButton.rised( - onPressed: formCubitState.isSubmitting - ? null - : () => - context.read().trySubmit(), - text: 'basis.apply'.tr(), - ), - const SizedBox(height: 30), - ], + ), ), ), + const SizedBox(height: 30), + BrandButton.rised( + onPressed: formCubitState.isSubmitting + ? null + : () => + context.read().trySubmit(), + text: 'basis.apply'.tr(), + ), + const SizedBox(height: 30), ], ), - ); - }, + ), + ], ), - ), - ); + ); + }, + ), + ); } diff --git a/lib/ui/pages/users/user_details.dart b/lib/ui/pages/users/user_details.dart index 38743878..c6ef2a8c 100644 --- a/lib/ui/pages/users/user_details.dart +++ b/lib/ui/pages/users/user_details.dart @@ -254,72 +254,70 @@ class NewSshKey extends StatelessWidget { final User user; @override - Widget build(final BuildContext context) => BrandBottomSheet( - child: BlocProvider( - create: (final context) { - final jobCubit = context.read(); - final jobState = jobCubit.state; - if (jobState is JobsStateWithJobs) { - final jobs = jobState.clientJobList; - for (final job in jobs) { - if (job is CreateSSHKeyJob && job.user.login == user.login) { - user.sshKeys.add(job.publicKey); - } - } - } - return SshFormCubit( - jobsCubit: jobCubit, - user: user, - ); - }, - child: Builder( - builder: (final context) { - final formCubitState = context.watch().state; + Widget build(final BuildContext context) => BlocProvider( + create: (final context) { + final jobCubit = context.read(); + final jobState = jobCubit.state; + if (jobState is JobsStateWithJobs) { + final jobs = jobState.clientJobList; + for (final job in jobs) { + if (job is CreateSSHKeyJob && job.user.login == user.login) { + user.sshKeys.add(job.publicKey); + } + } + } + return SshFormCubit( + jobsCubit: jobCubit, + user: user, + ); + }, + child: Builder( + builder: (final context) { + final formCubitState = context.watch().state; - return BlocListener( - listener: (final context, final state) { - if (state.isSubmitted) { - Navigator.pop(context); - } - }, + return BlocListener( + listener: (final context, final state) { + if (state.isSubmitted) { + Navigator.pop(context); + } + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + BrandHeader( + title: user.login, + ), + const SizedBox(width: 14), + Padding( + padding: paddingH15V0, child: Column( - crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - BrandHeader( - title: user.login, - ), - const SizedBox(width: 14), - Padding( - padding: paddingH15V0, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - IntrinsicHeight( - child: CubitFormTextField( - formFieldCubit: context.read().key, - decoration: InputDecoration( - labelText: 'ssh.input_label'.tr(), - ), - ), - ), - const SizedBox(height: 30), - BrandButton.rised( - onPressed: formCubitState.isSubmitting - ? null - : () => - context.read().trySubmit(), - text: 'ssh.create'.tr(), - ), - const SizedBox(height: 30), - ], + IntrinsicHeight( + child: CubitFormTextField( + formFieldCubit: context.read().key, + decoration: InputDecoration( + labelText: 'ssh.input_label'.tr(), + ), ), ), + const SizedBox(height: 30), + BrandButton.rised( + onPressed: formCubitState.isSubmitting + ? null + : () => + context.read().trySubmit(), + text: 'ssh.create'.tr(), + ), + const SizedBox(height: 30), ], ), - ); - }, + ), + ], ), - ), - ); + ); + }, + ), + ); } diff --git a/lib/ui/pages/users/users.dart b/lib/ui/pages/users/users.dart index 5ea1fcbb..fdba2cb5 100644 --- a/lib/ui/pages/users/users.dart +++ b/lib/ui/pages/users/users.dart @@ -11,7 +11,6 @@ import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart'; import 'package:selfprivacy/logic/cubit/users/users_cubit.dart'; import 'package:selfprivacy/logic/models/job.dart'; import 'package:selfprivacy/logic/models/hive/user.dart'; -import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart'; import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; import 'package:selfprivacy/ui/components/buttons/outlined_button.dart'; import 'package:selfprivacy/ui/components/brand_cards/filled_card.dart';