Add flush sensor icon to assets and enhancement code

This commit is contained in:
mohammad
2025-05-07 10:11:33 +03:00
parent 14a5d26ef9
commit 9cc4538dc5
10 changed files with 126 additions and 83 deletions
@@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart';
import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_info_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
@@ -15,17 +16,17 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
late DeviceModel deviceModel;
late FlushSensorModel deviceStatus;
FlushSensorBloc({required this.deviceId}) : super(InitialState()) {
on<InitialEvent>(_fetchFlushSensorStatus);
on<ChangeIndicatorEvent>(_changeIndicator);
on<ChangeValueEvent>(_changeValue);
on<WallSensorUpdatedEvent>(_flushSensorUpdated);
on<GetDeviceReportsEvent>(_getDeviceReports);
FlushSensorBloc({required this.deviceId}) : super(FlushSensorInitialState()) {
on<FlushSensorInitialEvent>(_fetchFlushSensorStatus);
on<FlushSensorChangeIndicatorEvent>(_changeIndicator);
on<FlushSensorChangeValueEvent>(_changeValue);
on<FlushSensorUpdatedEvent>(_flushSensorUpdated);
on<FlushSensorGetDeviceReportsEvent>(_getDeviceReports);
}
void _fetchFlushSensorStatus(
InitialEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingInitialState());
FlushSensorInitialEvent event, Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingInitialState());
try {
var response = await DevicesAPI.getDeviceStatus(deviceId);
List<StatusModel> statusModelList = [];
@@ -33,10 +34,10 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
statusModelList.add(StatusModel.fromJson(status));
}
deviceStatus = FlushSensorModel.fromJson(statusModelList);
emit(UpdateState(flushSensorModel: deviceStatus));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
_listenToChanges();
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
}
@@ -60,7 +61,7 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
});
deviceStatus = FlushSensorModel.fromJson(statusList);
if (!isClosed) {
add(WallSensorUpdatedEvent());
add(FlushSensorUpdatedEvent());
}
});
} catch (_) {
@@ -79,51 +80,53 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
}
_flushSensorUpdated(
WallSensorUpdatedEvent event, Emitter<FlushSensorState> emit) {
emit(UpdateState(flushSensorModel: deviceStatus));
FlushSensorUpdatedEvent event, Emitter<FlushSensorState> emit) {
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
}
void _changeIndicator(
ChangeIndicatorEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingNewSate(flushSensorModel: deviceStatus));
void _changeIndicator(FlushSensorChangeIndicatorEvent event,
Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingNewSate(flushSensorModel: deviceStatus));
try {
final response = await DevicesAPI.controlDevice(
DeviceControlModel(
deviceId: deviceId, code: 'indicator', value: !event.value),
deviceId);
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
emit(UpdateState(flushSensorModel: deviceStatus));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
}
void _changeValue(
ChangeValueEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingNewSate(flushSensorModel: deviceStatus));
FlushSensorChangeValueEvent event, Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingNewSate(flushSensorModel: deviceStatus));
try {
final response = await DevicesAPI.controlDevice(
DeviceControlModel(
deviceId: deviceId, code: event.code, value: event.value),
deviceId);
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
emit(UpdateState(flushSensorModel: deviceStatus));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
}
void _getDeviceReports(
GetDeviceReportsEvent event, Emitter<FlushSensorState> emit) async {
emit(LoadingInitialState());
void _getDeviceReports(FlushSensorGetDeviceReportsEvent event,
Emitter<FlushSensorState> emit) async {
emit(FlushSensorLoadingInitialState());
try {
await DevicesAPI.getDeviceReports(deviceId, event.code).then((value) {
emit(DeviceReportsState(deviceReport: value, code: event.code));
emit(FlushSensorDeviceReportsState(
deviceReport: value, code: event.code));
});
} catch (e) {
emit(FailedState(error: e.toString()));
emit(FlushSensorFailedState(error: e.toString()));
return;
}
}
}
@@ -7,33 +7,35 @@ abstract class FlushSensorEvent extends Equatable {
List<Object> get props => [];
}
class LoadingEvent extends FlushSensorEvent {}
class FlushSensorLoadingEvent extends FlushSensorEvent {}
class InitialEvent extends FlushSensorEvent {}
class FlushSensorInitialEvent extends FlushSensorEvent {}
class WallSensorUpdatedEvent extends FlushSensorEvent {}
class FlushSensorInitialDeviseInfo extends FlushSensorEvent {}
class ChangeIndicatorEvent extends FlushSensorEvent {
class FlushSensorUpdatedEvent extends FlushSensorEvent {}
class FlushSensorChangeIndicatorEvent extends FlushSensorEvent {
final bool value;
const ChangeIndicatorEvent({required this.value});
const FlushSensorChangeIndicatorEvent({required this.value});
@override
List<Object> get props => [value];
}
class ChangeValueEvent extends FlushSensorEvent {
class FlushSensorChangeValueEvent extends FlushSensorEvent {
final dynamic value;
final String code;
const ChangeValueEvent({required this.value, required this.code});
const FlushSensorChangeValueEvent({required this.value, required this.code});
@override
List<Object> get props => [value, code];
}
class GetDeviceReportsEvent extends FlushSensorEvent {
class FlushSensorGetDeviceReportsEvent extends FlushSensorEvent {
final String deviceUuid;
final String code;
const GetDeviceReportsEvent({
const FlushSensorGetDeviceReportsEvent({
required this.deviceUuid,
required this.code,
});
@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_app/features/devices/model/device_info_model.dart';
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart';
@@ -9,37 +10,43 @@ class FlushSensorState extends Equatable {
List<Object> get props => [];
}
class InitialState extends FlushSensorState {}
class FlushSensorInitialState extends FlushSensorState {}
class LoadingInitialState extends FlushSensorState {}
class FlushSensorLoadingInitialState extends FlushSensorState {}
class UpdateState extends FlushSensorState {
class FlushSensorUpdateState extends FlushSensorState {
final FlushSensorModel flushSensorModel;
const UpdateState({required this.flushSensorModel});
const FlushSensorUpdateState({required this.flushSensorModel});
@override
List<Object> get props => [flushSensorModel];
}
class LoadingNewSate extends FlushSensorState {
class FlushSensorLoadingNewSate extends FlushSensorState {
final FlushSensorModel flushSensorModel;
const LoadingNewSate({required this.flushSensorModel});
const FlushSensorLoadingNewSate({required this.flushSensorModel});
@override
List<Object> get props => [flushSensorModel];
}
class FailedState extends FlushSensorState {
class FlushSensorFailedState extends FlushSensorState {
final String error;
const FailedState({required this.error});
const FlushSensorFailedState({required this.error});
@override
List<Object> get props => [error];
}
class DeviceReportsState extends FlushSensorState {
class FlushSensorDeviceReportsState extends FlushSensorState {
final DeviceReport deviceReport;
final String code;
const DeviceReportsState({required this.deviceReport, required this.code});
const FlushSensorDeviceReportsState(
{required this.deviceReport, required this.code});
}
class FlushSensorLoadingDeviceInfo extends FlushSensorState {
final DeviceInfoModel? deviceInfo;
const FlushSensorLoadingDeviceInfo({this.deviceInfo});
}
+1 -1
View File
@@ -93,7 +93,7 @@ class DeviceModel {
} else if (type == DeviceType.SOS) {
tempIcon = Assets.sosHomeIcon;
} else if (type == DeviceType.FlushMountedSensor) {
tempIcon = Assets.sosHomeIcon;
tempIcon = Assets.flushIcon;
} else {
tempIcon = Assets.assetsIconsLogo;
}
@@ -15,7 +15,10 @@ class FlushPresenceRecords extends StatelessWidget {
final String code;
final String title;
const FlushPresenceRecords(
{super.key, required this.deviceId, required this.code, required this.title});
{super.key,
required this.deviceId,
required this.code,
required this.title});
@override
Widget build(BuildContext context) {
@@ -23,18 +26,23 @@ class FlushPresenceRecords extends StatelessWidget {
title: title,
child: BlocProvider(
create: (context) => FlushSensorBloc(deviceId: deviceId)
..add(GetDeviceReportsEvent(deviceUuid: deviceId, code: code)),
child: BlocBuilder<FlushSensorBloc, FlushSensorState>(builder: (context, state) {
..add(FlushSensorGetDeviceReportsEvent(
deviceUuid: deviceId, code: code)),
child: BlocBuilder<FlushSensorBloc, FlushSensorState>(
builder: (context, state) {
final Map<String, List<DeviceEvent>> groupedRecords = {};
if (state is LoadingInitialState) {
if (state is FlushSensorLoadingInitialState) {
return const Center(
child: DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
child: DefaultContainer(
width: 50, height: 50, child: CircularProgressIndicator()),
);
} else if (state is DeviceReportsState) {
} else if (state is FlushSensorDeviceReportsState) {
for (var record in state.deviceReport.data ?? []) {
final DateTime eventDateTime = DateTime.fromMillisecondsSinceEpoch(record.eventTime!);
final String formattedDate = DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime);
final DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(record.eventTime!);
final String formattedDate =
DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime);
// Group by formatted date
if (groupedRecords.containsKey(formattedDate)) {
@@ -52,7 +60,8 @@ class FlushPresenceRecords extends StatelessWidget {
itemCount: groupedRecords.length,
itemBuilder: (context, index) {
final String date = groupedRecords.keys.elementAt(index);
final List<DeviceEvent> recordsForDate = groupedRecords[date]!;
final List<DeviceEvent> recordsForDate =
groupedRecords[date]!;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -75,9 +84,11 @@ class FlushPresenceRecords extends StatelessWidget {
final int idx = entry.key;
final DeviceEvent record = entry.value;
final DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(record.eventTime!);
DateTime.fromMillisecondsSinceEpoch(
record.eventTime!);
final String formattedTime =
DateFormat('HH:mm:ss').format(eventDateTime);
DateFormat('HH:mm:ss')
.format(eventDateTime);
return Column(
children: [
@@ -87,10 +98,14 @@ class FlushPresenceRecords extends StatelessWidget {
record.value == 'true'
? Icons.radio_button_checked
: Icons.radio_button_unchecked,
color: record.value == 'true' ? Colors.blue : Colors.grey,
color: record.value == 'true'
? Colors.blue
: Colors.grey,
),
title: Text(
record.value == 'true' ? "Opened" : "Closed",
record.value == 'true'
? "Opened"
: "Closed",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
@@ -8,9 +8,11 @@ import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor
import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart';
import 'package:syncrow_app/features/devices/view/device_settings/settings_page.dart';
import 'package:syncrow_app/features/devices/view/widgets/device_appbar.dart';
import 'package:syncrow_app/features/devices/view/widgets/flush_sensor/flush_persence_records.dart';
import 'package:syncrow_app/features/devices/view/widgets/flush_sensor/flush_sensor_option.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
import 'package:syncrow_app/generated/assets.dart';
@@ -31,7 +33,7 @@ class FlushMountedInterface extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => FlushSensorBloc(deviceId: deviceModel.uuid ?? '')
..add(InitialEvent()),
..add(FlushSensorInitialEvent()),
child: BlocBuilder<FlushSensorBloc, FlushSensorState>(
builder: (context, state) {
final bloc = BlocProvider.of<FlushSensorBloc>(context);
@@ -47,28 +49,23 @@ class FlushMountedInterface extends StatelessWidget {
sensiReduce: 0,
sensitivity: 0);
if (state is UpdateState) {
if (state is FlushSensorUpdateState) {
flushSensorModel = state.flushSensorModel;
} else if (state is LoadingNewSate) {
} else if (state is FlushSensorLoadingNewSate) {
flushSensorModel = state.flushSensorModel;
}
return AnnotatedRegion(
value: SystemUiOverlayStyle(
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light,
),
child: Scaffold(
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: DeviceAppbar(
deviceName: deviceModel.name!,
deviceUuid: deviceModel.uuid!,
),
body: Container(
child: DefaultScaffold(
title: deviceModel.name!,
child: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
padding: const EdgeInsets.all(Constants.defaultPadding),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
@@ -78,14 +75,14 @@ class FlushMountedInterface extends StatelessWidget {
opacity: 0.4,
),
),
child: state is LoadingInitialState
child: state is FlushSensorLoadingInitialState
? const Center(
child: RefreshProgressIndicator(),
)
: SafeArea(
child: RefreshIndicator(
onRefresh: () async {
bloc.add(InitialEvent());
bloc.add(FlushSensorInitialEvent());
},
child: ListView(children: [
SizedBox(
@@ -186,7 +186,7 @@ class FlushSensorOptionsList extends StatelessWidget {
result = (result * 10).toInt();
}
bloc.add(
ChangeValueEvent(value: result, code: controlCode),
FlushSensorChangeValueEvent(value: result, code: controlCode),
);
}
}
@@ -153,14 +153,10 @@ class FlushParameterControlDialogState
),
InkWell(
onTap: () {
if (widget.sensor.isOnline == null) {
if (widget.sensor.isOnline == null || !widget.sensor.isOnline!) {
CustomSnackBar.displaySnackBar('The device is offline');
return;
}
if (!widget.sensor.isOnline!) {
CustomSnackBar.displaySnackBar('The device is offline');
return;
}
}
Navigator.pop(context, _value);
},
child: Center(
+1
View File
@@ -1155,4 +1155,5 @@ class Assets {
static const String targetConfirmTimeIcon =
'assets/icons/target_confirm_time_icon.svg';
static const String disappeDelayIcon = 'assets/icons/disappe_delay_icon.svg';
static const String flushIcon = 'assets/icons/flush_icon.svg';
}