use copywith and final class for bookableSpaceConfig

This commit is contained in:
Rafeek-Khoudare
2025-07-21 14:34:36 +03:00
parent 729b0caac3
commit b12903059d
4 changed files with 16 additions and 14 deletions

View File

@ -1,12 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class BookableSpaceConfig { class BookableSpaceConfig {
String configUuid; final String configUuid;
List<String> bookableDays; final List<String> bookableDays;
TimeOfDay? bookingStartTime; final TimeOfDay? bookingStartTime;
TimeOfDay? bookingEndTime; final TimeOfDay? bookingEndTime;
int cost; final int cost;
bool availability; final bool availability;
BookableSpaceConfig({ BookableSpaceConfig({
required this.configUuid, required this.configUuid,
required this.availability, required this.availability,

View File

@ -66,7 +66,8 @@ class BookingPeriodWidget extends StatelessWidget {
throw Exception(); throw Exception();
} else { } else {
setupBookableSpacesBloc.selectedBookableSpaces.forEach( setupBookableSpacesBloc.selectedBookableSpaces.forEach(
(e) => e.spaceConfig!.bookingStartTime = timePicked, (e) =>
e.spaceConfig!.copyWith(bookingStartTime: timePicked),
); );
} }
}, },
@ -99,7 +100,8 @@ class BookingPeriodWidget extends StatelessWidget {
throw Exception(); throw Exception();
} else { } else {
setupBookableSpacesBloc.selectedBookableSpaces.forEach( setupBookableSpacesBloc.selectedBookableSpaces.forEach(
(e) => e.spaceConfig!.bookingEndTime = timePicked, (e) =>
e.spaceConfig!.copyWith(bookingEndTime: timePicked),
); );
} }
}, },

View File

@ -81,7 +81,7 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
.selectedBookableSpaces .selectedBookableSpaces
.forEach( .forEach(
(e) => e.spaceConfig!.cost = -1, (e) => e.spaceConfig!.copyWith(cost: -1),
); );
context context
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
@ -95,7 +95,7 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
.selectedBookableSpaces .selectedBookableSpaces
.forEach( .forEach(
(e) => e.spaceConfig!.cost = 0, (e) => e.spaceConfig!.copyWith(cost: 0),
); );
context context
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
@ -118,10 +118,10 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
.selectedBookableSpaces .selectedBookableSpaces
.forEach( .forEach(
(e) => e.spaceConfig!.cost = int.parse( (e) => e.spaceConfig!.copyWith(
widget.pointsController.text.isEmpty cost: int.parse(widget.pointsController.text.isEmpty
? '0' ? '0'
: widget.pointsController.text, : widget.pointsController.text),
), ),
); );
context context

View File

@ -60,7 +60,7 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
for (var space in context for (var space in context
.read<SetupBookableSpacesBloc>() .read<SetupBookableSpacesBloc>()
.selectedBookableSpaces) { .selectedBookableSpaces) {
space.spaceConfig!.bookableDays = selectedDays; space.spaceConfig!.copyWith(bookableDays: selectedDays);
} }
}); });