mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-24 21:07:54 +00:00
door sensor
This commit is contained in:
@@ -16,8 +16,8 @@ class NotificationSettingsPage extends StatelessWidget {
|
||||
return DefaultScaffold(
|
||||
title: 'Notification Settings',
|
||||
child: BlocProvider(
|
||||
create: (context) => DoorSensorBloc(switchCode: 'switch_1', DSId: '')
|
||||
..add(const DoorSensorInitial()),
|
||||
create: (context) =>
|
||||
DoorSensorBloc(DSId: '')..add(const DoorSensorInitial()),
|
||||
child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
||||
builder: (context, state) {
|
||||
final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
|
||||
|
||||
@@ -7,71 +7,115 @@ import 'package:syncrow_app/features/devices/bloc/door_sensor_bloc/door_sensor_s
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
|
||||
// // class DoorRecordsScreen extends StatelessWidget {
|
||||
// final String DSId;
|
||||
// const DoorRecordsScreen({super.key, required this.DSId});
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return DefaultScaffold(
|
||||
// title: 'Records',
|
||||
// child: BlocProvider(
|
||||
// create: (context) =>
|
||||
// DoorSensorBloc(DSId: DSId)..add(const ReportLogsInitial()),
|
||||
// child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
||||
// builder: (context, state) {
|
||||
// final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
|
||||
// return SizedBox(
|
||||
// child: ListView.builder(
|
||||
// itemCount: doorSensorBloc.recordGroups!.data!.length,
|
||||
// itemBuilder: (context, index) {
|
||||
// final recordGroup = doorSensorBloc.recordGroups!.data![index];
|
||||
|
||||
class DoorRecordsScreen extends StatelessWidget {
|
||||
final String DSId;
|
||||
const DoorRecordsScreen({super.key,required this.DSId});
|
||||
final String DSId;
|
||||
const DoorRecordsScreen({super.key, required this.DSId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultScaffold(
|
||||
title: 'Records',
|
||||
child: BlocProvider(
|
||||
create: (context) =>
|
||||
DoorSensorBloc(switchCode: 'switch_1', DSId:DSId )
|
||||
..add(const ReportLogsInitial()),
|
||||
child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
||||
builder: (context, state) {
|
||||
final doorSensorBloc = BlocProvider.of<DoorSensorBloc>(context);
|
||||
return SizedBox(
|
||||
child: ListView.builder(
|
||||
itemCount: doorSensorBloc.recordGroups.length,
|
||||
itemBuilder: (context, index) {
|
||||
final recordGroup = doorSensorBloc.recordGroups[index];
|
||||
title: 'Records',
|
||||
child: BlocProvider(
|
||||
create: (context) =>
|
||||
DoorSensorBloc(DSId: DSId)..add(const ReportLogsInitial()),
|
||||
child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is DoorSensorLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Date header
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
DateFormat('EEEE, dd/MM/yyyy')
|
||||
.format(recordGroup.date),
|
||||
if (state is DoorSensorFailedState) {
|
||||
return Center(
|
||||
child: Text('Failed to load data: ${state.errorMessage}'),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is UpdateState && state.doorSensor != null) {
|
||||
final recordGroups = context.read<DoorSensorBloc>().recordGroups;
|
||||
|
||||
if (recordGroups == null ||
|
||||
recordGroups.data == null ||
|
||||
recordGroups.data!.isEmpty) {
|
||||
return const Center(child: Text('No records available.'));
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: recordGroups.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final record = recordGroups.data![index];
|
||||
|
||||
// Convert eventTime to a human-readable format
|
||||
final DateTime eventDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(record.eventTime!);
|
||||
final String formattedDate =
|
||||
DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime);
|
||||
final String formattedTime =
|
||||
DateFormat('HH:mm:ss').format(eventDateTime);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Date header
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
formattedDate,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
// Display the event details in DefaultContainer
|
||||
DefaultContainer(
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
record.value == 'true'
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_unchecked,
|
||||
color: record.value == 'true'
|
||||
? Colors.blue
|
||||
: Colors.grey,
|
||||
),
|
||||
title: Text(
|
||||
'Status: ${record.value}',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
subtitle: Text('Time: $formattedTime'),
|
||||
),
|
||||
// Display each record for the date
|
||||
DefaultContainer(
|
||||
child: Column(
|
||||
children: recordGroup.records.map((record) {
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
record.isOpen
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_unchecked,
|
||||
color:
|
||||
record.isOpen ? Colors.blue : Colors.grey,
|
||||
),
|
||||
title: Text(
|
||||
record.status,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
subtitle: Text(record.time),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
})));
|
||||
}
|
||||
|
||||
return const Center(child: Text('No data available.'));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class DoorSensorScreen extends StatelessWidget {
|
||||
title: 'Door Sensor',
|
||||
child: BlocProvider(
|
||||
create: (context) =>
|
||||
DoorSensorBloc(switchCode: 'switch_1', DSId: device?.uuid ?? '')
|
||||
DoorSensorBloc( DSId: device?.uuid ?? '')
|
||||
..add(const DoorSensorInitial()),
|
||||
child: BlocBuilder<DoorSensorBloc, DoorSensorState>(
|
||||
builder: (context, state) {
|
||||
|
||||
Reference in New Issue
Block a user