mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 19:54:55 +00:00
fix using copywith
This commit is contained in:
@ -65,10 +65,21 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
));
|
||||
throw Exception();
|
||||
} else {
|
||||
setupBookableSpacesBloc.selectedBookableSpaces.forEach(
|
||||
(e) =>
|
||||
e.spaceConfig!.copyWith(bookingStartTime: timePicked),
|
||||
);
|
||||
for (int i = 0;
|
||||
i <
|
||||
setupBookableSpacesBloc
|
||||
.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space =
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i];
|
||||
final updatedConfig = space.spaceConfig
|
||||
?.copyWith(bookingStartTime: timePicked);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i] =
|
||||
updatedSpace;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
@ -99,10 +110,21 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
));
|
||||
throw Exception();
|
||||
} else {
|
||||
setupBookableSpacesBloc.selectedBookableSpaces.forEach(
|
||||
(e) =>
|
||||
e.spaceConfig!.copyWith(bookingEndTime: timePicked),
|
||||
);
|
||||
for (int i = 0;
|
||||
i <
|
||||
setupBookableSpacesBloc
|
||||
.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space =
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i];
|
||||
final updatedConfig = space.spaceConfig
|
||||
?.copyWith(bookingEndTime: timePicked);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i] =
|
||||
updatedSpace;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
@ -53,8 +53,7 @@ class RowOfButtonsTitleWidget extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
SvgTextButton(
|
||||
verticalPadding: 10,
|
||||
horizontalPadding: 10,
|
||||
padding: const EdgeInsets.all(10),
|
||||
svgSize: 15,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
||||
@ -73,34 +73,31 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
}),
|
||||
value: state is ActivatePointsSwitch,
|
||||
onChanged: (value) {
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
final updatedCost = value ? -1 : 0;
|
||||
|
||||
final switchCubit =
|
||||
context.read<TogglePointsSwitchCubit>();
|
||||
if (value) {
|
||||
context
|
||||
.read<TogglePointsSwitchCubit>()
|
||||
.activateSwitch();
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.forEach(
|
||||
(e) => e.spaceConfig!.copyWith(cost: -1),
|
||||
);
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
switchCubit.activateSwitch();
|
||||
} else {
|
||||
context
|
||||
.read<TogglePointsSwitchCubit>()
|
||||
.unActivateSwitch();
|
||||
switchCubit.unActivateSwitch();
|
||||
widget.pointsController.clear();
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.forEach(
|
||||
(e) => e.spaceConfig!.copyWith(cost: 0),
|
||||
);
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
}
|
||||
|
||||
for (int i = 0;
|
||||
i < bloc.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space = bloc.selectedBookableSpaces[i];
|
||||
final updatedConfig =
|
||||
space.spaceConfig?.copyWith(cost: updatedCost);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
bloc.selectedBookableSpaces[i] = updatedSpace;
|
||||
}
|
||||
|
||||
bloc.add(CheckConfigurValidityEvent());
|
||||
},
|
||||
),
|
||||
)
|
||||
@ -114,16 +111,21 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
title: 'Ex: 0',
|
||||
height: 40,
|
||||
onChanged: (p0) {
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.forEach(
|
||||
(e) => e.spaceConfig!.copyWith(
|
||||
cost: int.parse(widget.pointsController.text.isEmpty
|
||||
? '0'
|
||||
: widget.pointsController.text),
|
||||
),
|
||||
);
|
||||
final updatedCost =
|
||||
int.tryParse(widget.pointsController.text) ?? 0;
|
||||
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
for (var i = 0; i < bloc.selectedBookableSpaces.length; i++) {
|
||||
final space = bloc.selectedBookableSpaces[i];
|
||||
final updatedConfig =
|
||||
space.spaceConfig?.copyWith(cost: updatedCost);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
bloc.selectedBookableSpaces[i] = updatedSpace;
|
||||
}
|
||||
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
|
||||
@ -52,21 +52,28 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_daysChecked[entry.key] = newValue ?? false;
|
||||
final selectedDays = _daysChecked.entries
|
||||
.where((e) => e.value)
|
||||
.map((e) => e.key)
|
||||
.toList();
|
||||
|
||||
for (var space in context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces) {
|
||||
space.spaceConfig!.copyWith(bookableDays: selectedDays);
|
||||
}
|
||||
});
|
||||
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
final selectedDays = _daysChecked.entries
|
||||
.where((e) => e.value)
|
||||
.map((e) => e.key)
|
||||
.toList();
|
||||
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
for (int i = 0;
|
||||
i < bloc.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space = bloc.selectedBookableSpaces[i];
|
||||
final updatedConfig = space.spaceConfig
|
||||
?.copyWith(bookableDays: selectedDays);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
bloc.selectedBookableSpaces[i] = updatedSpace;
|
||||
}
|
||||
|
||||
bloc.add(CheckConfigurValidityEvent());
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user