mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-26 10:19:41 +00:00
fix checkbox issue
This commit is contained in:
@ -42,7 +42,9 @@ class NonBookableSpacesBloc
|
|||||||
nonBookableSpacesList.data.addAll(currState.nonBookableSpaces.data);
|
nonBookableSpacesList.data.addAll(currState.nonBookableSpaces.data);
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
NonBookableSpacesLoaded(nonBookableSpaces: nonBookableSpacesList),
|
NonBookableSpacesLoaded(
|
||||||
|
nonBookableSpaces: nonBookableSpacesList,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(
|
emit(
|
||||||
|
@ -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/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';
|
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 BookableSpacemodel nonBookableSpace;
|
||||||
final List<BookableSpacemodel> selectedSpaces;
|
final List<BookableSpacemodel> selectedSpaces;
|
||||||
|
|
||||||
const CheckBoxSpaceWidget({
|
const CheckBoxSpaceWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.nonBookableSpace,
|
required this.nonBookableSpace,
|
||||||
required this.selectedSpaces,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final isChecked = selectedSpaces.any(
|
||||||
|
(element) => element.spaceUuid == nonBookableSpace.spaceUuid,
|
||||||
|
);
|
||||||
|
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Checkbox(
|
Checkbox(
|
||||||
value: isChecked,
|
value: isChecked,
|
||||||
onChanged: (value) => setState(() {
|
onChanged: (value) {
|
||||||
isChecked = value ?? false;
|
final bloc = context.read<NonBookableSpacesBloc>();
|
||||||
if (isChecked) {
|
if (value ?? false) {
|
||||||
context.read<NonBookableSpacesBloc>().add(
|
bloc.add(
|
||||||
AddToBookableSpaceEvent(
|
AddToBookableSpaceEvent(
|
||||||
nonBookableSpace: widget.nonBookableSpace,
|
nonBookableSpace: nonBookableSpace,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
context.read<NonBookableSpacesBloc>().add(
|
bloc.add(
|
||||||
RemoveFromBookableSpaceEvent(
|
RemoveFromBookableSpaceEvent(
|
||||||
bookableSpace: widget.nonBookableSpace,
|
bookableSpace: nonBookableSpace,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(width: 5),
|
||||||
width: 5,
|
Expanded(child: Text(nonBookableSpace.spaceName)),
|
||||||
),
|
|
||||||
Expanded(child: Text(widget.nonBookableSpace.spaceName)),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user