mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 23:24:56 +00:00
power_clamp_issue
This commit is contained in:
@ -23,7 +23,6 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
on<FilterRecordsByDateEvent>(_filterRecordsByDate);
|
||||
on<SelectDateEvent>(checkDayMonthYearSelected);
|
||||
on<SmartPowerFactoryReset>(_onFactoryReset);
|
||||
// FetchPowerClampBatchStatusEvent
|
||||
}
|
||||
|
||||
late PowerClampModel deviceStatus;
|
||||
@ -223,27 +222,27 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
phaseData = [
|
||||
{
|
||||
'name': 'Phase A',
|
||||
'voltage': '${deviceStatus.status.phaseA.dataPoints[0].value} V',
|
||||
'current': '${deviceStatus.status.phaseA.dataPoints[1].value} A',
|
||||
'voltage': '${deviceStatus.status.phaseA.dataPoints[0].value / 10} V',
|
||||
'current': '${deviceStatus.status.phaseA.dataPoints[1].value / 10} A',
|
||||
'activePower': '${deviceStatus.status.phaseA.dataPoints[2].value} W',
|
||||
'powerFactor': '${deviceStatus.status.phaseA.dataPoints[3].value}',
|
||||
},
|
||||
{
|
||||
'name': 'Phase B',
|
||||
'voltage': '${deviceStatus.status.phaseB.dataPoints[0].value} V',
|
||||
'current': '${deviceStatus.status.phaseB.dataPoints[1].value} A',
|
||||
'voltage': '${deviceStatus.status.phaseB.dataPoints[0].value / 10} V',
|
||||
'current': '${deviceStatus.status.phaseB.dataPoints[1].value / 10} A',
|
||||
'activePower': '${deviceStatus.status.phaseB.dataPoints[2].value} W',
|
||||
'powerFactor': '${deviceStatus.status.phaseB.dataPoints[3].value}',
|
||||
},
|
||||
{
|
||||
'name': 'Phase C',
|
||||
'voltage': '${deviceStatus.status.phaseC.dataPoints[0].value} V',
|
||||
'current': '${deviceStatus.status.phaseC.dataPoints[1].value} A',
|
||||
'voltage': '${deviceStatus.status.phaseC.dataPoints[0].value / 10} V',
|
||||
'current': '${deviceStatus.status.phaseC.dataPoints[1].value / 10} A',
|
||||
'activePower': '${deviceStatus.status.phaseC.dataPoints[2].value} W',
|
||||
'powerFactor': '${deviceStatus.status.phaseC.dataPoints[3].value}',
|
||||
},
|
||||
];
|
||||
emit(SmartPowerStatusLoaded(deviceStatus, currentPage));
|
||||
emit(GetDeviceStatus());
|
||||
} catch (e) {
|
||||
emit(SmartPowerError(e.toString()));
|
||||
}
|
||||
@ -253,12 +252,14 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
SmartPowerArrowPressedEvent event, Emitter<SmartPowerState> emit) {
|
||||
currentPage = (currentPage + event.direction + 4) % 4;
|
||||
emit(SmartPowerStatusLoaded(deviceStatus, currentPage));
|
||||
emit(GetDeviceStatus());
|
||||
}
|
||||
|
||||
FutureOr<void> _onPageChanged(
|
||||
SmartPowerPageChangedEvent event, Emitter<SmartPowerState> emit) {
|
||||
currentPage = event.page;
|
||||
emit(SmartPowerStatusLoaded(deviceStatus, currentPage));
|
||||
emit(GetDeviceStatus());
|
||||
}
|
||||
|
||||
Future<void> _onFactoryReset(
|
||||
@ -588,14 +589,16 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Pops without value, returning null
|
||||
Navigator.of(context)
|
||||
.pop(); // Pops without value, returning null
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('OK'),
|
||||
onPressed: () {
|
||||
final selectedDateTime = DateTime(selectedYear);
|
||||
Navigator.of(context).pop(selectedDateTime); // Pops with the selected date
|
||||
Navigator.of(context).pop(
|
||||
selectedDateTime); // Pops with the selected date
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -635,8 +638,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
minimumYear: 1900,
|
||||
maximumYear: DateTime.now().year,
|
||||
onDateTimeChanged: (DateTime newDateTime) {
|
||||
selectedDate =
|
||||
newDateTime; // Update the selected date when changed
|
||||
selectedDate = newDateTime;
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -650,15 +652,13 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.pop(); // Dismiss the modal without returning a value
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('OK'),
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.pop(selectedDate); // Return the selected date
|
||||
Navigator.of(context).pop(selectedDate);
|
||||
},
|
||||
),
|
||||
],
|
||||
@ -674,6 +674,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
}
|
||||
|
||||
DateTime? dateTime = DateTime.now();
|
||||
|
||||
String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now());
|
||||
|
||||
void checkDayMonthYearSelected(
|
||||
@ -708,12 +709,17 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
emit(SmartPowerLoading());
|
||||
});
|
||||
// Use the selected picker
|
||||
|
||||
await dateSelector(event.context).then((newDate) {
|
||||
add(FilterRecordsByDateEvent(
|
||||
selectedDate: dateTime!,
|
||||
viewType: views[currentIndex],
|
||||
));
|
||||
if (newDate.toString() == 'null') {
|
||||
emit(GetDeviceStatus());
|
||||
} else {
|
||||
dateTime = newDate;
|
||||
add(FilterRecordsByDateEvent(
|
||||
selectedDate: newDate!,
|
||||
viewType: views[currentIndex],
|
||||
));
|
||||
}
|
||||
// formattedDate = newDate.toString();
|
||||
});
|
||||
emit(FilterRecordsState(filteredRecords: energyDataList));
|
||||
|
||||
@ -725,21 +731,24 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
FilterRecordsByDateEvent event, Emitter<SmartPowerState> emit) {
|
||||
emit(SmartPowerLoading());
|
||||
|
||||
print('FilterRecordsByDate method called');
|
||||
print('Selected date: ${event.selectedDate}');
|
||||
print('View type: ${event.viewType}');
|
||||
|
||||
if (event.viewType == 'Year') {
|
||||
formattedDate = event.selectedDate.year.toString();
|
||||
filteredRecords = record
|
||||
.where((record) => record.eventTime!.year == event.selectedDate.year)
|
||||
.toList();
|
||||
} else if (event.viewType == 'Month') {
|
||||
formattedDate =
|
||||
"${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}";
|
||||
|
||||
filteredRecords = record
|
||||
.where((record) =>
|
||||
record.eventTime!.year == event.selectedDate.year &&
|
||||
record.eventTime!.month == event.selectedDate.month)
|
||||
.toList();
|
||||
} else if (event.viewType == 'Day') {
|
||||
formattedDate =
|
||||
"${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}-${event.selectedDate.day}";
|
||||
|
||||
filteredRecords = record
|
||||
.where((record) =>
|
||||
record.eventTime!.year == event.selectedDate.year &&
|
||||
@ -748,9 +757,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
.toList();
|
||||
}
|
||||
|
||||
print('Filtered Records: ${filteredRecords.length} items found.');
|
||||
|
||||
// Update `energyDataList` with filtered records.
|
||||
selectDateRange();
|
||||
energyDataList = filteredRecords.map((eventDevice) {
|
||||
return EnergyData(
|
||||
event.viewType == 'Year'
|
||||
@ -762,14 +769,6 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
double.parse(eventDevice.value!),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
// if (filteredRecords.isEmpty) {
|
||||
// print('No records found for the selected date');
|
||||
// } else {
|
||||
// print('Filtered energyDataList: ${energyDataList.length} items found.');
|
||||
// }
|
||||
|
||||
// Emitting state for filtered data
|
||||
emit(FilterRecordsState(filteredRecords: energyDataList));
|
||||
}
|
||||
|
||||
@ -777,4 +776,13 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
final date = DateTime(0, month);
|
||||
return DateFormat.MMM().format(date);
|
||||
}
|
||||
|
||||
String endChartDate = '';
|
||||
void selectDateRange() async {
|
||||
DateTime startDate = dateTime!;
|
||||
DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1)
|
||||
.subtract(Duration(days: 1));
|
||||
String formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate);
|
||||
endChartDate = ' - $formattedEndDate';
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ class SmartPowerState extends Equatable {
|
||||
class SmartPowerInitial extends SmartPowerState {}
|
||||
|
||||
class SmartPowerLoading extends SmartPowerState {}
|
||||
class GetDeviceStatus extends SmartPowerState {}
|
||||
//GetDeviceStatus
|
||||
|
||||
class SmartPowerLoadBatchControll extends SmartPowerState {
|
||||
final PowerClampBatchModel status;
|
||||
|
||||
Reference in New Issue
Block a user