From a1954b3ad3565d46ff80fa831028e31b621d68aa Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 7 May 2025 10:37:59 +0300 Subject: [PATCH] add settings to flush sensor --- .../flush_sensor_bloc/flush_sensor_bloc.dart | 46 +++++++++++++++++++ .../flush_sensor/flush_sensor_interface.dart | 19 +++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart index 7790881..4b98da7 100644 --- a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart +++ b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart @@ -22,6 +22,7 @@ class FlushSensorBloc extends Bloc { on(_changeValue); on(_flushSensorUpdated); on(_getDeviceReports); + on(fetchDeviceInfo); } void _fetchFlushSensorStatus( @@ -128,5 +129,50 @@ class FlushSensorBloc extends Bloc { } } + DeviceInfoModel deviceInfo = DeviceInfoModel( + activeTime: 0, + category: "", + categoryName: "", + createTime: 0, + gatewayId: "", + icon: "", + ip: "", + lat: "", + localKey: "", + lon: "", + model: "", + name: "", + nodeId: "", + online: false, + ownerId: "", + productName: "", + sub: false, + timeZone: "", + updateTime: 0, + uuid: "", + productUuid: "", + productType: "", + permissionType: "", + macAddress: "", + subspace: Subspace( + uuid: "", + createdAt: "", + updatedAt: "", + subspaceName: "", + ), + ); + static String deviceName = ''; + void fetchDeviceInfo(FlushSensorInitialDeviseInfo event, + Emitter emit) async { + try { + emit(FlushSensorLoadingInitialState()); + var response = await DevicesAPI.getDeviceInfo(deviceId); + deviceInfo = DeviceInfoModel.fromJson(response); + deviceName = deviceInfo.name; + emit(FlushSensorLoadingDeviceInfo(deviceInfo: deviceInfo)); + } catch (e) { + emit(FlushSensorFailedState(error: e.toString())); + } + } } diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart index 341ccc7..c41c781 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart @@ -62,7 +62,24 @@ class FlushMountedInterface extends StatelessWidget { ), child: DefaultScaffold( title: deviceModel.name!, - + actions: [ + InkWell( + onTap: () async { + var val = await Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => + SettingsPage(device: deviceModel), + ), + ); + if (val == null) { + bloc.add(FlushSensorInitialDeviseInfo()); + bloc.add(FlushSensorInitialEvent()); + } + }, + child: SvgPicture.asset(Assets.assetsIconsSettings), + ), + const SizedBox(width: 10), + ], child: Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height,