mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 23:42:28 +00:00
break down Massive widgets into smaller ones
This commit is contained in:
@ -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<BookableSpacemodel> 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<UpdateBookableSpacesBloc, UpdateBookableSpacesState>(
|
||||||
|
listener: (context, updateState) {
|
||||||
|
if (updateState is UpdateBookableSpaceSuccess) {
|
||||||
|
context.read<BookableSpacesBloc>().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<Color>(
|
||||||
|
(Set<WidgetState> states) {
|
||||||
|
return ColorsManager.whiteColors;
|
||||||
|
}),
|
||||||
|
value: space.spaceConfig!.availability,
|
||||||
|
activeTrackColor: ColorsManager.blueColor,
|
||||||
|
inactiveTrackColor: ColorsManager.grayBorder,
|
||||||
|
thumbColor: WidgetStateProperty.resolveWith<Color>(
|
||||||
|
(Set<WidgetState> states) {
|
||||||
|
return ColorsManager.whiteColors;
|
||||||
|
}),
|
||||||
|
onChanged: (value) {
|
||||||
|
context.read<UpdateBookableSpacesBloc>().add(
|
||||||
|
UpdateBookableSpace(
|
||||||
|
updatedParams: UpdateBookableSpaceParam(
|
||||||
|
spaceUuid: space.spaceUuid,
|
||||||
|
availability: value,
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -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<BookableSpacesBloc>();
|
||||||
|
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/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/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/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/widgets/bookable_space_switch_activation_widget.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/custom_data_table.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/pages/access_management/manage_bookable_spaces/presentation/widgets/edit_bookable_space_button_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
||||||
|
|
||||||
class TableOfBookableSpacesWidget extends StatelessWidget {
|
class TableOfBookableSpacesWidget extends StatelessWidget {
|
||||||
const TableOfBookableSpacesWidget({
|
const TableOfBookableSpacesWidget({
|
||||||
@ -43,12 +37,9 @@ class TableOfBookableSpacesWidget extends StatelessWidget {
|
|||||||
items: state.bookableSpacesList.data,
|
items: state.bookableSpacesList.data,
|
||||||
cellsWidgets: (space) => [
|
cellsWidgets: (space) => [
|
||||||
DataCell(
|
DataCell(
|
||||||
Padding(
|
DataCellWidget(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
title: space.spaceName,
|
||||||
child: Text(
|
),
|
||||||
space.spaceName,
|
|
||||||
style: const TextStyle(fontSize: 11),
|
|
||||||
)),
|
|
||||||
),
|
),
|
||||||
DataCell(Padding(
|
DataCell(Padding(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
padding: const EdgeInsetsGeometry.only(left: 10),
|
||||||
@ -62,123 +53,33 @@ class TableOfBookableSpacesWidget extends StatelessWidget {
|
|||||||
child: Wrap(
|
child: Wrap(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: space.spaceConfig!.bookableDays
|
children: space.spaceConfig!.bookableDays
|
||||||
.map((day) => Text(
|
.map(
|
||||||
day,
|
(day) => DataCellWidget(title: day),
|
||||||
style: const TextStyle(fontSize: 11),
|
)
|
||||||
))
|
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
DataCell(
|
DataCell(
|
||||||
Padding(
|
DataCellWidget(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
title: space.spaceConfig!.bookingStartTime!.format(context),
|
||||||
child: Text(
|
|
||||||
space.spaceConfig!.bookingStartTime!.format(context),
|
|
||||||
style: const TextStyle(fontSize: 11),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
DataCell(
|
DataCell(
|
||||||
Padding(
|
DataCellWidget(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
title: space.spaceConfig!.bookingEndTime!.format(context),
|
||||||
child: Text(
|
|
||||||
space.spaceConfig!.bookingEndTime!.format(context),
|
|
||||||
style: const TextStyle(fontSize: 11),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
DataCell(Padding(
|
DataCell(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
DataCellWidget(
|
||||||
child: Text(
|
title: '${space.spaceConfig!.cost} Points',
|
||||||
'${space.spaceConfig!.cost} Points',
|
|
||||||
style: const TextStyle(fontSize: 11),
|
|
||||||
))),
|
|
||||||
DataCell(Center(
|
|
||||||
child: Transform.scale(
|
|
||||||
scale: 0.7,
|
|
||||||
child: BlocConsumer<UpdateBookableSpacesBloc,
|
|
||||||
UpdateBookableSpacesState>(
|
|
||||||
listener: (context, updateState) {
|
|
||||||
if (updateState is UpdateBookableSpaceSuccess) {
|
|
||||||
context.read<BookableSpacesBloc>().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<Color>(
|
|
||||||
(Set<WidgetState> states) {
|
|
||||||
return ColorsManager.whiteColors;
|
|
||||||
}),
|
|
||||||
value: space.spaceConfig!.availability,
|
|
||||||
activeTrackColor: ColorsManager.blueColor,
|
|
||||||
inactiveTrackColor: ColorsManager.grayBorder,
|
|
||||||
thumbColor: WidgetStateProperty.resolveWith<Color>(
|
|
||||||
(Set<WidgetState> states) {
|
|
||||||
return ColorsManager.whiteColors;
|
|
||||||
}),
|
|
||||||
onChanged: (value) {
|
|
||||||
context.read<UpdateBookableSpacesBloc>().add(
|
|
||||||
UpdateBookableSpace(
|
|
||||||
updatedParams: UpdateBookableSpaceParam(
|
|
||||||
spaceUuid: space.spaceUuid,
|
|
||||||
availability: value,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
DataCell(BookableSpaceSwitchActivationWidget(
|
||||||
|
bookableSpaces: state.bookableSpacesList,
|
||||||
|
space: space,
|
||||||
)),
|
)),
|
||||||
DataCell(Center(
|
DataCell(EditBookableSpaceButtonWidget(
|
||||||
child: ElevatedButton(
|
space: space,
|
||||||
onPressed: () {
|
|
||||||
final bookableBloc = context.read<BookableSpacesBloc>();
|
|
||||||
|
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
columnsTitles: const [
|
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),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user