mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 16:34:55 +00:00
power_clamp
This commit is contained in:
16
assets/icons/speedo_meter.svg
Normal file
16
assets/icons/speedo_meter.svg
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M12 24C8.8072 24 5.79717 22.7483 3.52439 20.4756C1.25166 18.2028 0 15.1928 0 12C0 8.8072 1.25166 5.79717 3.52444 3.52444C5.79717 1.25166 8.8072 0 12 0C15.1928 0 18.2028 1.25166 20.4756 3.52444C22.7483 5.79717 24 8.8072 24 12C24 15.1928 22.7483 18.2028 20.4756 20.4756C18.2028 22.7483 15.1928 24 12 24Z" fill="#EDF3F9"/>
|
||||||
|
<path d="M20.4756 20.4756C22.7483 18.2028 24 15.1928 24 12C24 8.8072 22.7483 5.79717 20.4756 3.52444C18.2028 1.25166 15.1928 0 12 0V24C15.1928 24 18.2028 22.7483 20.4756 20.4756Z" fill="#C2DBF2"/>
|
||||||
|
<path d="M12 22.5938C17.8508 22.5938 22.5938 17.8508 22.5938 12C22.5938 6.14923 17.8508 1.40625 12 1.40625C6.14923 1.40625 1.40625 6.14923 1.40625 12C1.40625 17.8508 6.14923 22.5938 12 22.5938Z" fill="#465A61"/>
|
||||||
|
<path d="M22.5938 12C22.5938 6.15858 17.8414 1.40625 12 1.40625V22.5938C17.8414 22.5938 22.5938 17.8414 22.5938 12Z" fill="#3B4A51"/>
|
||||||
|
<path d="M7.88953 9.29576C7.37672 10.072 7.07812 11.002 7.07812 12V12.7031H2.85938V12C2.85938 9.83717 3.61453 7.84779 4.87453 6.28076L7.88953 9.29576Z" fill="#F36A3D"/>
|
||||||
|
<path d="M21.1408 12V12.7031H16.922V12C16.922 11.002 16.6234 10.072 16.1106 9.29576L19.1256 6.28076C20.3856 7.84779 21.1408 9.83717 21.1408 12Z" fill="#66A6FF"/>
|
||||||
|
<path d="M19.1255 6.28078L16.1105 9.29578C15.2292 7.96078 13.7161 7.07812 12 7.07812V2.85938C14.8772 2.85938 17.4488 4.19578 19.1255 6.28078Z" fill="#FFDF40"/>
|
||||||
|
<path d="M12 2.85938V7.07812C10.2839 7.07812 8.77076 7.96078 7.88951 9.29578L4.87451 6.28078C6.55123 4.19578 9.12279 2.85938 12 2.85938Z" fill="#FF9F40"/>
|
||||||
|
<path d="M11.2969 8.48438H12.7031V14.8594H11.2969V8.48438Z" fill="#F36A3D"/>
|
||||||
|
<path d="M12 8.48438H12.7031V14.8594H12V8.48438Z" fill="#EC4C36"/>
|
||||||
|
<path d="M12 24C15.1066 24 17.625 21.4816 17.625 18.375C17.625 15.2684 15.1066 12.75 12 12.75C8.8934 12.75 6.375 15.2684 6.375 18.375C6.375 21.4816 8.8934 24 12 24Z" fill="#FFDF40"/>
|
||||||
|
<path d="M17.625 18.375C17.625 15.2734 15.1016 12.75 12 12.75V24C15.1016 24 17.625 21.4766 17.625 18.375Z" fill="#FFBE40"/>
|
||||||
|
<path d="M11.8818 21.5776L10.7118 20.7976L11.7983 19.1678L10.3921 17.7615L12.1182 15.1724L13.2882 15.9524L12.2017 17.5823L13.6079 18.9886L11.8818 21.5776Z" fill="#465A61"/>
|
||||||
|
<path d="M12.1182 15.1724L12 15.3496V21.4004L13.6079 18.9886L12.2017 17.5823L13.2882 15.9524L12.1182 15.1724Z" fill="#3B4A51"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.3 KiB |
41
assets/icons/voltage_icon.svg
Normal file
41
assets/icons/voltage_icon.svg
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M11.998 2.5882C11.8004 2.5882 11.6403 2.42817 11.6403 2.23069V0.357516C11.6403 0.160078 11.8004 0 11.998 0C12.1956 0 12.3558 0.160031 12.3558 0.357516V2.23073C12.3558 2.42817 12.1956 2.5882 11.998 2.5882Z" fill="#E6E2E6"/>
|
||||||
|
<path d="M5.22457 2.5882C5.02699 2.5882 4.86682 2.42817 4.86682 2.23069V0.357516C4.86682 0.160078 5.02699 0 5.22457 0C5.42215 0 5.58232 0.160031 5.58232 0.357516V2.23073C5.58232 2.42817 5.42215 2.5882 5.22457 2.5882Z" fill="#E6E2E6"/>
|
||||||
|
<path d="M18.7714 2.5882C18.5738 2.5882 18.4137 2.42817 18.4137 2.23069V0.357516C18.4137 0.160078 18.5739 0 18.7714 0C18.969 0 19.1292 0.160031 19.1292 0.357516V2.23073C19.1292 2.42817 18.969 2.5882 18.7714 2.5882Z" fill="#E6E2E6"/>
|
||||||
|
<path d="M17.6937 1.7467H19.8492C20.0782 1.7467 20.2814 1.8937 20.3528 2.1112L20.7326 3.26672C20.7832 3.42084 20.6683 3.57942 20.506 3.57942H17.0369C16.8746 3.57942 16.7596 3.42084 16.8103 3.26672L17.19 2.1112C17.2615 1.8937 17.4647 1.7467 17.6937 1.7467Z" fill="#545454"/>
|
||||||
|
<path d="M17.6935 3.57938H19.8492C20.0782 3.57938 20.2814 3.72638 20.3528 3.94383L20.7326 5.0993C20.7832 5.25342 20.6683 5.412 20.506 5.412H17.0369C16.8746 5.412 16.7596 5.25342 16.8103 5.0993L17.1901 3.94359C17.2615 3.72628 17.4646 3.57938 17.6935 3.57938Z" fill="#545454"/>
|
||||||
|
<path d="M17.6935 5.41205H19.8492C20.0782 5.41205 20.2814 5.55905 20.3528 5.77655L20.7326 6.93206C20.7832 7.08619 20.6683 7.24477 20.506 7.24477H17.0369C16.8746 7.24477 16.7596 7.08619 16.8103 6.93206L17.1901 5.77636C17.2615 5.55895 17.4646 5.41205 17.6935 5.41205Z" fill="#545454"/>
|
||||||
|
<path d="M13.0759 1.7467H10.9203C10.6912 1.7467 10.488 1.8937 10.4166 2.1112L10.0369 3.26672C9.9862 3.42084 10.1011 3.57942 10.2635 3.57942H13.7325C13.8949 3.57942 14.0098 3.42084 13.9591 3.26672L13.5793 2.11102C13.5079 1.89361 13.3049 1.7467 13.0759 1.7467Z" fill="#545454"/>
|
||||||
|
<path d="M13.0757 3.57938H10.9203C10.6912 3.57938 10.4881 3.72638 10.4166 3.94383L10.0369 5.0993C9.9862 5.25342 10.1011 5.412 10.2635 5.412H13.7325C13.8949 5.412 14.0098 5.25342 13.9591 5.0993L13.5794 3.94378C13.508 3.72638 13.3048 3.57938 13.0757 3.57938Z" fill="#545454"/>
|
||||||
|
<path d="M13.0759 5.41205H10.9203C10.6912 5.41205 10.4881 5.55905 10.4166 5.77655L10.0369 6.93206C9.9862 7.08619 10.1011 7.24477 10.2635 7.24477H13.7325C13.8949 7.24477 14.0098 7.08619 13.9591 6.93206L13.5793 5.77636C13.5079 5.55895 13.3049 5.41205 13.0759 5.41205Z" fill="#545454"/>
|
||||||
|
<path d="M6.30253 1.7467H4.14689C3.91781 1.7467 3.71465 1.8937 3.64321 2.1112L3.26343 3.26667C3.21276 3.4208 3.3277 3.57938 3.49003 3.57938H6.9591C7.12143 3.57938 7.23637 3.4208 7.1857 3.26667L6.80592 2.11097C6.73448 1.89361 6.53146 1.7467 6.30253 1.7467Z" fill="#545454"/>
|
||||||
|
<path d="M3.44264 2.72137L3.26343 3.26667C3.21276 3.4208 3.3277 3.57937 3.49003 3.57937H6.9591C7.12143 3.57937 7.23637 3.4208 7.1857 3.26667L7.0065 2.72137H3.44264Z" fill="#494949"/>
|
||||||
|
<path d="M6.30248 3.57938H4.14684C3.91776 3.57938 3.71461 3.72638 3.64317 3.94383L3.26343 5.0993C3.21276 5.25342 3.3277 5.412 3.49003 5.412H6.95911C7.12143 5.412 7.23637 5.25342 7.1857 5.0993L6.80592 3.94359C6.73443 3.72628 6.53142 3.57938 6.30248 3.57938Z" fill="#545454"/>
|
||||||
|
<path d="M3.44264 4.55405L3.26343 5.09934C3.21276 5.25347 3.3277 5.41205 3.49003 5.41205H6.9591C7.12143 5.41205 7.23637 5.25347 7.1857 5.09934L7.0065 4.55405H3.44264Z" fill="#494949"/>
|
||||||
|
<path d="M6.30225 5.41205H4.14684C3.91776 5.41205 3.71461 5.55905 3.64317 5.77655L3.26343 6.93206C3.21276 7.08619 3.3277 7.24477 3.49003 7.24477H6.95911C7.12143 7.24477 7.23637 7.08619 7.1857 6.93206L6.80596 5.77655C6.73448 5.55905 6.53132 5.41205 6.30225 5.41205Z" fill="#545454"/>
|
||||||
|
<path d="M3.44264 6.38666L3.26343 6.93196C3.21276 7.08608 3.3277 7.24466 3.49003 7.24466H6.9591C7.12143 7.24466 7.23637 7.08608 7.1857 6.93196L7.0065 6.38666H3.44264Z" fill="#494949"/>
|
||||||
|
<path d="M10.2161 2.72137L10.0369 3.26667C9.9862 3.4208 10.1011 3.57937 10.2635 3.57937H13.7325C13.8949 3.57937 14.0098 3.4208 13.9591 3.26667L13.7799 2.72137H10.2161Z" fill="#494949"/>
|
||||||
|
<path d="M10.2161 4.55405L10.0369 5.09934C9.9862 5.25347 10.1011 5.41205 10.2635 5.41205H13.7325C13.8949 5.41205 14.0098 5.25347 13.9591 5.09934L13.7799 4.55405H10.2161Z" fill="#494949"/>
|
||||||
|
<path d="M10.2161 6.38666L10.0369 6.93196C9.9862 7.08608 10.1011 7.24466 10.2635 7.24466H13.7325C13.8949 7.24466 14.0098 7.08608 13.9591 6.93196L13.7799 6.38666H10.2161Z" fill="#494949"/>
|
||||||
|
<path d="M16.9895 2.72137L16.8103 3.26667C16.7596 3.4208 16.8746 3.57937 17.0369 3.57937H20.506C20.6683 3.57937 20.7832 3.4208 20.7326 3.26667L20.5534 2.72137H16.9895Z" fill="#494949"/>
|
||||||
|
<path d="M16.9895 4.55405L16.8103 5.09934C16.7596 5.25347 16.8746 5.41205 17.0369 5.41205H20.506C20.6683 5.41205 20.7832 5.25347 20.7326 5.09934L20.5534 4.55405H16.9895Z" fill="#494949"/>
|
||||||
|
<path d="M16.9895 6.38666L16.8103 6.93196C16.7596 7.08608 16.8746 7.24466 17.0369 7.24466H20.506C20.6683 7.24466 20.7832 7.08608 20.7326 6.93196L20.5534 6.38666H16.9895Z" fill="#494949"/>
|
||||||
|
<path d="M11.0522 7.24466H12.9437V8.88885H11.0522V7.24466Z" fill="#545454"/>
|
||||||
|
<path d="M4.27881 7.24466H6.17031V8.88885H4.27881V7.24466Z" fill="#545454"/>
|
||||||
|
<path d="M19.7172 8.88892H17.8257V7.24473H19.7172V8.88892Z" fill="#545454"/>
|
||||||
|
<path d="M1.21143 10.9806H22.7886V21.9083H1.21143V10.9806Z" fill="#545454"/>
|
||||||
|
<path d="M1.21143 10.9806H22.7886V11.8386H1.21143V10.9806Z" fill="#494949"/>
|
||||||
|
<path d="M11.998 12.3605C11.8004 12.3605 11.6403 12.2004 11.6403 12.003V10.7935C11.6403 10.596 11.8004 10.436 11.998 10.436C12.1956 10.436 12.3558 10.596 12.3558 10.7935V12.003C12.3558 12.2004 12.1956 12.3605 11.998 12.3605Z" fill="#E6E2E6"/>
|
||||||
|
<path d="M5.22457 12.3605C5.02699 12.3605 4.86682 12.2004 4.86682 12.003V10.7935C4.86682 10.596 5.02699 10.436 5.22457 10.436C5.42215 10.436 5.58232 10.596 5.58232 10.7935V12.003C5.58232 12.2004 5.42215 12.3605 5.22457 12.3605Z" fill="#E6E2E6"/>
|
||||||
|
<path d="M18.7714 12.3605C18.5738 12.3605 18.4137 12.2004 18.4137 12.003V10.7935C18.4137 10.596 18.5739 10.436 18.7714 10.436C18.969 10.436 19.1292 10.596 19.1292 10.7935V12.003C19.1292 12.2004 18.969 12.3605 18.7714 12.3605Z" fill="#E6E2E6"/>
|
||||||
|
<path d="M23.5233 10.9806H0.476672C0.213422 10.9806 0 10.7672 0 10.5039V9.36559C0 9.10234 0.213422 8.88892 0.476672 8.88892H23.5233C23.7865 8.88892 24 9.10234 24 9.36559V10.5039C24 10.7672 23.7866 10.9806 23.5233 10.9806Z" fill="#A8A7A8"/>
|
||||||
|
<path d="M23.5231 10.1226H0.476859C0.213516 10.1226 0 9.90929 0 9.64609V10.5041C0 10.7673 0.213516 10.9806 0.476859 10.9806H23.5231C23.7865 10.9806 24 10.7673 24 10.5041V9.64609C24 9.90929 23.7865 10.1226 23.5231 10.1226Z" fill="#818181"/>
|
||||||
|
<path d="M23.5233 24H0.476672C0.213422 24 0 23.7866 0 23.5234V22.385C0 22.1217 0.213422 21.9083 0.476672 21.9083H23.5233C23.7865 21.9083 24 22.1217 24 22.385V23.5234C24 23.7866 23.7866 24 23.5233 24Z" fill="#A8A7A8"/>
|
||||||
|
<path d="M23.5231 23.142H0.476859C0.213516 23.142 0 22.9287 0 22.6655V23.5235C0 23.7867 0.213516 24 0.476859 24H23.5231C23.7865 24 24 23.7867 24 23.5235V22.6655C24 22.9287 23.7865 23.142 23.5231 23.142Z" fill="#818181"/>
|
||||||
|
<path d="M15.6454 19.172L12.6056 14.0633C12.3317 13.6029 11.6644 13.6029 11.3904 14.0633L8.35062 19.172C8.07068 19.6425 8.4102 20.2384 8.95816 20.2384H15.0378C15.5858 20.2384 15.9253 19.6425 15.6454 19.172Z" fill="#F6E266"/>
|
||||||
|
<path d="M15.6023 19.0995C15.4767 19.2667 15.2772 19.3804 15.0379 19.3804H8.95829C8.71894 19.3804 8.51944 19.2667 8.39387 19.0995L8.35074 19.172C8.0708 19.6425 8.41032 20.2384 8.95829 20.2384H15.0379C15.5859 20.2384 15.9254 19.6425 15.6454 19.172L15.6023 19.0995Z" fill="#FFC239"/>
|
||||||
|
<path d="M11.0522 8.06677H12.9437V8.88887H11.0522V8.06677Z" fill="#494949"/>
|
||||||
|
<path d="M4.27881 8.06677H6.17031V8.88887H4.27881V8.06677Z" fill="#494949"/>
|
||||||
|
<path d="M17.8257 8.06677H19.7172V8.88887H17.8257V8.06677Z" fill="#494949"/>
|
||||||
|
<path d="M11.9225 15.9461L10.9958 17.4033C10.9256 17.5136 10.9211 17.6534 10.9841 17.7679C11.0471 17.8825 11.1675 17.9536 11.2983 17.9536H11.7902L11.2135 18.8605C11.1073 19.0275 11.1567 19.2488 11.3237 19.355C11.4658 19.449 11.7038 19.4221 11.8185 19.2448L12.7453 17.7876C12.8154 17.6773 12.8198 17.5376 12.7569 17.423C12.6939 17.3085 12.5735 17.2373 12.4427 17.2373H11.9508L12.5276 16.3304C12.6338 16.1634 12.5844 15.942 12.4173 15.8359C12.2503 15.7298 12.0287 15.7792 11.9225 15.9461Z" fill="#DD636E"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 8.1 KiB |
@ -1,7 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
@ -9,17 +8,15 @@ import 'package:syncrow_app/features/devices/bloc/power_clamp_bloc/power_clamp_e
|
|||||||
import 'package:syncrow_app/features/devices/bloc/power_clamp_bloc/power_clamp_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/power_clamp_bloc/power_clamp_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/power_clamp_model.dart';
|
import 'package:syncrow_app/features/devices/model/power_clamp_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/power_clamp/power_chart.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/power_clamp/power_chart.dart';
|
||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
|
||||||
|
|
||||||
class PowerClampBloc extends Bloc<PowerClampEvent, PowerClampState> {
|
class PowerClampBloc extends Bloc<PowerClampEvent, PowerClampState> {
|
||||||
final String PCId;
|
final String PCId;
|
||||||
PowerClampBloc({
|
PowerClampBloc({
|
||||||
required this.PCId,
|
required this.PCId,
|
||||||
}) : super(const PowerClampState()) {
|
}) : super(const PowerClampState()) {
|
||||||
on<PowerClampInitial>(_fetchStatus);
|
on<PowerClampInitial>(_fetchPowerClampInfo);
|
||||||
on<ReportLogsInitial>(fetchLogsForLastMonth);
|
on<ReportLogsInitial>(fetchLogsForLastMonth);
|
||||||
on<FetchEnergyData>(_mapReportToEnergyData);
|
on<FetchEnergyData>(_mapReportToEnergyData);
|
||||||
on<SelectDateEvent>(selectTimeOfLinePassword);
|
on<SelectDateEvent>(selectTimeOfLinePassword);
|
||||||
@ -32,30 +29,80 @@ class PowerClampBloc extends Bloc<PowerClampEvent, PowerClampState> {
|
|||||||
bool lowBattery = false;
|
bool lowBattery = false;
|
||||||
bool closingReminder = false;
|
bool closingReminder = false;
|
||||||
bool doorAlarm = false;
|
bool doorAlarm = false;
|
||||||
PowerClampModel deviceStatus =
|
|
||||||
PowerClampModel(doorContactState: false, batteryPercentage: 0);
|
|
||||||
|
|
||||||
void _fetchStatus(
|
PowerClampModel deviceStatus = PowerClampModel(
|
||||||
|
productType: '',
|
||||||
|
productUuid: '',
|
||||||
|
status: PowerStatus(
|
||||||
|
phaseA: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '', customName: '', dpId: 0, time: 0, type: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
phaseB: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '', customName: '', dpId: 0, time: 0, type: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
phaseC: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '', customName: '', dpId: 0, time: 0, type: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
general: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '', customName: '', dpId: 0, time: 0, type: '', value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// void _fetchStatus(
|
||||||
|
// PowerClampInitial event, Emitter<PowerClampState> emit) async {
|
||||||
|
// emit(PowerClampLoadingState());
|
||||||
|
// try {
|
||||||
|
// var response = await DevicesAPI.getDeviceStatus(PCId);
|
||||||
|
// List<StatusModel> statusModelList = [];
|
||||||
|
// for (var status in response['status']) {
|
||||||
|
// statusModelList.add(StatusModel.fromJson(status));
|
||||||
|
// }
|
||||||
|
// deviceStatus = PowerClampModel.fromJson(
|
||||||
|
// statusModelList,
|
||||||
|
// );
|
||||||
|
// emit(UpdateState(powerClampModel: deviceStatus));
|
||||||
|
// Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
// // _listenToChanges();
|
||||||
|
// } catch (e) {
|
||||||
|
// emit(PowerClampFailedState(errorMessage: e.toString()));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
void _fetchPowerClampInfo(
|
||||||
PowerClampInitial event, Emitter<PowerClampState> emit) async {
|
PowerClampInitial event, Emitter<PowerClampState> emit) async {
|
||||||
emit(PowerClampLoadingState());
|
emit(PowerClampLoadingState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(PCId);
|
var response = await DevicesAPI.getPowerClampStatus(PCId);
|
||||||
List<StatusModel> statusModelList = [];
|
PowerClampModel deviceStatus = PowerClampModel.fromJson(response);
|
||||||
for (var status in response['status']) {
|
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
|
||||||
}
|
|
||||||
deviceStatus = PowerClampModel.fromJson(
|
|
||||||
statusModelList,
|
|
||||||
);
|
|
||||||
emit(UpdateState(powerClampModel: deviceStatus));
|
emit(UpdateState(powerClampModel: deviceStatus));
|
||||||
Future.delayed(const Duration(milliseconds: 500));
|
Future.delayed(const Duration(milliseconds: 500));
|
||||||
// _listenToChanges();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(PowerClampFailedState(errorMessage: e.toString()));
|
emit(PowerClampFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//List<StatusModel> statusModelList = [];
|
||||||
|
// for (var status in response['status']) {
|
||||||
|
// statusModelList.add(StatusModel.fromJson(status));
|
||||||
|
// }
|
||||||
|
// deviceStatus = PowerClampModel.fromJson(
|
||||||
|
// statusModelList,
|
||||||
|
// );
|
||||||
|
|
||||||
DeviceReport recordGroups =
|
DeviceReport recordGroups =
|
||||||
DeviceReport(startTime: '0', endTime: '0', data: []);
|
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||||
|
|
||||||
@ -84,33 +131,33 @@ class PowerClampBloc extends Bloc<PowerClampEvent, PowerClampState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_listenToChanges() {
|
// _listenToChanges() {
|
||||||
try {
|
// try {
|
||||||
DatabaseReference ref =
|
// DatabaseReference ref =
|
||||||
FirebaseDatabase.instance.ref('device-status/$PCId');
|
// FirebaseDatabase.instance.ref('device-status/$PCId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
// Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
// stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
// if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
// await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
// }
|
||||||
Map<dynamic, dynamic> usersMap =
|
// Map<dynamic, dynamic> usersMap =
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
// event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
// List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
// usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: true));
|
// statusList.add(StatusModel(code: element['code'], value: true));
|
||||||
});
|
// });
|
||||||
|
|
||||||
deviceStatus = PowerClampModel.fromJson(statusList);
|
// deviceStatus = PowerClampModel.fromJson(statusList);
|
||||||
if (!isClosed) {
|
// if (!isClosed) {
|
||||||
add(
|
// add(
|
||||||
PowerClampSwitch(switchD: deviceStatus.doorContactState),
|
// PowerClampSwitch(switchD: deviceStatus.doorContactState),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
} catch (_) {}
|
// } catch (_) {}
|
||||||
}
|
// }
|
||||||
|
|
||||||
// New Function: Convert the device report data into EnergyData and emit it.
|
// New Function: Convert the device report data into EnergyData and emit it.
|
||||||
void _mapReportToEnergyData(
|
void _mapReportToEnergyData(
|
||||||
@ -167,7 +214,6 @@ class PowerClampBloc extends Bloc<PowerClampEvent, PowerClampState> {
|
|||||||
).millisecondsSinceEpoch ~/
|
).millisecondsSinceEpoch ~/
|
||||||
1000; // Divide by 1000 to remove milliseconds
|
1000; // Divide by 1000 to remove milliseconds
|
||||||
|
|
||||||
|
|
||||||
DateTime dateTime =
|
DateTime dateTime =
|
||||||
selectedDateTime; // Assuming this is your DateTime object
|
selectedDateTime; // Assuming this is your DateTime object
|
||||||
formattedDate = DateFormat('yyyy/MM/dd').format(dateTime);
|
formattedDate = DateFormat('yyyy/MM/dd').format(dateTime);
|
||||||
|
|||||||
@ -1,28 +1,86 @@
|
|||||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
// PowerClampModel class to represent the response
|
||||||
|
|
||||||
class PowerClampModel {
|
class PowerClampModel {
|
||||||
dynamic doorContactState;
|
String productUuid;
|
||||||
dynamic batteryPercentage;
|
String productType;
|
||||||
|
PowerStatus status;
|
||||||
|
|
||||||
PowerClampModel({
|
PowerClampModel({
|
||||||
required this.doorContactState,
|
required this.productUuid,
|
||||||
required this.batteryPercentage,
|
required this.productType,
|
||||||
|
required this.status,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory PowerClampModel.fromJson(List<StatusModel> jsonList) {
|
factory PowerClampModel.fromJson(Map<String, dynamic> json) {
|
||||||
late dynamic _doorContactState;
|
|
||||||
late dynamic _batteryPercentage;
|
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
|
||||||
if (jsonList[i].code == 'VoltageA') {
|
|
||||||
_doorContactState = jsonList[i].value ?? false;
|
|
||||||
} else if (jsonList[i].code == 'CurrentA') {
|
|
||||||
_batteryPercentage = jsonList[i].value ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PowerClampModel(
|
return PowerClampModel(
|
||||||
doorContactState: _doorContactState,
|
productUuid: json['productUuid'],
|
||||||
batteryPercentage: _batteryPercentage,
|
productType: json['productType'],
|
||||||
|
status: PowerStatus.fromJson(json['status']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PowerStatus {
|
||||||
|
Phase phaseA;
|
||||||
|
Phase phaseB;
|
||||||
|
Phase phaseC;
|
||||||
|
Phase general;
|
||||||
|
|
||||||
|
PowerStatus({
|
||||||
|
required this.phaseA,
|
||||||
|
required this.phaseB,
|
||||||
|
required this.phaseC,
|
||||||
|
required this.general,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory PowerStatus.fromJson(Map<String, dynamic> json) {
|
||||||
|
return PowerStatus(
|
||||||
|
phaseA: Phase.fromJson(json['phaseA']),
|
||||||
|
phaseB: Phase.fromJson(json['phaseB']),
|
||||||
|
phaseC: Phase.fromJson(json['phaseC']),
|
||||||
|
general: Phase.fromJson(json['general']
|
||||||
|
// List<DataPoint>.from(
|
||||||
|
// json['general'].map((x) => DataPoint.fromJson(x))),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Phase {
|
||||||
|
List<DataPoint> dataPoints;
|
||||||
|
|
||||||
|
Phase({required this.dataPoints});
|
||||||
|
|
||||||
|
factory Phase.fromJson(List<dynamic> json) {
|
||||||
|
return Phase(
|
||||||
|
dataPoints: json.map((x) => DataPoint.fromJson(x)).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DataPoint {
|
||||||
|
dynamic code;
|
||||||
|
dynamic customName;
|
||||||
|
dynamic dpId;
|
||||||
|
dynamic time;
|
||||||
|
dynamic type;
|
||||||
|
dynamic value;
|
||||||
|
|
||||||
|
DataPoint({
|
||||||
|
required this.code,
|
||||||
|
required this.customName,
|
||||||
|
required this.dpId,
|
||||||
|
required this.time,
|
||||||
|
required this.type,
|
||||||
|
required this.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory DataPoint.fromJson(Map<String, dynamic> json) {
|
||||||
|
return DataPoint(
|
||||||
|
code: json['code'],
|
||||||
|
customName: json['customName'],
|
||||||
|
dpId: json['dpId'],
|
||||||
|
time: json['time'],
|
||||||
|
type: json['type'],
|
||||||
|
value: json['value'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,26 @@ class PowerClampPage extends StatefulWidget {
|
|||||||
class _PowerClampPageState extends State<PowerClampPage> {
|
class _PowerClampPageState extends State<PowerClampPage> {
|
||||||
final PageController _pageController = PageController();
|
final PageController _pageController = PageController();
|
||||||
int _currentPage = 0;
|
int _currentPage = 0;
|
||||||
final int _pageCount = 5;
|
final int _pageCount = 4;
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
// Add listener to update _currentPage when the page is changed
|
||||||
|
_pageController.addListener(() {
|
||||||
|
int nextPage = _pageController.page?.round() ?? 0;
|
||||||
|
if (_currentPage != nextPage) {
|
||||||
|
setState(() {
|
||||||
|
_currentPage = nextPage;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_pageController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -35,24 +54,68 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
title: 'Power Clamp',
|
title: 'Power Clamp',
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) => PowerClampBloc(PCId: widget.device?.uuid ?? '')
|
create: (context) => PowerClampBloc(PCId: widget.device?.uuid ?? '')
|
||||||
..add(const PowerClampInitial())
|
..add(const PowerClampInitial()),
|
||||||
..add(ReportLogsInitial(code: 'VoltageA')),
|
|
||||||
child: BlocBuilder<PowerClampBloc, PowerClampState>(
|
child: BlocBuilder<PowerClampBloc, PowerClampState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final _blocProvider = BlocProvider.of<PowerClampBloc>(context);
|
final _blocProvider = BlocProvider.of<PowerClampBloc>(context);
|
||||||
PowerClampModel model =
|
PowerClampModel model = PowerClampModel(
|
||||||
PowerClampModel(batteryPercentage: 0, doorContactState: false);
|
productType: '',
|
||||||
|
productUuid: '',
|
||||||
|
status: PowerStatus(
|
||||||
|
phaseA: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '',
|
||||||
|
customName: '',
|
||||||
|
dpId: 0,
|
||||||
|
time: 0,
|
||||||
|
type: '',
|
||||||
|
value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
phaseB: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '',
|
||||||
|
customName: '',
|
||||||
|
dpId: 0,
|
||||||
|
time: 0,
|
||||||
|
type: '',
|
||||||
|
value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
phaseC: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '',
|
||||||
|
customName: '',
|
||||||
|
dpId: 0,
|
||||||
|
time: 0,
|
||||||
|
type: '',
|
||||||
|
value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
general: Phase(
|
||||||
|
dataPoints: [
|
||||||
|
DataPoint(
|
||||||
|
code: '',
|
||||||
|
customName: '',
|
||||||
|
dpId: 0,
|
||||||
|
time: 0,
|
||||||
|
type: '',
|
||||||
|
value: 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
List<EnergyData> chartData = [];
|
List<EnergyData> chartData = [];
|
||||||
|
|
||||||
if (state is LoadingNewSate) {
|
if (state is UpdateState) {
|
||||||
model = state.powerClampModel;
|
|
||||||
} else if (state is UpdateState) {
|
|
||||||
model = state.powerClampModel;
|
model = state.powerClampModel;
|
||||||
} else if (state is EnergyDataState) {
|
} else if (state is EnergyDataState) {
|
||||||
chartData = state.energyData;
|
chartData = state.energyData;
|
||||||
print(chartData);
|
print(chartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state is PowerClampLoadingState
|
return state is PowerClampLoadingState
|
||||||
? const Center(
|
? const Center(
|
||||||
child: DefaultContainer(
|
child: DefaultContainer(
|
||||||
@ -62,209 +125,147 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
)
|
)
|
||||||
: Column(
|
: Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Flexible(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
_blocProvider.add(const PowerClampInitial());
|
_blocProvider.add(const PowerClampInitial());
|
||||||
},
|
},
|
||||||
child: Padding(
|
child:
|
||||||
padding: EdgeInsets.only(top: 25),
|
PageView(controller: _pageController, children: [
|
||||||
child: PageView.builder(
|
powerClampCard(
|
||||||
controller: _pageController,
|
title: 'Total Energy \nConsumption',
|
||||||
onPageChanged: (int page) {
|
isGeneral: true,
|
||||||
setState(() {
|
dateSwitcher: _blocProvider.dateSwitcher(),
|
||||||
_currentPage = page;
|
formattedDate: _blocProvider.formattedDate,
|
||||||
});
|
selectDateEvent: () {
|
||||||
_blocProvider.add(
|
|
||||||
const ReportLogsInitial(code: 'VoltageA'));
|
|
||||||
},
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return DefaultContainer(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 10,
|
|
||||||
right: 10,
|
|
||||||
top: 25,
|
|
||||||
bottom: 20),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment:
|
|
||||||
CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text('Energy usage'),
|
|
||||||
const Row(
|
|
||||||
crossAxisAlignment:
|
|
||||||
CrossAxisAlignment.end,
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
BodyLarge(
|
|
||||||
text:
|
|
||||||
'Total Energy \nConsumption',
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
BodyLarge(
|
|
||||||
text: '8623.20 ',
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
|
||||||
BodySmall(text: 'kWh')
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
const Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
PowerClampInfoCard(
|
|
||||||
iconPath:
|
|
||||||
Assets.powerActiveIcon,
|
|
||||||
title: 'Active',
|
|
||||||
value: '700',
|
|
||||||
unit: ' w',
|
|
||||||
),
|
|
||||||
PowerClampInfoCard(
|
|
||||||
iconPath: Assets.voltMeterIcon,
|
|
||||||
title: 'Current',
|
|
||||||
value: '3.06',
|
|
||||||
unit: ' A',
|
|
||||||
),
|
|
||||||
PowerClampInfoCard(
|
|
||||||
iconPath: Assets.frequencyIcon,
|
|
||||||
title: 'Frequency',
|
|
||||||
value: '50',
|
|
||||||
unit: ' Hz',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment:
|
|
||||||
CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
BodyMedium(
|
|
||||||
text: 'Total consumption',
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'10/08/2024',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 8,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.w400),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
BodyMedium(
|
|
||||||
text: '1000.00 ',
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.w700),
|
|
||||||
BodyMedium(
|
|
||||||
text: 'kWh',
|
|
||||||
fontSize: 8,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.w700),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 290,
|
|
||||||
child: EnergyConsumptionPage(
|
|
||||||
chartData: chartData.isNotEmpty
|
|
||||||
? chartData
|
|
||||||
: [
|
|
||||||
EnergyData(
|
|
||||||
'12:00 AM', 4.0),
|
|
||||||
EnergyData(
|
|
||||||
'01:00 AM', 3.5),
|
|
||||||
EnergyData(
|
|
||||||
'02:00 AM', 3.8),
|
|
||||||
EnergyData(
|
|
||||||
'03:00 AM', 3.2),
|
|
||||||
EnergyData(
|
|
||||||
'04:00 AM', 4.0),
|
|
||||||
EnergyData(
|
|
||||||
'05:00 AM', 3.4),
|
|
||||||
EnergyData(
|
|
||||||
'06:00 AM', 3.2),
|
|
||||||
EnergyData(
|
|
||||||
'07:00 AM', 3.5),
|
|
||||||
EnergyData(
|
|
||||||
'08:00 AM', 3.8),
|
|
||||||
EnergyData(
|
|
||||||
'09:00 AM', 3.6),
|
|
||||||
EnergyData(
|
|
||||||
'10:00 AM', 3.9),
|
|
||||||
EnergyData(
|
|
||||||
'11:00 AM', 4.0),
|
|
||||||
],
|
|
||||||
totalConsumption: chartData.fold(
|
|
||||||
0,
|
|
||||||
(sum, data) =>
|
|
||||||
sum + data.consumption),
|
|
||||||
date: '10/08/2024',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 5,
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
DefaultContainer(
|
|
||||||
padding: EdgeInsets.all(0),
|
|
||||||
color: ColorsManager.grayBox,
|
|
||||||
child: SizedBox(
|
|
||||||
child: _blocProvider
|
|
||||||
.dateSwitcher(),
|
|
||||||
)),
|
|
||||||
InkWell(
|
|
||||||
onTap: () {
|
|
||||||
_blocProvider.add(
|
|
||||||
SelectDateEvent(
|
|
||||||
context: context));
|
|
||||||
},
|
|
||||||
child: DefaultContainer(
|
|
||||||
color:
|
|
||||||
ColorsManager.grayBox,
|
|
||||||
child: SizedBox(
|
|
||||||
child: Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets
|
|
||||||
.all(5),
|
|
||||||
child: Text(
|
|
||||||
_blocProvider
|
_blocProvider
|
||||||
.formattedDate),
|
.add(SelectDateEvent(context: context));
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
itemCount: _pageCount,
|
totalFrequencyGeneral: model
|
||||||
),
|
.status.general.dataPoints.isNotEmpty
|
||||||
),
|
? model.status.general.dataPoints[0].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalActiveGeneral:
|
||||||
|
model.status.general.dataPoints.length > 3
|
||||||
|
? model
|
||||||
|
.status.general.dataPoints[3].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalCurrentGeneral:
|
||||||
|
model.status.general.dataPoints.length > 2
|
||||||
|
? model
|
||||||
|
.status.general.dataPoints[2].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalVoltage:
|
||||||
|
model.status.general.dataPoints.length > 1
|
||||||
|
? model
|
||||||
|
.status.general.dataPoints[1].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
chartData: chartData,
|
||||||
|
context: context),
|
||||||
|
powerClampCard(
|
||||||
|
title: 'Phase A Energy \nConsumption',
|
||||||
|
dateSwitcher: _blocProvider.dateSwitcher(),
|
||||||
|
formattedDate: _blocProvider.formattedDate,
|
||||||
|
selectDateEvent: () {
|
||||||
|
_blocProvider
|
||||||
|
.add(SelectDateEvent(context: context));
|
||||||
|
},
|
||||||
|
totalFactor: model
|
||||||
|
.status.phaseA.dataPoints.isNotEmpty
|
||||||
|
? model.status.phaseA.dataPoints[0].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalActive:
|
||||||
|
model.status.phaseA.dataPoints.length > 3
|
||||||
|
? model
|
||||||
|
.status.phaseA.dataPoints[3].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalCurrent:
|
||||||
|
model.status.phaseA.dataPoints.length > 1
|
||||||
|
? model
|
||||||
|
.status.phaseA.dataPoints[1].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalVoltage:
|
||||||
|
model.status.phaseA.dataPoints.length > 0
|
||||||
|
? model
|
||||||
|
.status.phaseA.dataPoints[0].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
chartData: chartData,
|
||||||
|
context: context),
|
||||||
|
powerClampCard(
|
||||||
|
title: 'Phase B Energy \nConsumption',
|
||||||
|
dateSwitcher: _blocProvider.dateSwitcher(),
|
||||||
|
formattedDate: _blocProvider.formattedDate,
|
||||||
|
selectDateEvent: () {
|
||||||
|
_blocProvider
|
||||||
|
.add(SelectDateEvent(context: context));
|
||||||
|
},
|
||||||
|
totalFactor: model
|
||||||
|
.status.phaseB.dataPoints.isNotEmpty
|
||||||
|
? model.status.phaseB.dataPoints[0].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalActive:
|
||||||
|
model.status.phaseB.dataPoints.length > 3
|
||||||
|
? model
|
||||||
|
.status.phaseB.dataPoints[3].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalCurrent:
|
||||||
|
model.status.phaseB.dataPoints.length > 2
|
||||||
|
? model
|
||||||
|
.status.phaseB.dataPoints[2].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalVoltage:
|
||||||
|
model.status.phaseB.dataPoints.length > 1
|
||||||
|
? model
|
||||||
|
.status.phaseB.dataPoints[1].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
chartData: chartData,
|
||||||
|
context: context),
|
||||||
|
powerClampCard(
|
||||||
|
title: 'Phase C Energy \nConsumption',
|
||||||
|
dateSwitcher: _blocProvider.dateSwitcher(),
|
||||||
|
formattedDate: _blocProvider.formattedDate,
|
||||||
|
selectDateEvent: () {
|
||||||
|
_blocProvider
|
||||||
|
.add(SelectDateEvent(context: context));
|
||||||
|
},
|
||||||
|
totalFactor: model
|
||||||
|
.status.phaseC.dataPoints.isNotEmpty
|
||||||
|
? model.status.phaseC.dataPoints[0].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalActive:
|
||||||
|
model.status.phaseC.dataPoints.length > 3
|
||||||
|
? model
|
||||||
|
.status.phaseC.dataPoints[3].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalCurrent:
|
||||||
|
model.status.phaseC.dataPoints.length > 2
|
||||||
|
? model
|
||||||
|
.status.phaseC.dataPoints[2].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
totalVoltage:
|
||||||
|
model.status.phaseC.dataPoints.length > 1
|
||||||
|
? model
|
||||||
|
.status.phaseC.dataPoints[1].value
|
||||||
|
.toString()
|
||||||
|
: 'N/A',
|
||||||
|
chartData: chartData,
|
||||||
|
context: context),
|
||||||
|
]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
@ -277,20 +278,16 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
margin:
|
margin:
|
||||||
const EdgeInsets.symmetric(horizontal: 4.0),
|
const EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
height: 10.0,
|
height: 10.0,
|
||||||
width: _currentPage == index ? 10.0 : 10.0,
|
width: _currentPage == index
|
||||||
|
? 20.0
|
||||||
|
: 10.0, // Change width for current page
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: _currentPage == index
|
color: _currentPage == index
|
||||||
? Colors.grey
|
? Colors
|
||||||
|
.grey // Use a different color for the active indicator
|
||||||
: ColorsManager.greyColor,
|
: ColorsManager.greyColor,
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
),
|
),
|
||||||
child: Center(
|
|
||||||
child: _currentPage == index
|
|
||||||
? Text(
|
|
||||||
'',
|
|
||||||
)
|
|
||||||
: SizedBox.shrink(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@ -302,4 +299,205 @@ class _PowerClampPageState extends State<PowerClampPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefaultContainer powerClampCard(
|
||||||
|
{bool? isGeneral,
|
||||||
|
String? title,
|
||||||
|
String? totalCurrent,
|
||||||
|
String? totalActiveGeneral,
|
||||||
|
String? totalCurrentGeneral,
|
||||||
|
String? totalFrequencyGeneral,
|
||||||
|
String? totalVoltage,
|
||||||
|
String? totalActive,
|
||||||
|
String? totalFrequency,
|
||||||
|
String? totalFactor,
|
||||||
|
Widget? dateSwitcher,
|
||||||
|
String? formattedDate,
|
||||||
|
Function()? selectDateEvent,
|
||||||
|
List<EnergyData>? chartData,
|
||||||
|
BuildContext? context}) {
|
||||||
|
return DefaultContainer(
|
||||||
|
child: Padding(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text('Energy usage'),
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
BodyLarge(
|
||||||
|
text: title!,
|
||||||
|
// 'Total Energy \nConsumption',
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
BodyLarge(
|
||||||
|
text: totalVoltage!,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
BodySmall(text: 'kWh')
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
isGeneral == true
|
||||||
|
? Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.powerActiveIcon,
|
||||||
|
title: 'Active',
|
||||||
|
value: '$totalActiveGeneral',
|
||||||
|
unit: ' w',
|
||||||
|
),
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.voltMeterIcon,
|
||||||
|
title: 'Current',
|
||||||
|
value: '$totalCurrentGeneral',
|
||||||
|
unit: ' A',
|
||||||
|
),
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.frequencyIcon,
|
||||||
|
title: 'Frequency',
|
||||||
|
value: '$totalFrequencyGeneral',
|
||||||
|
unit: ' Hz',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.voltageIcon,
|
||||||
|
title: 'Voltage',
|
||||||
|
value: totalVoltage,
|
||||||
|
unit: ' V',
|
||||||
|
),
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.voltMeterIcon,
|
||||||
|
title: 'Current',
|
||||||
|
value: '$totalCurrent',
|
||||||
|
unit: ' A',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.powerActiveIcon,
|
||||||
|
title: 'Active Power',
|
||||||
|
value: '$totalActive',
|
||||||
|
unit: ' w',
|
||||||
|
),
|
||||||
|
PowerClampInfoCard(
|
||||||
|
iconPath: Assets.speedoMeter,
|
||||||
|
title: 'Power Factor',
|
||||||
|
value: '$totalFactor',
|
||||||
|
unit: '',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
const Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
BodyMedium(
|
||||||
|
text: 'Total consumption',
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'10/08/2024',
|
||||||
|
style:
|
||||||
|
TextStyle(fontSize: 8, fontWeight: FontWeight.w400),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
BodyMedium(
|
||||||
|
text: '1000.00 ',
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w700),
|
||||||
|
BodyMedium(
|
||||||
|
text: 'kWh',
|
||||||
|
fontSize: 8,
|
||||||
|
fontWeight: FontWeight.w700),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 290,
|
||||||
|
child: EnergyConsumptionPage(
|
||||||
|
chartData: chartData!.isNotEmpty
|
||||||
|
? chartData
|
||||||
|
: [
|
||||||
|
EnergyData('12:00 AM', 4.0),
|
||||||
|
EnergyData('01:00 AM', 3.5),
|
||||||
|
EnergyData('02:00 AM', 3.8),
|
||||||
|
EnergyData('03:00 AM', 3.2),
|
||||||
|
EnergyData('04:00 AM', 4.0),
|
||||||
|
EnergyData('05:00 AM', 3.4),
|
||||||
|
EnergyData('06:00 AM', 3.2),
|
||||||
|
EnergyData('07:00 AM', 3.5),
|
||||||
|
EnergyData('08:00 AM', 3.8),
|
||||||
|
EnergyData('09:00 AM', 3.6),
|
||||||
|
EnergyData('10:00 AM', 3.9),
|
||||||
|
EnergyData('11:00 AM', 4.0),
|
||||||
|
],
|
||||||
|
totalConsumption:
|
||||||
|
chartData.fold(0, (sum, data) => sum + data.consumption),
|
||||||
|
date: '10/08/2024',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
DefaultContainer(
|
||||||
|
padding: EdgeInsets.all(0),
|
||||||
|
color: ColorsManager.grayBox,
|
||||||
|
child: SizedBox(
|
||||||
|
child: dateSwitcher,
|
||||||
|
)),
|
||||||
|
InkWell(
|
||||||
|
onTap: selectDateEvent,
|
||||||
|
child: DefaultContainer(
|
||||||
|
color: ColorsManager.grayBox,
|
||||||
|
child: SizedBox(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(5),
|
||||||
|
child: Text(formattedDate!),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,13 +22,13 @@ class PowerClampInfoCard extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(5.0),
|
||||||
child: DefaultContainer(
|
child: DefaultContainer(
|
||||||
height: 60,
|
height: 55,
|
||||||
color: ColorsManager.grayBox,
|
color: ColorsManager.grayBox,
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
@ -40,6 +40,7 @@ class PowerClampInfoCard extends StatelessWidget {
|
|||||||
flex: 3,
|
flex: 3,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
BodyMedium(
|
BodyMedium(
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
@ -47,7 +48,7 @@ class PowerClampInfoCard extends StatelessWidget {
|
|||||||
text: title,
|
text: title,
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
BodyMedium(
|
BodyMedium(
|
||||||
|
|||||||
@ -1086,7 +1086,8 @@ class Assets {
|
|||||||
static const String voltMeterIcon = "assets/icons/volt_meter_icon.svg";
|
static const String voltMeterIcon = "assets/icons/volt_meter_icon.svg";
|
||||||
static const String powerActiveIcon = "assets/icons/power_active_icon.svg";
|
static const String powerActiveIcon = "assets/icons/power_active_icon.svg";
|
||||||
static const String searchIcon = "assets/icons/search_icon.svg";
|
static const String searchIcon = "assets/icons/search_icon.svg";
|
||||||
|
static const String voltageIcon = "assets/icons/voltage_icon.svg";
|
||||||
|
static const String speedoMeter = "assets/icons/speedo_meter.svg";
|
||||||
|
|
||||||
|
//speedo_meter
|
||||||
//leakNormalIcon
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,8 +105,8 @@ abstract class ApiEndpoints {
|
|||||||
static const String deviceByUuid = '/device/{deviceUuid}';
|
static const String deviceByUuid = '/device/{deviceUuid}';
|
||||||
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
||||||
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
||||||
static const String deviceFunctionsStatus =
|
static const String deviceFunctionsStatus = '/device/{deviceUuid}/functions/status';
|
||||||
'/device/{deviceUuid}/functions/status';
|
static const String powerClamp = '/device/{powerClampUuid}/power-clamp/status';
|
||||||
|
|
||||||
///Device Permission Module
|
///Device Permission Module
|
||||||
//POST
|
//POST
|
||||||
|
|||||||
@ -80,6 +80,18 @@ class DevicesAPI {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<Map<String, dynamic>> getPowerClampStatus(
|
||||||
|
String deviceId) async {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: ApiEndpoints.powerClamp.replaceAll('{powerClampUuid}', deviceId),
|
||||||
|
showServerMessage: false,
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
return json;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<Map<String, dynamic>> renamePass(
|
static Future<Map<String, dynamic>> renamePass(
|
||||||
{required String name,
|
{required String name,
|
||||||
required String doorLockUuid,
|
required String doorLockUuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user