diff --git a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart index 1fa61fc2..db1dd2c7 100644 --- a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart +++ b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart @@ -17,8 +17,6 @@ class DeviceManagementBloc extends Bloc(_onFetchDevices); @@ -34,13 +32,7 @@ class DeviceManagementBloc extends Bloc _onFetchDevices(FetchDevices event, Emitter emit) async { emit(DeviceManagementLoading()); try { - if (event.communityId.isNotEmpty) { - communityId = event.communityId; - } - if (event.spaceId.isNotEmpty) { - spaceId = event.spaceId; - } - final devices = await DevicesManagementApi().fetchDevices(communityId ?? '', spaceId ?? ''); + final devices = await DevicesManagementApi().fetchDevices(event.communityId, event.spaceId); _selectedDevices.clear(); _devices = devices; _filteredDevices = devices; diff --git a/lib/pages/device_managment/all_devices/view/device_managment_page.dart b/lib/pages/device_managment/all_devices/view/device_managment_page.dart index f64ef734..114c1fac 100644 --- a/lib/pages/device_managment/all_devices/view/device_managment_page.dart +++ b/lib/pages/device_managment/all_devices/view/device_managment_page.dart @@ -80,7 +80,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout { return BlocBuilder( builder: (context, deviceState) { if (deviceState is DeviceManagementLoading) { - return const Center(child: CircularProgressIndicator()); + return const DeviceManagementBody(devices: []); } else if (deviceState is DeviceManagementLoaded) { return DeviceManagementBody(devices: deviceState.devices); } else if (deviceState is DeviceManagementFiltered) { diff --git a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart index 9ae3b89f..af4e8039 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart @@ -69,133 +69,143 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { )), Flexible( flex: 3, - child: Column( - children: [ - Container( - padding: isLargeScreenSize(context) - ? const EdgeInsets.all(30) - : const EdgeInsets.all(15), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + child: state is DeviceManagementLoading + ? const Center(child: CircularProgressIndicator()) + : Column( children: [ - FilterWidget( - size: MediaQuery.of(context).size, - tabs: tabs, - selectedIndex: selectedIndex, - onTabChanged: (index) { - context.read().add(SelectedFilterChanged(index)); - }, - ), - const SizedBox(height: 20), - const DeviceSearchFilters(), - const SizedBox(height: 12), Container( - height: 45, - width: 125, - decoration: containerDecoration, - child: Center( - child: DefaultButton( - onPressed: isControlButtonEnabled - ? () { - if (selectedDevices.length == 1) { - showDialog( - context: context, - builder: (context) => DeviceControlDialog( - device: selectedDevices.first, - ), - ); - } else if (selectedDevices.length > 1) { - final productTypes = selectedDevices - .map((device) => device.productType) - .toSet(); - if (productTypes.length == 1) { - showDialog( - context: context, - builder: (context) => DeviceBatchControlDialog( - devices: selectedDevices, - ), - ); - } - } - } - : null, - borderRadius: 9, - child: Text( - buttonLabel, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: isControlButtonEnabled ? Colors.white : Colors.grey, + padding: isLargeScreenSize(context) + ? const EdgeInsets.all(30) + : const EdgeInsets.all(15), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + FilterWidget( + size: MediaQuery.of(context).size, + tabs: tabs, + selectedIndex: selectedIndex, + onTabChanged: (index) { + context + .read() + .add(SelectedFilterChanged(index)); + }, + ), + const SizedBox(height: 20), + const DeviceSearchFilters(), + const SizedBox(height: 12), + Container( + height: 45, + width: 125, + decoration: containerDecoration, + child: Center( + child: DefaultButton( + onPressed: isControlButtonEnabled + ? () { + if (selectedDevices.length == 1) { + showDialog( + context: context, + builder: (context) => DeviceControlDialog( + device: selectedDevices.first, + ), + ); + } else if (selectedDevices.length > 1) { + final productTypes = selectedDevices + .map((device) => device.productType) + .toSet(); + if (productTypes.length == 1) { + showDialog( + context: context, + builder: (context) => DeviceBatchControlDialog( + devices: selectedDevices, + ), + ); + } + } + } + : null, + borderRadius: 9, + child: Text( + buttonLabel, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: isControlButtonEnabled ? Colors.white : Colors.grey, + ), + ), + ), ), ), - ), + ], ), ), + Expanded( + child: Padding( + padding: isLargeScreenSize(context) + ? const EdgeInsets.all(30) + : const EdgeInsets.all(15), + child: DynamicTable( + withSelectAll: true, + cellDecoration: containerDecoration, + onRowSelected: (index, isSelected, row) { + final selectedDevice = devicesToShow[index]; + context + .read() + .add(SelectDevice(selectedDevice)); + }, + withCheckBox: true, + size: MediaQuery.of(context).size, + uuidIndex: 2, + headers: const [ + 'Device Name', + 'Product Name', + 'Device ID', + 'Space Name', + 'location', + 'Battery Level', + 'Installation Date and Time', + 'Status', + 'Last Offline Date and Time', + ], + data: devicesToShow.map((device) { + final combinedSpaceNames = device.spaces != null + ? device.spaces!.map((space) => space.spaceName).join(' > ') + + (device.community != null + ? ' > ${device.community!.name}' + : '') + : (device.community != null ? device.community!.name : ''); + + return [ + device.name ?? '', + device.productName ?? '', + device.uuid ?? '', + (device.spaces != null && device.spaces!.isNotEmpty) + ? device.spaces![0].spaceName + : '', + combinedSpaceNames, + device.batteryLevel != null ? '${device.batteryLevel}%' : '-', + formatDateTime(DateTime.fromMillisecondsSinceEpoch( + (device.createTime ?? 0) * 1000)), + device.online == true ? 'Online' : 'Offline', + formatDateTime(DateTime.fromMillisecondsSinceEpoch( + (device.updateTime ?? 0) * 1000)), + ]; + }).toList(), + onSelectionChanged: (selectedRows) { + context + .read() + .add(UpdateSelection(selectedRows)); + }, + initialSelectedIds: context + .read() + .selectedDevices + .map((device) => device.uuid!) + .toList(), + isEmpty: devicesToShow.isEmpty, + ), + ), + ) ], ), - ), - Expanded( - child: Padding( - padding: isLargeScreenSize(context) - ? const EdgeInsets.all(30) - : const EdgeInsets.all(15), - child: DynamicTable( - withSelectAll: true, - cellDecoration: containerDecoration, - onRowSelected: (index, isSelected, row) { - final selectedDevice = devicesToShow[index]; - context.read().add(SelectDevice(selectedDevice)); - }, - withCheckBox: true, - size: MediaQuery.of(context).size, - uuidIndex: 2, - headers: const [ - 'Device Name', - 'Product Name', - 'Device ID', - 'Space Name', - 'location', - 'Battery Level', - 'Installation Date and Time', - 'Status', - 'Last Offline Date and Time', - ], - data: devicesToShow.map((device) { - final combinedSpaceNames = device.spaces != null - ? device.spaces!.map((space) => space.spaceName).join(' > ') + - (device.community != null ? ' > ${device.community!.name}' : '') - : (device.community != null ? device.community!.name : ''); - - return [ - device.name ?? '', - device.productName ?? '', - device.uuid ?? '', - (device.spaces != null && device.spaces!.isNotEmpty) - ? device.spaces![0].spaceName - : '', - combinedSpaceNames, - device.batteryLevel != null ? '${device.batteryLevel}%' : '-', - formatDateTime(DateTime.fromMillisecondsSinceEpoch( - (device.createTime ?? 0) * 1000)), - device.online == true ? 'Online' : 'Offline', - formatDateTime(DateTime.fromMillisecondsSinceEpoch( - (device.updateTime ?? 0) * 1000)), - ]; - }).toList(), - onSelectionChanged: (selectedRows) { - context.read().add(UpdateSelection(selectedRows)); - }, - initialSelectedIds: context - .read() - .selectedDevices - .map((device) => device.uuid!) - .toList(), - isEmpty: devicesToShow.isEmpty, - ), - ), - ) - ], - ), ), ], );