From 04fcf0a14006728f3dece68f95fce47573b528a6 Mon Sep 17 00:00:00 2001 From: Rafeek-Khoudare Date: Thu, 17 Jul 2025 15:03:22 +0300 Subject: [PATCH] break down Massive widgets into smaller ones --- ...okable_space_switch_activation_widget.dart | 71 ++++++++ .../edit_bookable_space_button_widget.dart | 59 +++++++ .../table_part_widget.dart | 160 +++++------------- 3 files changed, 170 insertions(+), 120 deletions(-) create mode 100644 lib/pages/access_management/manage_bookable_spaces/presentation/widgets/bookable_space_switch_activation_widget.dart create mode 100644 lib/pages/access_management/manage_bookable_spaces/presentation/widgets/edit_bookable_space_button_widget.dart diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/bookable_space_switch_activation_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/bookable_space_switch_activation_widget.dart new file mode 100644 index 00000000..4c88fe87 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/bookable_space_switch_activation_widget.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/update_bookable_space_param.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/update_bookable_spaces/update_bookable_spaces_bloc.dart'; +import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; + +class BookableSpaceSwitchActivationWidget extends StatelessWidget { + final PaginatedDataModel bookableSpaces; + final BookableSpacemodel space; + const BookableSpaceSwitchActivationWidget({ + super.key, + required this.bookableSpaces, + required this.space, + }); + + @override + Widget build(BuildContext context) { + return Center( + child: Transform.scale( + scale: 0.7, + child: + BlocConsumer( + listener: (context, updateState) { + if (updateState is UpdateBookableSpaceSuccess) { + context.read().add( + InsertUpdatedSpaceEvent( + bookableSpaces: bookableSpaces, + bookableSpace: space, + updatedBookableSpaceConfig: + updateState.bookableSpaceConfig, + ), + ); + } + }, + builder: (context, updateState) { + final isLoading = updateState is UpdateBookableSpaceLoading && + updateState.updatingSpaceUuid == space.spaceUuid; + if (isLoading) { + return const Center(child: CircularProgressIndicator()); + } + return Switch( + trackOutlineColor: WidgetStateProperty.resolveWith( + (Set states) { + return ColorsManager.whiteColors; + }), + value: space.spaceConfig!.availability, + activeTrackColor: ColorsManager.blueColor, + inactiveTrackColor: ColorsManager.grayBorder, + thumbColor: WidgetStateProperty.resolveWith( + (Set states) { + return ColorsManager.whiteColors; + }), + onChanged: (value) { + context.read().add( + UpdateBookableSpace( + updatedParams: UpdateBookableSpaceParam( + spaceUuid: space.spaceUuid, + availability: value, + )), + ); + }, + ); + }, + ), + ), + ); + } +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/edit_bookable_space_button_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/edit_bookable_space_button_widget.dart new file mode 100644 index 00000000..8f82e08d --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/edit_bookable_space_button_widget.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/data/remote_update_bookable_space_service.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/update_bookable_spaces/update_bookable_spaces_bloc.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/screens/setup_bookable_spaces_dialog.dart'; +import 'package:syncrow_web/services/api/http_service.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; + +class EditBookableSpaceButtonWidget extends StatelessWidget { + final BookableSpacemodel? space; + const EditBookableSpaceButtonWidget({ + super.key, + required this.space, + }); + + @override + Widget build(BuildContext context) { + return Center( + child: ElevatedButton( + onPressed: () { + final bookableBloc = context.read(); + + showDialog( + context: context, + builder: (context) => MultiBlocProvider( + providers: [ + BlocProvider.value( + value: bookableBloc, + ), + BlocProvider( + create: (context) => UpdateBookableSpacesBloc( + RemoteUpdateBookableSpaceService(HTTPService()), + ), + ), + ], + child: SetupBookableSpacesDialog( + editingBookableSpace: space, + ), + ), + ); + }, + style: ElevatedButton.styleFrom( + padding: EdgeInsets.zero, + fixedSize: const Size(50, 30), + elevation: 1, + ), + child: SvgPicture.asset( + Assets.settings, + height: 15, + color: ColorsManager.blue1, + ), + ), + ); + } +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/table_part_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/table_part_widget.dart index 0f1ddc4b..a0ce8ace 100644 --- a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/table_part_widget.dart +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/table_part_widget.dart @@ -1,17 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/data/remote_update_bookable_space_service.dart'; import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart'; import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/bookable_spaces_params.dart'; -import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/update_bookable_space_param.dart'; import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart'; -import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/update_bookable_spaces/update_bookable_spaces_bloc.dart'; -import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/screens/setup_bookable_spaces_dialog.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/bookable_space_switch_activation_widget.dart'; import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/custom_data_table.dart'; -import 'package:syncrow_web/services/api/http_service.dart'; -import 'package:syncrow_web/utils/color_manager.dart'; -import 'package:syncrow_web/utils/constants/assets.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/edit_bookable_space_button_widget.dart'; class TableOfBookableSpacesWidget extends StatelessWidget { const TableOfBookableSpacesWidget({ @@ -43,12 +37,9 @@ class TableOfBookableSpacesWidget extends StatelessWidget { items: state.bookableSpacesList.data, cellsWidgets: (space) => [ DataCell( - Padding( - padding: const EdgeInsetsGeometry.only(left: 10), - child: Text( - space.spaceName, - style: const TextStyle(fontSize: 11), - )), + DataCellWidget( + title: space.spaceName, + ), ), DataCell(Padding( padding: const EdgeInsetsGeometry.only(left: 10), @@ -62,123 +53,33 @@ class TableOfBookableSpacesWidget extends StatelessWidget { child: Wrap( spacing: 4, children: space.spaceConfig!.bookableDays - .map((day) => Text( - day, - style: const TextStyle(fontSize: 11), - )) + .map( + (day) => DataCellWidget(title: day), + ) .toList(), ), )), DataCell( - Padding( - padding: const EdgeInsetsGeometry.only(left: 10), - child: Text( - space.spaceConfig!.bookingStartTime!.format(context), - style: const TextStyle(fontSize: 11), - ), + DataCellWidget( + title: space.spaceConfig!.bookingStartTime!.format(context), ), ), DataCell( - Padding( - padding: const EdgeInsetsGeometry.only(left: 10), - child: Text( - space.spaceConfig!.bookingEndTime!.format(context), - style: const TextStyle(fontSize: 11), - ), + DataCellWidget( + title: space.spaceConfig!.bookingEndTime!.format(context), ), ), - DataCell(Padding( - padding: const EdgeInsetsGeometry.only(left: 10), - child: Text( - '${space.spaceConfig!.cost} Points', - style: const TextStyle(fontSize: 11), - ))), - DataCell(Center( - child: Transform.scale( - scale: 0.7, - child: BlocConsumer( - listener: (context, updateState) { - if (updateState is UpdateBookableSpaceSuccess) { - context.read().add( - InsertUpdatedSpaceEvent( - bookableSpaces: state.bookableSpacesList, - bookableSpace: space, - updatedBookableSpaceConfig: - updateState.bookableSpaceConfig, - ), - ); - } - }, - builder: (context, updateState) { - final isLoading = - updateState is UpdateBookableSpaceLoading && - updateState.updatingSpaceUuid == space.spaceUuid; - if (isLoading) { - return const Center(child: CircularProgressIndicator()); - } - return Switch( - trackOutlineColor: - WidgetStateProperty.resolveWith( - (Set states) { - return ColorsManager.whiteColors; - }), - value: space.spaceConfig!.availability, - activeTrackColor: ColorsManager.blueColor, - inactiveTrackColor: ColorsManager.grayBorder, - thumbColor: WidgetStateProperty.resolveWith( - (Set states) { - return ColorsManager.whiteColors; - }), - onChanged: (value) { - context.read().add( - UpdateBookableSpace( - updatedParams: UpdateBookableSpaceParam( - spaceUuid: space.spaceUuid, - availability: value, - )), - ); - }, - ); - }, - ), + DataCell( + DataCellWidget( + title: '${space.spaceConfig!.cost} Points', ), + ), + DataCell(BookableSpaceSwitchActivationWidget( + bookableSpaces: state.bookableSpacesList, + space: space, )), - DataCell(Center( - child: ElevatedButton( - onPressed: () { - final bookableBloc = context.read(); - - showDialog( - context: context, - builder: (context) => MultiBlocProvider( - providers: [ - BlocProvider.value( - value: bookableBloc, - ), - BlocProvider( - create: (context) => UpdateBookableSpacesBloc( - RemoteUpdateBookableSpaceService(HTTPService()), - ), - ), - ], - child: SetupBookableSpacesDialog( - editingBookableSpace: space, - ), - ), - ); - }, - style: ElevatedButton.styleFrom( - padding: EdgeInsets.zero, - fixedSize: const Size(50, 30), - elevation: 1, - ), - child: SvgPicture.asset( - Assets.settings, - height: 15, - color: ColorsManager.blue1, - ), - ), + DataCell(EditBookableSpaceButtonWidget( + space: space, )), ], columnsTitles: const [ @@ -199,3 +100,22 @@ class TableOfBookableSpacesWidget extends StatelessWidget { ); } } + +class DataCellWidget extends StatelessWidget { + final String title; + const DataCellWidget({ + super.key, + required this.title, + }); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsetsGeometry.only(left: 10), + child: Text( + title, + style: const TextStyle(fontSize: 11), + ), + ); + } +}