check if row in the table checked

This commit is contained in:
mohammad
2024-08-24 09:26:37 +03:00
parent 820da1ecfb
commit 13ae978908
4 changed files with 25 additions and 5 deletions

View File

@ -13,6 +13,7 @@ class DynamicTable extends StatefulWidget {
final bool isEmpty; final bool isEmpty;
final void Function(bool?)? selectAll; final void Function(bool?)? selectAll;
final void Function(int, bool?)? onRowCheckboxChanged; final void Function(int, bool?)? onRowCheckboxChanged;
final List<String>? initialSelectedIds;
const DynamicTable({ const DynamicTable({
super.key, super.key,
@ -25,6 +26,7 @@ class DynamicTable extends StatefulWidget {
this.cellDecoration, this.cellDecoration,
this.selectAll, this.selectAll,
this.onRowCheckboxChanged, this.onRowCheckboxChanged,
this.initialSelectedIds,
}); });
@override @override
@ -38,7 +40,11 @@ class _DynamicTableState extends State<DynamicTable> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_selected = List<bool>.filled(widget.data.length, false); _selected = List<bool>.generate(widget.data.length, (index) {
return widget.initialSelectedIds != null &&
widget.initialSelectedIds!.contains(widget.data[index][1]);
});
_selectAll = _selected.every((element) => element == true);
} }
void _toggleSelectAll(bool? value) { void _toggleSelectAll(bool? value) {

View File

@ -51,7 +51,10 @@ class ToggleDaySelectionEvent extends VisitorPasswordEvent {
class ToggleRepeatEvent extends VisitorPasswordEvent {} class ToggleRepeatEvent extends VisitorPasswordEvent {}
class GeneratePasswordEvent extends VisitorPasswordEvent {} class GeneratePasswordEvent extends VisitorPasswordEvent {}
class FetchDevice extends VisitorPasswordEvent {} class FetchDevice extends VisitorPasswordEvent {
final List<String>? list;
const FetchDevice({this.list});
}
//online password //online password
class OnlineOneTimePasswordEvent extends VisitorPasswordEvent { class OnlineOneTimePasswordEvent extends VisitorPasswordEvent {

View File

@ -13,15 +13,25 @@ import 'package:syncrow_web/utils/constants/const.dart';
import 'package:syncrow_web/utils/style.dart'; import 'package:syncrow_web/utils/style.dart';
class AddDeviceDialog extends StatelessWidget { class AddDeviceDialog extends StatelessWidget {
const AddDeviceDialog({super.key}); final List<String>? selectedDeviceIds;
const AddDeviceDialog({super.key,this.selectedDeviceIds });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size; Size size = MediaQuery.of(context).size;
return BlocProvider( return BlocProvider(
create: (context) => VisitorPasswordBloc()..add(FetchDevice()), create: (context) => VisitorPasswordBloc()..add(FetchDevice(list: selectedDeviceIds)),
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>( child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
builder: (BuildContext context, VisitorPasswordState state) { builder: (BuildContext context, VisitorPasswordState state) {
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context); final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
if (state is TableLoaded) {
print('ooooooooooo${selectedDeviceIds}');
for (var device in selectedDeviceIds!) {
if (selectedDeviceIds!.contains(device)) {
visitorBloc.add(SelectDeviceEvent(device));
}
}
}
return AlertDialog( return AlertDialog(
backgroundColor: Colors.white, backgroundColor: Colors.white,
title: Text('Add Accessible Device', title: Text('Add Accessible Device',
@ -143,6 +153,7 @@ class AddDeviceDialog extends StatelessWidget {
flex: 3, flex: 3,
child: state is TableLoaded child: state is TableLoaded
? DynamicTable( ? DynamicTable(
initialSelectedIds:selectedDeviceIds ,
cellDecoration: containerDecoration, cellDecoration: containerDecoration,
isEmpty:visitorBloc.data.isEmpty, isEmpty:visitorBloc.data.isEmpty,
selectAll: (p0) { selectAll: (p0) {

View File

@ -318,7 +318,7 @@ class VisitorPasswordDialog extends StatelessWidget {
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (BuildContext context) { builder: (BuildContext context) {
return const AddDeviceDialog(); return AddDeviceDialog(selectedDeviceIds: visitorBloc.selectedDevices,);
}, },
).then((listDevice) { ).then((listDevice) {
if(listDevice!=null){ if(listDevice!=null){