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
@@ -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(