fix checkbox issue

This commit is contained in:
Rafeek-Khoudare
2025-07-11 10:27:18 +03:00
parent 6e4f0c3c0c
commit a9895f5462
2 changed files with 25 additions and 34 deletions

View File

@ -42,7 +42,9 @@ class NonBookableSpacesBloc
nonBookableSpacesList.data.addAll(currState.nonBookableSpaces.data);
emit(
NonBookableSpacesLoaded(nonBookableSpaces: nonBookableSpacesList),
NonBookableSpacesLoaded(
nonBookableSpaces: nonBookableSpacesList,
),
);
} catch (e) {
emit(

View File

@ -3,56 +3,45 @@ 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/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.dart';
class CheckBoxSpaceWidget extends StatefulWidget {
class CheckBoxSpaceWidget extends StatelessWidget {
final BookableSpacemodel nonBookableSpace;
final List<BookableSpacemodel> selectedSpaces;
const CheckBoxSpaceWidget({
super.key,
required this.nonBookableSpace,
required this.selectedSpaces,
});
@override
State<CheckBoxSpaceWidget> createState() => _CheckBoxSpaceWidgetState();
}
class _CheckBoxSpaceWidgetState extends State<CheckBoxSpaceWidget> {
bool isChecked = false;
@override
void initState() {
isChecked = widget.selectedSpaces.any(
(element) => element.spaceUuid == widget.nonBookableSpace.spaceUuid,
);
super.initState();
}
@override
Widget build(BuildContext context) {
final isChecked = selectedSpaces.any(
(element) => element.spaceUuid == nonBookableSpace.spaceUuid,
);
return Row(
children: [
Checkbox(
value: isChecked,
onChanged: (value) => setState(() {
isChecked = value ?? false;
if (isChecked) {
context.read<NonBookableSpacesBloc>().add(
onChanged: (value) {
final bloc = context.read<NonBookableSpacesBloc>();
if (value ?? false) {
bloc.add(
AddToBookableSpaceEvent(
nonBookableSpace: widget.nonBookableSpace,
nonBookableSpace: nonBookableSpace,
),
);
} else {
context.read<NonBookableSpacesBloc>().add(
bloc.add(
RemoveFromBookableSpaceEvent(
bookableSpace: widget.nonBookableSpace,
bookableSpace: nonBookableSpace,
),
);
}
}),
},
),
const SizedBox(
width: 5,
),
Expanded(child: Text(widget.nonBookableSpace.spaceName)),
const SizedBox(width: 5),
Expanded(child: Text(nonBookableSpace.spaceName)),
],
);
}