mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 20:04:56 +00:00
Compare commits
1 Commits
fix-schedu
...
SP-1707-fe
| Author | SHA1 | Date | |
|---|---|---|---|
| 818bdee745 |
@ -39,12 +39,8 @@ class AnalyticsDevice {
|
|||||||
? ProductDevice.fromJson(json['productDevice'] as Map<String, dynamic>)
|
? ProductDevice.fromJson(json['productDevice'] as Map<String, dynamic>)
|
||||||
: null,
|
: null,
|
||||||
spaceUuid: json['spaceUuid'] as String?,
|
spaceUuid: json['spaceUuid'] as String?,
|
||||||
latitude: json['lat'] != null && json['lat'] != ''
|
latitude: json['lat'] != null ? double.parse(json['lat'] as String? ?? '0.0') : null,
|
||||||
? double.tryParse(json['lat']?.toString() ?? '0.0')
|
longitude: json['lon'] != null ? double.parse(json['lon'] as String? ?? '0.0') : null,
|
||||||
: null,
|
|
||||||
longitude: json['lon'] != null && json['lon'] != ''
|
|
||||||
? double.tryParse(json['lon']?.toString() ?? '0.0')
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,11 +46,11 @@ class AirQualityDistributionBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onClearAirQualityDistribution(
|
Future<void> _onClearAirQualityDistribution(
|
||||||
ClearAirQualityDistribution event,
|
ClearAirQualityDistribution event,
|
||||||
Emitter<AirQualityDistributionState> emit,
|
Emitter<AirQualityDistributionState> emit,
|
||||||
) {
|
) async {
|
||||||
emit(AirQualityDistributionState(selectedAqiType: state.selectedAqiType));
|
emit(const AirQualityDistributionState());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateAqiTypeEvent(
|
void _onUpdateAqiTypeEvent(
|
||||||
|
|||||||
@ -75,6 +75,6 @@ class RangeOfAqiBloc extends Bloc<RangeOfAqiEvent, RangeOfAqiState> {
|
|||||||
ClearRangeOfAqiEvent event,
|
ClearRangeOfAqiEvent event,
|
||||||
Emitter<RangeOfAqiState> emit,
|
Emitter<RangeOfAqiState> emit,
|
||||||
) {
|
) {
|
||||||
emit(RangeOfAqiState(selectedAqiType: state.selectedAqiType));
|
emit(const RangeOfAqiState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,6 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
alignment: AlignmentDirectional.centerEnd,
|
alignment: AlignmentDirectional.centerEnd,
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
child: AqiTypeDropdown(
|
child: AqiTypeDropdown(
|
||||||
selectedAqiType: context.watch<AirQualityDistributionBloc>().state.selectedAqiType,
|
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
final bloc = context.read<AirQualityDistributionBloc>();
|
final bloc = context.read<AirQualityDistributionBloc>();
|
||||||
|
|||||||
@ -18,20 +18,19 @@ enum AqiType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AqiTypeDropdown extends StatefulWidget {
|
class AqiTypeDropdown extends StatefulWidget {
|
||||||
const AqiTypeDropdown({
|
const AqiTypeDropdown({super.key, required this.onChanged});
|
||||||
required this.onChanged,
|
|
||||||
this.selectedAqiType,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
final ValueChanged<AqiType?> onChanged;
|
final ValueChanged<AqiType?> onChanged;
|
||||||
final AqiType? selectedAqiType;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AqiTypeDropdown> createState() => _AqiTypeDropdownState();
|
State<AqiTypeDropdown> createState() => _AqiTypeDropdownState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AqiTypeDropdownState extends State<AqiTypeDropdown> {
|
class _AqiTypeDropdownState extends State<AqiTypeDropdown> {
|
||||||
|
AqiType? _selectedItem = AqiType.aqi;
|
||||||
|
|
||||||
|
void _updateSelectedItem(AqiType? item) => setState(() => _selectedItem = item);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@ -42,8 +41,8 @@ class _AqiTypeDropdownState extends State<AqiTypeDropdown> {
|
|||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: DropdownButton<AqiType>(
|
child: DropdownButton<AqiType?>(
|
||||||
value: widget.selectedAqiType,
|
value: _selectedItem,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
dropdownColor: ColorsManager.whiteColors,
|
dropdownColor: ColorsManager.whiteColors,
|
||||||
@ -60,7 +59,10 @@ class _AqiTypeDropdownState extends State<AqiTypeDropdown> {
|
|||||||
items: AqiType.values
|
items: AqiType.values
|
||||||
.map((e) => DropdownMenuItem(value: e, child: Text(e.value)))
|
.map((e) => DropdownMenuItem(value: e, child: Text(e.value)))
|
||||||
.toList(),
|
.toList(),
|
||||||
onChanged: widget.onChanged,
|
onChanged: (value) {
|
||||||
|
_updateSelectedItem(value);
|
||||||
|
widget.onChanged(value);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,15 +63,15 @@ class RangeOfAqiChartTitle extends StatelessWidget {
|
|||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
alignment: AlignmentDirectional.centerEnd,
|
alignment: AlignmentDirectional.centerEnd,
|
||||||
child: AqiTypeDropdown(
|
child: AqiTypeDropdown(
|
||||||
selectedAqiType: context.watch<RangeOfAqiBloc>().state.selectedAqiType,
|
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
||||||
final spaceUuid = spaceTreeState.selectedSpaces.firstOrNull;
|
final spaceUuid = spaceTreeState.selectedSpaces.firstOrNull;
|
||||||
|
|
||||||
|
if (spaceUuid == null) return;
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
context.read<RangeOfAqiBloc>().add(UpdateAqiTypeEvent(value));
|
context.read<RangeOfAqiBloc>().add(UpdateAqiTypeEvent(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spaceUuid == null) return;
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -17,8 +17,8 @@ class DeviceLocationDetailsServiceDecorator implements DeviceLocationService {
|
|||||||
'reverse',
|
'reverse',
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'format': 'json',
|
'format': 'json',
|
||||||
'lat': 25.1880567,
|
'lat': param.latitude,
|
||||||
'lon': 55.266608,
|
'lon': param.longitude,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -16,12 +16,11 @@ class DeviceManagementBloc
|
|||||||
int _onlineCount = 0;
|
int _onlineCount = 0;
|
||||||
int _offlineCount = 0;
|
int _offlineCount = 0;
|
||||||
int _lowBatteryCount = 0;
|
int _lowBatteryCount = 0;
|
||||||
final List<AllDevicesModel> _selectedDevices = [];
|
List<AllDevicesModel> _selectedDevices = [];
|
||||||
List<AllDevicesModel> _filteredDevices = [];
|
List<AllDevicesModel> _filteredDevices = [];
|
||||||
String currentProductName = '';
|
String currentProductName = '';
|
||||||
String? currentCommunity;
|
String? currentCommunity;
|
||||||
String? currentUnitName;
|
String? currentUnitName;
|
||||||
String subSpaceName = '';
|
|
||||||
|
|
||||||
DeviceManagementBloc() : super(DeviceManagementInitial()) {
|
DeviceManagementBloc() : super(DeviceManagementInitial()) {
|
||||||
on<FetchDevices>(_onFetchDevices);
|
on<FetchDevices>(_onFetchDevices);
|
||||||
@ -32,29 +31,24 @@ class DeviceManagementBloc
|
|||||||
on<ResetFilters>(_onResetFilters);
|
on<ResetFilters>(_onResetFilters);
|
||||||
on<ResetSelectedDevices>(_onResetSelectedDevices);
|
on<ResetSelectedDevices>(_onResetSelectedDevices);
|
||||||
on<UpdateSelection>(_onUpdateSelection);
|
on<UpdateSelection>(_onUpdateSelection);
|
||||||
on<UpdateDeviceName>(_onUpdateDeviceName);
|
|
||||||
on<UpdateSubSpaceName>(_onUpdateSubSpaceName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFetchDevices(
|
Future<void> _onFetchDevices(
|
||||||
FetchDevices event, Emitter<DeviceManagementState> emit) async {
|
FetchDevices event, Emitter<DeviceManagementState> emit) async {
|
||||||
emit(DeviceManagementLoading());
|
emit(DeviceManagementLoading());
|
||||||
try {
|
try {
|
||||||
var devices = <AllDevicesModel>[];
|
List<AllDevicesModel> devices = [];
|
||||||
_devices.clear();
|
_devices.clear();
|
||||||
final spaceBloc = event.context.read<SpaceTreeBloc>();
|
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||||
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
devices = await DevicesManagementApi().fetchDevices(projectUuid);
|
||||||
} else {
|
} else {
|
||||||
for (final community in spaceBloc.state.selectedCommunities) {
|
for (var community in spaceBloc.state.selectedCommunities) {
|
||||||
final spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||||
for (final space in spacesList) {
|
|
||||||
devices.addAll(await DevicesManagementApi()
|
devices.addAll(await DevicesManagementApi()
|
||||||
.fetchDevices(community, space, projectUuid));
|
.fetchDevices(projectUuid, spacesId: spacesList));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +70,7 @@ class DeviceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFilterDevices(
|
void _onFilterDevices(
|
||||||
FilterDevices event, Emitter<DeviceManagementState> emit) async {
|
FilterDevices event, Emitter<DeviceManagementState> emit) async {
|
||||||
if (_devices.isNotEmpty) {
|
if (_devices.isNotEmpty) {
|
||||||
_filteredDevices = List.from(_devices.where((device) {
|
_filteredDevices = List.from(_devices.where((device) {
|
||||||
@ -158,7 +152,8 @@ class DeviceManagementBloc
|
|||||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSelectDevice(SelectDevice event, Emitter<DeviceManagementState> emit) {
|
void _onSelectDevice(
|
||||||
|
SelectDevice event, Emitter<DeviceManagementState> emit) {
|
||||||
final selectedUuid = event.selectedDevice.uuid;
|
final selectedUuid = event.selectedDevice.uuid;
|
||||||
|
|
||||||
if (_selectedDevices.any((device) => device.uuid == selectedUuid)) {
|
if (_selectedDevices.any((device) => device.uuid == selectedUuid)) {
|
||||||
@ -167,9 +162,9 @@ class DeviceManagementBloc
|
|||||||
_selectedDevices.add(event.selectedDevice);
|
_selectedDevices.add(event.selectedDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
final clonedSelectedDevices = List<AllDevicesModel>.from(_selectedDevices);
|
List<AllDevicesModel> clonedSelectedDevices = List.from(_selectedDevices);
|
||||||
|
|
||||||
final isControlButtonEnabled =
|
bool isControlButtonEnabled =
|
||||||
_checkIfControlButtonEnabled(clonedSelectedDevices);
|
_checkIfControlButtonEnabled(clonedSelectedDevices);
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
if (state is DeviceManagementLoaded) {
|
||||||
@ -199,8 +194,8 @@ class DeviceManagementBloc
|
|||||||
|
|
||||||
void _onUpdateSelection(
|
void _onUpdateSelection(
|
||||||
UpdateSelection event, Emitter<DeviceManagementState> emit) {
|
UpdateSelection event, Emitter<DeviceManagementState> emit) {
|
||||||
final selectedDevices = <AllDevicesModel>[];
|
List<AllDevicesModel> selectedDevices = [];
|
||||||
var devicesToSelectFrom = <AllDevicesModel>[];
|
List<AllDevicesModel> devicesToSelectFrom = [];
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
if (state is DeviceManagementLoaded) {
|
||||||
devicesToSelectFrom = (state as DeviceManagementLoaded).devices;
|
devicesToSelectFrom = (state as DeviceManagementLoaded).devices;
|
||||||
@ -208,7 +203,7 @@ class DeviceManagementBloc
|
|||||||
devicesToSelectFrom = (state as DeviceManagementFiltered).filteredDevices;
|
devicesToSelectFrom = (state as DeviceManagementFiltered).filteredDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < event.selectedRows.length; i++) {
|
for (int i = 0; i < event.selectedRows.length; i++) {
|
||||||
if (event.selectedRows[i]) {
|
if (event.selectedRows[i]) {
|
||||||
selectedDevices.add(devicesToSelectFrom[i]);
|
selectedDevices.add(devicesToSelectFrom[i]);
|
||||||
}
|
}
|
||||||
@ -254,7 +249,8 @@ class DeviceManagementBloc
|
|||||||
_onlineCount = _devices.where((device) => device.online == true).length;
|
_onlineCount = _devices.where((device) => device.online == true).length;
|
||||||
_offlineCount = _devices.where((device) => device.online == false).length;
|
_offlineCount = _devices.where((device) => device.online == false).length;
|
||||||
_lowBatteryCount = _devices
|
_lowBatteryCount = _devices
|
||||||
.where((device) => device.batteryLevel != null && device.batteryLevel! < 20)
|
.where((device) =>
|
||||||
|
device.batteryLevel != null && device.batteryLevel! < 20)
|
||||||
.length;
|
.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +267,8 @@ class DeviceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSearchDevices(SearchDevices event, Emitter<DeviceManagementState> emit) {
|
void _onSearchDevices(
|
||||||
|
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||||
if ((event.community == null || event.community!.isEmpty) &&
|
if ((event.community == null || event.community!.isEmpty) &&
|
||||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||||
(event.deviceNameOrProductName == null ||
|
(event.deviceNameOrProductName == null ||
|
||||||
@ -300,7 +297,7 @@ class DeviceManagementBloc
|
|||||||
currentCommunity = event.community;
|
currentCommunity = event.community;
|
||||||
currentUnitName = event.unitName;
|
currentUnitName = event.unitName;
|
||||||
|
|
||||||
final devicesToSearch = _devices;
|
List<AllDevicesModel> devicesToSearch = _devices;
|
||||||
|
|
||||||
if (devicesToSearch.isNotEmpty) {
|
if (devicesToSearch.isNotEmpty) {
|
||||||
final searchText = event.deviceNameOrProductName?.toLowerCase() ?? '';
|
final searchText = event.deviceNameOrProductName?.toLowerCase() ?? '';
|
||||||
@ -343,134 +340,5 @@ class DeviceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateDeviceName(
|
|
||||||
UpdateDeviceName event, Emitter<DeviceManagementState> emit) {
|
|
||||||
final devices = _devices.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
final modifiedDevice = device.copyWith(name: event.newName);
|
|
||||||
_selectedDevices.removeWhere((device) => device.uuid == event.deviceId);
|
|
||||||
_selectedDevices.add(modifiedDevice);
|
|
||||||
return modifiedDevice;
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
final filteredDevices = _filteredDevices.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
final modifiedDevice = device.copyWith(name: event.newName);
|
|
||||||
_selectedDevices.removeWhere((device) => device.uuid == event.deviceId);
|
|
||||||
_selectedDevices.add(modifiedDevice);
|
|
||||||
return modifiedDevice;
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
_devices = devices;
|
|
||||||
_filteredDevices = filteredDevices;
|
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
|
||||||
final loaded = state as DeviceManagementLoaded;
|
|
||||||
final selectedDevices01 = _selectedDevices.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
final modifiedDevice = device.copyWith(name: event.newName);
|
|
||||||
return modifiedDevice;
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
emit(DeviceManagementLoaded(
|
|
||||||
devices: devices,
|
|
||||||
selectedIndex: loaded.selectedIndex,
|
|
||||||
onlineCount: loaded.onlineCount,
|
|
||||||
offlineCount: loaded.offlineCount,
|
|
||||||
lowBatteryCount: loaded.lowBatteryCount,
|
|
||||||
selectedDevice: selectedDevices01,
|
|
||||||
isControlButtonEnabled: loaded.isControlButtonEnabled,
|
|
||||||
));
|
|
||||||
} else if (state is DeviceManagementFiltered) {
|
|
||||||
final filtered = state as DeviceManagementFiltered;
|
|
||||||
final selectedDevices01 = filtered.selectedDevice?.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
final modifiedDevice = device.copyWith(name: event.newName);
|
|
||||||
return modifiedDevice;
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
emit(DeviceManagementFiltered(
|
|
||||||
filteredDevices: filteredDevices,
|
|
||||||
selectedIndex: filtered.selectedIndex,
|
|
||||||
onlineCount: filtered.onlineCount,
|
|
||||||
offlineCount: filtered.offlineCount,
|
|
||||||
lowBatteryCount: filtered.lowBatteryCount,
|
|
||||||
selectedDevice: selectedDevices01,
|
|
||||||
isControlButtonEnabled: filtered.isControlButtonEnabled,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onUpdateSubSpaceName(
|
|
||||||
UpdateSubSpaceName event, Emitter<DeviceManagementState> emit) {
|
|
||||||
final devices = _devices.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
return device.copyWith(
|
|
||||||
subspace:
|
|
||||||
device.subspace?.copyWith(subspaceName: event.newSubSpaceName));
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
final filteredDevices = _filteredDevices.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
return device.copyWith(
|
|
||||||
subspace:
|
|
||||||
device.subspace?.copyWith(subspaceName: event.newSubSpaceName));
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
_devices = devices;
|
|
||||||
_filteredDevices = filteredDevices;
|
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
|
||||||
final loaded = state as DeviceManagementLoaded;
|
|
||||||
final selectedDevices = loaded.selectedDevice?.map((device) {
|
|
||||||
if (device.uuid == event.deviceId) {
|
|
||||||
return device.copyWith(
|
|
||||||
subspace:
|
|
||||||
device.subspace?.copyWith(subspaceName: event.newSubSpaceName));
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}).toList();
|
|
||||||
emit(DeviceManagementLoaded(
|
|
||||||
devices: _devices,
|
|
||||||
selectedIndex: loaded.selectedIndex,
|
|
||||||
onlineCount: loaded.onlineCount,
|
|
||||||
offlineCount: loaded.offlineCount,
|
|
||||||
lowBatteryCount: loaded.lowBatteryCount,
|
|
||||||
selectedDevice: selectedDevices,
|
|
||||||
isControlButtonEnabled: loaded.isControlButtonEnabled,
|
|
||||||
));
|
|
||||||
} else if (state is DeviceManagementFiltered) {
|
|
||||||
// final filtered = state as DeviceManagementFiltered;
|
|
||||||
// emit(DeviceManagementFiltered(
|
|
||||||
// filteredDevices: _filteredDevices,
|
|
||||||
// selectedIndex: filtered.selectedIndex,
|
|
||||||
// onlineCount: filtered.onlineCount,
|
|
||||||
// offlineCount: filtered.offlineCount,
|
|
||||||
// lowBatteryCount: filtered.lowBatteryCount,
|
|
||||||
// selectedDevice: filtered.selectedDevice,
|
|
||||||
// isControlButtonEnabled: filtered.isControlButtonEnabled,
|
|
||||||
// ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void changeSubspaceName(
|
|
||||||
String deviceId, String newSubSpaceName, String subspaceId) {
|
|
||||||
add(UpdateSubSpaceName(
|
|
||||||
deviceId: deviceId,
|
|
||||||
newSubSpaceName: newSubSpaceName,
|
|
||||||
subspaceId: subspaceId,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AllDevicesModel> get selectedDevices => _selectedDevices;
|
List<AllDevicesModel> get selectedDevices => _selectedDevices;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,21 +70,3 @@ class UpdateSelection extends DeviceManagementEvent {
|
|||||||
|
|
||||||
const UpdateSelection(this.selectedRows);
|
const UpdateSelection(this.selectedRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateDeviceName extends DeviceManagementEvent {
|
|
||||||
final String deviceId;
|
|
||||||
final String newName;
|
|
||||||
|
|
||||||
const UpdateDeviceName({required this.deviceId, required this.newName});
|
|
||||||
}
|
|
||||||
|
|
||||||
class UpdateSubSpaceName extends DeviceManagementEvent {
|
|
||||||
final String deviceId;
|
|
||||||
final String newSubSpaceName;
|
|
||||||
final String subspaceId;
|
|
||||||
|
|
||||||
const UpdateSubSpaceName(
|
|
||||||
{required this.deviceId,
|
|
||||||
required this.newSubSpaceName,
|
|
||||||
required this.subspaceId});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -60,13 +60,4 @@ class Status {
|
|||||||
factory Status.fromJson(String source) => Status.fromMap(json.decode(source));
|
factory Status.fromJson(String source) => Status.fromMap(json.decode(source));
|
||||||
|
|
||||||
String toJson() => json.encode(toMap());
|
String toJson() => json.encode(toMap());
|
||||||
Status copyWith({
|
|
||||||
String? code,
|
|
||||||
dynamic value,
|
|
||||||
}) {
|
|
||||||
return Status(
|
|
||||||
code: code ?? this.code,
|
|
||||||
value: value ?? this.value,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,20 +44,4 @@ class DeviceSubspace {
|
|||||||
static List<Map<String, dynamic>> listToJson(List<DeviceSubspace> subspaces) {
|
static List<Map<String, dynamic>> listToJson(List<DeviceSubspace> subspaces) {
|
||||||
return subspaces.map((subspace) => subspace.toJson()).toList();
|
return subspaces.map((subspace) => subspace.toJson()).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceSubspace copyWith({
|
|
||||||
String? uuid,
|
|
||||||
DateTime? createdAt,
|
|
||||||
DateTime? updatedAt,
|
|
||||||
String? subspaceName,
|
|
||||||
bool? disabled,
|
|
||||||
}) {
|
|
||||||
return DeviceSubspace(
|
|
||||||
uuid: uuid ?? this.uuid,
|
|
||||||
createdAt: createdAt ?? this.createdAt,
|
|
||||||
updatedAt: updatedAt ?? this.updatedAt,
|
|
||||||
subspaceName: subspaceName ?? this.subspaceName,
|
|
||||||
disabled: disabled ?? this.disabled,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -588,72 +588,4 @@ SOS
|
|||||||
"NCPS": DeviceType.NCPS,
|
"NCPS": DeviceType.NCPS,
|
||||||
"PC": DeviceType.PC,
|
"PC": DeviceType.PC,
|
||||||
};
|
};
|
||||||
|
|
||||||
AllDevicesModel copyWith({
|
|
||||||
DevicesModelRoom? room,
|
|
||||||
DeviceSubspace? subspace,
|
|
||||||
DevicesModelUnit? unit,
|
|
||||||
DeviceCommunityModel? community,
|
|
||||||
String? productUuid,
|
|
||||||
String? productType,
|
|
||||||
String? permissionType,
|
|
||||||
int? activeTime,
|
|
||||||
String? category,
|
|
||||||
String? categoryName,
|
|
||||||
int? createTime,
|
|
||||||
String? gatewayId,
|
|
||||||
String? icon,
|
|
||||||
String? ip,
|
|
||||||
String? lat,
|
|
||||||
String? localKey,
|
|
||||||
String? lon,
|
|
||||||
String? model,
|
|
||||||
String? name,
|
|
||||||
String? nodeId,
|
|
||||||
bool? online,
|
|
||||||
String? ownerId,
|
|
||||||
bool? sub,
|
|
||||||
String? timeZone,
|
|
||||||
int? updateTime,
|
|
||||||
String? uuid,
|
|
||||||
int? batteryLevel,
|
|
||||||
String? productName,
|
|
||||||
List<DeviceSpaceModel>? spaces,
|
|
||||||
List<DeviceTagModel>? deviceTags,
|
|
||||||
DeviceSubSpace? deviceSubSpace,
|
|
||||||
}) {
|
|
||||||
return AllDevicesModel(
|
|
||||||
room: room ?? this.room,
|
|
||||||
subspace: subspace ?? this.subspace,
|
|
||||||
unit: unit ?? this.unit,
|
|
||||||
community: community ?? this.community,
|
|
||||||
productUuid: productUuid ?? this.productUuid,
|
|
||||||
productType: productType ?? this.productType,
|
|
||||||
permissionType: permissionType ?? this.permissionType,
|
|
||||||
activeTime: activeTime ?? this.activeTime,
|
|
||||||
category: category ?? this.category,
|
|
||||||
categoryName: categoryName ?? this.categoryName,
|
|
||||||
createTime: createTime ?? this.createTime,
|
|
||||||
gatewayId: gatewayId ?? this.gatewayId,
|
|
||||||
icon: icon ?? this.icon,
|
|
||||||
ip: ip ?? this.ip,
|
|
||||||
lat: lat ?? this.lat,
|
|
||||||
localKey: localKey ?? this.localKey,
|
|
||||||
lon: lon ?? this.lon,
|
|
||||||
model: model ?? this.model,
|
|
||||||
name: name ?? this.name,
|
|
||||||
nodeId: nodeId ?? this.nodeId,
|
|
||||||
online: online ?? this.online,
|
|
||||||
ownerId: ownerId ?? this.ownerId,
|
|
||||||
sub: sub ?? this.sub,
|
|
||||||
timeZone: timeZone ?? this.timeZone,
|
|
||||||
updateTime: updateTime ?? this.updateTime,
|
|
||||||
uuid: uuid ?? this.uuid,
|
|
||||||
batteryLevel: batteryLevel ?? this.batteryLevel,
|
|
||||||
productName: productName ?? this.productName,
|
|
||||||
spaces: spaces ?? this.spaces,
|
|
||||||
deviceTags: deviceTags ?? this.deviceTags,
|
|
||||||
deviceSubSpace: deviceSubSpace ?? this.deviceSubSpace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,6 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
||||||
buildWhen: (previous, current) => previous != current,
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
List<AllDevicesModel> devicesToShow = [];
|
List<AllDevicesModel> devicesToShow = [];
|
||||||
int selectedIndex = 0;
|
int selectedIndex = 0;
|
||||||
@ -32,6 +31,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
int lowBatteryCount = 0;
|
int lowBatteryCount = 0;
|
||||||
bool isControlButtonEnabled = false;
|
bool isControlButtonEnabled = false;
|
||||||
List<AllDevicesModel> selectedDevices = [];
|
List<AllDevicesModel> selectedDevices = [];
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
if (state is DeviceManagementLoaded) {
|
||||||
devicesToShow = state.devices;
|
devicesToShow = state.devices;
|
||||||
selectedIndex = state.selectedIndex;
|
selectedIndex = state.selectedIndex;
|
||||||
@ -111,8 +111,6 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
onPressed: isControlButtonEnabled
|
onPressed: isControlButtonEnabled
|
||||||
? () {
|
? () {
|
||||||
if (isAnyDeviceOffline) {
|
if (isAnyDeviceOffline) {
|
||||||
ScaffoldMessenger.of(context)
|
|
||||||
.clearSnackBars();
|
|
||||||
ScaffoldMessenger.of(context)
|
ScaffoldMessenger.of(context)
|
||||||
.showSnackBar(
|
.showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
@ -192,7 +190,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
'Product Name',
|
'Product Name',
|
||||||
'Device ID',
|
'Device ID',
|
||||||
'Space Name',
|
'Space Name',
|
||||||
'Location',
|
'location',
|
||||||
'Battery Level',
|
'Battery Level',
|
||||||
'Installation Date and Time',
|
'Installation Date and Time',
|
||||||
'Status',
|
'Status',
|
||||||
@ -244,7 +242,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
.map((device) => device.uuid!)
|
.map((device) => device.uuid!)
|
||||||
.toList(),
|
.toList(),
|
||||||
isEmpty: devicesToShow.isEmpty,
|
isEmpty: devicesToShow.isEmpty,
|
||||||
onSettingsPressed: (rowIndex) async {
|
onSettingsPressed: (rowIndex) {
|
||||||
final device = devicesToShow[rowIndex];
|
final device = devicesToShow[rowIndex];
|
||||||
showDeviceSettingsSidebar(context, device);
|
showDeviceSettingsSidebar(context, device);
|
||||||
},
|
},
|
||||||
@ -266,7 +264,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
barrierLabel: "Device Settings",
|
barrierLabel: "Device Settings",
|
||||||
transitionDuration: const Duration(milliseconds: 300),
|
transitionDuration: const Duration(milliseconds: 300),
|
||||||
pageBuilder: (_, anim1, anim2) {
|
pageBuilder: (context, anim1, anim2) {
|
||||||
return Align(
|
return Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: Material(
|
child: Material(
|
||||||
@ -276,7 +274,6 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
child: DeviceSettingsPanel(
|
child: DeviceSettingsPanel(
|
||||||
device: device,
|
device: device,
|
||||||
onClose: () => Navigator.of(context).pop(),
|
onClose: () => Navigator.of(context).pop(),
|
||||||
deviceManagementBloc: context.read<DeviceManagementBloc>(),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -62,10 +62,9 @@ class CurtainModuleItems extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
BlocProvider.of<CurtainModuleBloc>(context),
|
BlocProvider.of<CurtainModuleBloc>(context),
|
||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'timer',
|
category: 'CUR_2',
|
||||||
code: 'control',
|
code: 'control',
|
||||||
countdownCode: 'timer',
|
|
||||||
deviceType: 'CUR_2',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -17,6 +17,7 @@ class CalibrateCompletedDialog extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(_) {
|
Widget build(_) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: 250,
|
height: 250,
|
||||||
|
|||||||
@ -19,14 +19,11 @@ class DeviceManagementContent extends StatelessWidget {
|
|||||||
required this.device,
|
required this.device,
|
||||||
required this.subSpaces,
|
required this.subSpaces,
|
||||||
required this.deviceInfo,
|
required this.deviceInfo,
|
||||||
required this.deviceManagementBloc,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final AllDevicesModel device;
|
final AllDevicesModel device;
|
||||||
final List<SubSpaceModel> subSpaces;
|
final List<SubSpaceModel> subSpaces;
|
||||||
final DeviceInfoModel deviceInfo;
|
final DeviceInfoModel deviceInfo;
|
||||||
final DeviceManagementBloc deviceManagementBloc;
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -90,11 +87,6 @@ class DeviceManagementContent extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceManagementBloc.add(UpdateSubSpaceName(
|
|
||||||
subspaceId: selectedSubSpace.id!,
|
|
||||||
deviceId: device.uuid!,
|
|
||||||
newSubSpaceName: selectedSubSpace.name ?? ''));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: infoRow(
|
child: infoRow(
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/device_icon_type_helper.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/device_icon_type_helper.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/device_management_content.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/device_management_content.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/remove_device_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/remove_device_widget.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
@ -19,13 +17,7 @@ import 'package:syncrow_web/web_layout/default_container.dart';
|
|||||||
class DeviceSettingsPanel extends StatelessWidget {
|
class DeviceSettingsPanel extends StatelessWidget {
|
||||||
final VoidCallback? onClose;
|
final VoidCallback? onClose;
|
||||||
final AllDevicesModel device;
|
final AllDevicesModel device;
|
||||||
final DeviceManagementBloc deviceManagementBloc;
|
const DeviceSettingsPanel({super.key, this.onClose, required this.device});
|
||||||
const DeviceSettingsPanel({
|
|
||||||
super.key,
|
|
||||||
this.onClose,
|
|
||||||
required this.device,
|
|
||||||
required this.deviceManagementBloc,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -142,14 +134,8 @@ class DeviceSettingsPanel extends StatelessWidget {
|
|||||||
onFieldSubmitted: (value) {
|
onFieldSubmitted: (value) {
|
||||||
_bloc.add(const ChangeNameEvent(
|
_bloc.add(const ChangeNameEvent(
|
||||||
value: false));
|
value: false));
|
||||||
deviceManagementBloc
|
|
||||||
..add(UpdateDeviceName(
|
|
||||||
deviceId: device.uuid!,
|
|
||||||
newName: _bloc
|
|
||||||
.nameController
|
|
||||||
.text))..add(ResetSelectedDevices());
|
|
||||||
},
|
},
|
||||||
decoration:const InputDecoration(
|
decoration: InputDecoration(
|
||||||
isDense: true,
|
isDense: true,
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
@ -204,7 +190,6 @@ class DeviceSettingsPanel extends StatelessWidget {
|
|||||||
device: device,
|
device: device,
|
||||||
subSpaces: subSpaces.cast<SubSpaceModel>(),
|
subSpaces: subSpaces.cast<SubSpaceModel>(),
|
||||||
deviceInfo: deviceInfo,
|
deviceInfo: deviceInfo,
|
||||||
deviceManagementBloc: deviceManagementBloc,
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
RemoveDeviceWidget(bloc: _bloc),
|
RemoveDeviceWidget(bloc: _bloc),
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class OneGangGlassSwitchBloc
|
|||||||
emit(OneGangGlassSwitchLoading());
|
emit(OneGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
_listenToChanges(event.deviceId);
|
_listenToChanges(event.deviceId, emit);
|
||||||
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||||
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -48,28 +48,42 @@ class OneGangGlassSwitchBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription<DatabaseEvent>? _deviceStatusSubscription;
|
void _listenToChanges(
|
||||||
|
String deviceId,
|
||||||
void _listenToChanges(String deviceId) {
|
Emitter<OneGangGlassSwitchState> emit,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
_deviceStatusSubscription = ref.onValue.listen((DatabaseEvent event) async {
|
final stream = ref.onValue;
|
||||||
if (event.snapshot.value == null) return;
|
|
||||||
|
|
||||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
stream.listen((DatabaseEvent event) {
|
||||||
|
final data = event.snapshot.value as Map<dynamic, dynamic>?;
|
||||||
|
if (data == null) return;
|
||||||
|
|
||||||
final statusList = <Status>[];
|
final statusList = <Status>[];
|
||||||
|
if (data['status'] != null) {
|
||||||
usersMap['status'].forEach((element) {
|
for (var element in data['status']) {
|
||||||
statusList.add(Status(code: element['code'], value: element['value']));
|
statusList.add(
|
||||||
});
|
Status(
|
||||||
|
code: element['code'].toString(),
|
||||||
deviceStatus =
|
value: element['value'].toString(),
|
||||||
OneGangGlassStatusModel.fromJson(usersMap['productUuid'], statusList);
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (statusList.isNotEmpty) {
|
||||||
|
final newStatus = OneGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||||
|
if (newStatus != deviceStatus) {
|
||||||
|
deviceStatus = newStatus;
|
||||||
|
if (!isClosed) {
|
||||||
add(StatusUpdated(deviceStatus));
|
add(StatusUpdated(deviceStatus));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (e) {
|
||||||
|
emit(OneGangGlassSwitchError('Failed to listen to changes: $e'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onStatusUpdated(
|
void _onStatusUpdated(
|
||||||
@ -160,10 +174,4 @@ class OneGangGlassSwitchBloc
|
|||||||
deviceStatus = deviceStatus.copyWith(switch1: value);
|
deviceStatus = deviceStatus.copyWith(switch1: value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() {
|
|
||||||
_deviceStatusSubscription?.cancel();
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,8 +90,6 @@ class OneGangGlassSwitchControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: '1GT',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -80,8 +80,6 @@ class WallLightDeviceControl extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: '1G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -47,7 +47,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
final success = await RemoteControlDeviceService().controlDevice(
|
final success = await RemoteControlDeviceService().controlDevice(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
status: Status(
|
status: Status(
|
||||||
code: event.countdownCode,
|
code: 'countdown_1',
|
||||||
value: 0,
|
value: 0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -80,18 +80,15 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
) {
|
) {
|
||||||
if (state is ScheduleLoaded) {
|
if (state is ScheduleLoaded) {
|
||||||
final currentState = state as ScheduleLoaded;
|
final currentState = state as ScheduleLoaded;
|
||||||
|
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
countdownSeconds: currentState.countdownSeconds,
|
|
||||||
selectedTime: currentState.selectedTime,
|
|
||||||
deviceId: deviceId,
|
|
||||||
scheduleMode: event.scheduleMode,
|
scheduleMode: event.scheduleMode,
|
||||||
countdownHours: currentState.countdownHours,
|
countdownRemaining: Duration.zero,
|
||||||
countdownMinutes: currentState.countdownMinutes,
|
countdownHours: 0,
|
||||||
inchingHours: currentState.inchingHours,
|
countdownMinutes: 0,
|
||||||
inchingMinutes: currentState.inchingMinutes,
|
inchingHours: 0,
|
||||||
|
inchingMinutes: 0,
|
||||||
|
isCountdownActive: false,
|
||||||
isInchingActive: false,
|
isInchingActive: false,
|
||||||
isCountdownActive: currentState.countdownRemaining > Duration.zero,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,6 +221,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
deviceId,
|
deviceId,
|
||||||
event.category,
|
event.category,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (state is ScheduleLoaded) {
|
if (state is ScheduleLoaded) {
|
||||||
final currentState = state as ScheduleLoaded;
|
final currentState = state as ScheduleLoaded;
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
@ -287,22 +285,12 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
if (state is ScheduleLoaded) {
|
if (state is ScheduleLoaded) {
|
||||||
Status status = Status(code: '', value: '');
|
|
||||||
if (event.deviceType == 'CUR_2') {
|
|
||||||
status = status.copyWith(
|
|
||||||
code: 'control',
|
|
||||||
value: event.functionOn == true ? 'open' : 'close');
|
|
||||||
} else {
|
|
||||||
status =
|
|
||||||
status.copyWith(code: event.category, value: event.functionOn);
|
|
||||||
}
|
|
||||||
|
|
||||||
final dateTime = DateTime.parse(event.time);
|
final dateTime = DateTime.parse(event.time);
|
||||||
final updatedSchedule = ScheduleEntry(
|
final updatedSchedule = ScheduleEntry(
|
||||||
scheduleId: event.scheduleId,
|
scheduleId: event.scheduleId,
|
||||||
category: event.category,
|
category: event.category,
|
||||||
time: getTimeStampWithoutSeconds(dateTime).toString(),
|
time: getTimeStampWithoutSeconds(dateTime).toString(),
|
||||||
function: status,
|
function: Status(code: event.category, value: event.functionOn),
|
||||||
days: event.selectedDays,
|
days: event.selectedDays,
|
||||||
);
|
);
|
||||||
final success = await DevicesManagementApi().editScheduleRecord(
|
final success = await DevicesManagementApi().editScheduleRecord(
|
||||||
@ -408,7 +396,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
final totalSeconds =
|
final totalSeconds =
|
||||||
Duration(hours: event.hours, minutes: event.minutes).inSeconds;
|
Duration(hours: event.hours, minutes: event.minutes).inSeconds;
|
||||||
final code = event.mode == ScheduleModes.countdown
|
final code = event.mode == ScheduleModes.countdown
|
||||||
? event.countDownCode
|
? 'countdown_1'
|
||||||
: 'switch_inching';
|
: 'switch_inching';
|
||||||
final currentState = state as ScheduleLoaded;
|
final currentState = state as ScheduleLoaded;
|
||||||
final duration = Duration(seconds: totalSeconds);
|
final duration = Duration(seconds: totalSeconds);
|
||||||
@ -435,7 +423,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
if (code == event.countDownCode) {
|
if (code == 'countdown_1') {
|
||||||
final countdownDuration = Duration(seconds: totalSeconds);
|
final countdownDuration = Duration(seconds: totalSeconds);
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
@ -449,7 +437,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (countdownDuration.inSeconds > 0) {
|
if (countdownDuration.inSeconds > 0) {
|
||||||
_startCountdownTimer(emit, countdownDuration, event.countDownCode);
|
_startCountdownTimer(emit, countdownDuration);
|
||||||
} else {
|
} else {
|
||||||
_countdownTimer?.cancel();
|
_countdownTimer?.cancel();
|
||||||
emit(
|
emit(
|
||||||
@ -479,7 +467,9 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _startCountdownTimer(
|
void _startCountdownTimer(
|
||||||
Emitter<ScheduleState> emit, Duration duration, String countdownCode) {
|
Emitter<ScheduleState> emit,
|
||||||
|
Duration duration,
|
||||||
|
) {
|
||||||
_countdownTimer?.cancel();
|
_countdownTimer?.cancel();
|
||||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
if (_currentCountdown != null && _currentCountdown! > Duration.zero) {
|
if (_currentCountdown != null && _currentCountdown! > Duration.zero) {
|
||||||
@ -489,7 +479,6 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
} else {
|
} else {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
add(StopScheduleEvent(
|
add(StopScheduleEvent(
|
||||||
countdownCode: countdownCode,
|
|
||||||
mode: _currentCountdown == null
|
mode: _currentCountdown == null
|
||||||
? ScheduleModes.countdown
|
? ScheduleModes.countdown
|
||||||
: ScheduleModes.inching,
|
: ScheduleModes.inching,
|
||||||
@ -526,75 +515,70 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
try {
|
try {
|
||||||
final status =
|
final status =
|
||||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
int totalSeconds = 0;
|
print(status.status);
|
||||||
final countdownItem = status.status.firstWhere(
|
|
||||||
(item) => item.code == event.countdownCode,
|
|
||||||
orElse: () => Status(code: '', value: 0),
|
|
||||||
);
|
|
||||||
totalSeconds = (countdownItem.value as int?) ?? 0;
|
|
||||||
final countdownHours = totalSeconds ~/ 3600;
|
|
||||||
final countdownMinutes = (totalSeconds % 3600) ~/ 60;
|
|
||||||
final countdownSeconds = totalSeconds % 60;
|
|
||||||
|
|
||||||
final deviceStatus =
|
final deviceStatus =
|
||||||
WaterHeaterStatusModel.fromJson(event.deviceId, status.status);
|
WaterHeaterStatusModel.fromJson(event.deviceId, status.status);
|
||||||
final isCountdownActive = totalSeconds > 0;
|
|
||||||
final isInchingActive = !isCountdownActive &&
|
|
||||||
(deviceStatus.inchingHours > 0 || deviceStatus.inchingMinutes > 0);
|
|
||||||
|
|
||||||
final newState = state is ScheduleLoaded
|
final scheduleMode =
|
||||||
? (state as ScheduleLoaded).copyWith(
|
deviceStatus.countdownHours > 0 || deviceStatus.countdownMinutes > 0
|
||||||
scheduleMode: ScheduleModes.schedule,
|
? ScheduleModes.countdown
|
||||||
countdownHours: countdownHours,
|
: deviceStatus.inchingHours > 0 || deviceStatus.inchingMinutes > 0
|
||||||
countdownMinutes: countdownMinutes,
|
? ScheduleModes.inching
|
||||||
countdownSeconds: countdownSeconds,
|
: ScheduleModes.schedule;
|
||||||
|
final isCountdown = scheduleMode == ScheduleModes.countdown;
|
||||||
|
final isInching = scheduleMode == ScheduleModes.inching;
|
||||||
|
|
||||||
|
Duration? countdownRemaining;
|
||||||
|
var isCountdownActive = false;
|
||||||
|
var isInchingActive = false;
|
||||||
|
|
||||||
|
if (isCountdown) {
|
||||||
|
countdownRemaining = Duration(
|
||||||
|
hours: deviceStatus.countdownHours,
|
||||||
|
minutes: deviceStatus.countdownMinutes,
|
||||||
|
);
|
||||||
|
isCountdownActive = countdownRemaining > Duration.zero;
|
||||||
|
} else if (isInching) {
|
||||||
|
isInchingActive = Duration(
|
||||||
|
hours: deviceStatus.inchingHours,
|
||||||
|
minutes: deviceStatus.inchingMinutes,
|
||||||
|
) >
|
||||||
|
Duration.zero;
|
||||||
|
}
|
||||||
|
if (state is ScheduleLoaded) {
|
||||||
|
final currentState = state as ScheduleLoaded;
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
scheduleMode: scheduleMode,
|
||||||
|
countdownHours: deviceStatus.countdownHours,
|
||||||
|
countdownMinutes: deviceStatus.countdownMinutes,
|
||||||
inchingHours: deviceStatus.inchingHours,
|
inchingHours: deviceStatus.inchingHours,
|
||||||
inchingMinutes: deviceStatus.inchingMinutes,
|
inchingMinutes: deviceStatus.inchingMinutes,
|
||||||
isCountdownActive: isCountdownActive,
|
isCountdownActive: isCountdownActive,
|
||||||
isInchingActive: isInchingActive,
|
isInchingActive: isInchingActive,
|
||||||
countdownRemaining: isCountdownActive
|
countdownRemaining: countdownRemaining ?? Duration.zero,
|
||||||
? Duration(seconds: totalSeconds)
|
));
|
||||||
: Duration.zero,
|
} else {
|
||||||
)
|
emit(ScheduleLoaded(
|
||||||
: ScheduleLoaded(
|
|
||||||
scheduleMode: ScheduleModes.schedule,
|
|
||||||
schedules: const [],
|
schedules: const [],
|
||||||
selectedTime: null,
|
selectedTime: null,
|
||||||
selectedDays: List.filled(7, false),
|
selectedDays: List.filled(7, false),
|
||||||
functionOn: false,
|
functionOn: false,
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
deviceId: event.deviceId,
|
deviceId: deviceId,
|
||||||
countdownHours: countdownHours,
|
scheduleMode: scheduleMode,
|
||||||
countdownMinutes: countdownMinutes,
|
countdownHours: deviceStatus.countdownHours,
|
||||||
countdownSeconds: countdownSeconds,
|
countdownMinutes: deviceStatus.countdownMinutes,
|
||||||
inchingHours: deviceStatus.inchingHours,
|
inchingHours: deviceStatus.inchingHours,
|
||||||
inchingMinutes: deviceStatus.inchingMinutes,
|
inchingMinutes: deviceStatus.inchingMinutes,
|
||||||
isCountdownActive: isCountdownActive,
|
isCountdownActive: isCountdownActive,
|
||||||
isInchingActive: isInchingActive,
|
isInchingActive: isInchingActive,
|
||||||
countdownRemaining: isCountdownActive
|
countdownRemaining: countdownRemaining ?? Duration.zero,
|
||||||
? Duration(seconds: totalSeconds)
|
|
||||||
: Duration.zero,
|
|
||||||
);
|
|
||||||
emit(newState);
|
|
||||||
|
|
||||||
if (isCountdownActive) {
|
|
||||||
_countdownTimer?.cancel();
|
|
||||||
_currentCountdown = Duration(seconds: totalSeconds);
|
|
||||||
countdownRemaining = _currentCountdown!;
|
|
||||||
|
|
||||||
if (totalSeconds > 0) {
|
|
||||||
_startCountdownTimer(
|
|
||||||
emit, Duration(seconds: totalSeconds), event.countdownCode);
|
|
||||||
} else {
|
|
||||||
add(StopScheduleEvent(
|
|
||||||
countdownCode: event.countdownCode,
|
|
||||||
mode: ScheduleModes.countdown,
|
|
||||||
deviceId: event.deviceId,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
_countdownTimer?.cancel();
|
// if (isCountdownActive && countdownRemaining != null) {
|
||||||
}
|
// _startCountdownTimer(emit, countdownRemaining);
|
||||||
|
// }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(ScheduleError('Failed to fetch device status: $e'));
|
emit(ScheduleError('Failed to fetch device status: $e'));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,7 +91,6 @@ class ScheduleEditEvent extends ScheduleEvent {
|
|||||||
final String time;
|
final String time;
|
||||||
final List<String> selectedDays;
|
final List<String> selectedDays;
|
||||||
final bool functionOn;
|
final bool functionOn;
|
||||||
final String deviceType;
|
|
||||||
|
|
||||||
const ScheduleEditEvent({
|
const ScheduleEditEvent({
|
||||||
required this.scheduleId,
|
required this.scheduleId,
|
||||||
@ -99,7 +98,6 @@ class ScheduleEditEvent extends ScheduleEvent {
|
|||||||
required this.time,
|
required this.time,
|
||||||
required this.selectedDays,
|
required this.selectedDays,
|
||||||
required this.functionOn,
|
required this.functionOn,
|
||||||
required this.deviceType,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -109,7 +107,6 @@ class ScheduleEditEvent extends ScheduleEvent {
|
|||||||
time,
|
time,
|
||||||
selectedDays,
|
selectedDays,
|
||||||
functionOn,
|
functionOn,
|
||||||
deviceType,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,13 +138,11 @@ class ScheduleUpdateEntryEvent extends ScheduleEvent {
|
|||||||
|
|
||||||
class UpdateScheduleModeEvent extends ScheduleEvent {
|
class UpdateScheduleModeEvent extends ScheduleEvent {
|
||||||
final ScheduleModes scheduleMode;
|
final ScheduleModes scheduleMode;
|
||||||
final String countdownCode;
|
|
||||||
|
|
||||||
const UpdateScheduleModeEvent(
|
const UpdateScheduleModeEvent({required this.scheduleMode});
|
||||||
{required this.scheduleMode, required this.countdownCode});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [scheduleMode, countdownCode!];
|
List<Object> get props => [scheduleMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateCountdownTimeEvent extends ScheduleEvent {
|
class UpdateCountdownTimeEvent extends ScheduleEvent {
|
||||||
@ -182,32 +177,28 @@ class StartScheduleEvent extends ScheduleEvent {
|
|||||||
final ScheduleModes mode;
|
final ScheduleModes mode;
|
||||||
final int hours;
|
final int hours;
|
||||||
final int minutes;
|
final int minutes;
|
||||||
final String countDownCode;
|
|
||||||
|
|
||||||
const StartScheduleEvent({
|
const StartScheduleEvent({
|
||||||
required this.mode,
|
required this.mode,
|
||||||
required this.hours,
|
required this.hours,
|
||||||
required this.minutes,
|
required this.minutes,
|
||||||
required this.countDownCode,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [mode, hours, minutes, countDownCode];
|
List<Object?> get props => [mode, hours, minutes];
|
||||||
}
|
}
|
||||||
|
|
||||||
class StopScheduleEvent extends ScheduleEvent {
|
class StopScheduleEvent extends ScheduleEvent {
|
||||||
final ScheduleModes mode;
|
final ScheduleModes mode;
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
final String countdownCode;
|
|
||||||
|
|
||||||
const StopScheduleEvent({
|
const StopScheduleEvent({
|
||||||
required this.mode,
|
required this.mode,
|
||||||
required this.deviceId,
|
required this.deviceId,
|
||||||
required this.countdownCode,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [mode, deviceId, countdownCode];
|
List<Object?> get props => [mode, deviceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScheduleDecrementCountdownEvent extends ScheduleEvent {
|
class ScheduleDecrementCountdownEvent extends ScheduleEvent {
|
||||||
@ -219,13 +210,11 @@ class ScheduleDecrementCountdownEvent extends ScheduleEvent {
|
|||||||
|
|
||||||
class ScheduleFetchStatusEvent extends ScheduleEvent {
|
class ScheduleFetchStatusEvent extends ScheduleEvent {
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
final String countdownCode;
|
|
||||||
|
|
||||||
const ScheduleFetchStatusEvent(
|
const ScheduleFetchStatusEvent(this.deviceId);
|
||||||
{required this.deviceId, required this.countdownCode});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [deviceId, countdownCode];
|
List<Object> get props => [deviceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeleteScheduleEvent extends ScheduleEvent {
|
class DeleteScheduleEvent extends ScheduleEvent {
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
final int inchingSeconds;
|
final int inchingSeconds;
|
||||||
final bool isInchingActive;
|
final bool isInchingActive;
|
||||||
final ScheduleModes scheduleMode;
|
final ScheduleModes scheduleMode;
|
||||||
final Duration countdownRemaining;
|
final Duration? countdownRemaining;
|
||||||
final int? countdownSeconds;
|
final int? countdownSeconds;
|
||||||
|
|
||||||
const ScheduleLoaded({
|
const ScheduleLoaded({
|
||||||
@ -48,7 +48,7 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
this.inchingMinutes = 0,
|
this.inchingMinutes = 0,
|
||||||
this.isInchingActive = false,
|
this.isInchingActive = false,
|
||||||
this.scheduleMode = ScheduleModes.countdown,
|
this.scheduleMode = ScheduleModes.countdown,
|
||||||
this.countdownRemaining = Duration.zero,
|
this.countdownRemaining,
|
||||||
});
|
});
|
||||||
|
|
||||||
ScheduleLoaded copyWith({
|
ScheduleLoaded copyWith({
|
||||||
|
|||||||
@ -11,7 +11,6 @@ class CountdownModeButtons extends StatelessWidget {
|
|||||||
final String deviceId;
|
final String deviceId;
|
||||||
final int hours;
|
final int hours;
|
||||||
final int minutes;
|
final int minutes;
|
||||||
final String countDownCode;
|
|
||||||
|
|
||||||
const CountdownModeButtons({
|
const CountdownModeButtons({
|
||||||
super.key,
|
super.key,
|
||||||
@ -19,7 +18,6 @@ class CountdownModeButtons extends StatelessWidget {
|
|||||||
required this.deviceId,
|
required this.deviceId,
|
||||||
required this.hours,
|
required this.hours,
|
||||||
required this.minutes,
|
required this.minutes,
|
||||||
required this.countDownCode,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -45,7 +43,6 @@ class CountdownModeButtons extends StatelessWidget {
|
|||||||
StopScheduleEvent(
|
StopScheduleEvent(
|
||||||
mode: ScheduleModes.countdown,
|
mode: ScheduleModes.countdown,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
countdownCode: countDownCode,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -60,7 +57,7 @@ class CountdownModeButtons extends StatelessWidget {
|
|||||||
mode: ScheduleModes.countdown,
|
mode: ScheduleModes.countdown,
|
||||||
hours: hours,
|
hours: hours,
|
||||||
minutes: minutes,
|
minutes: minutes,
|
||||||
countDownCode: countDownCode),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
backgroundColor: ColorsManager.primaryColor,
|
backgroundColor: ColorsManager.primaryColor,
|
||||||
|
|||||||
@ -75,33 +75,23 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
|||||||
final isCountDown = state.scheduleMode == ScheduleModes.countdown;
|
final isCountDown = state.scheduleMode == ScheduleModes.countdown;
|
||||||
final isActive =
|
final isActive =
|
||||||
isCountDown ? state.isCountdownActive : state.isInchingActive;
|
isCountDown ? state.isCountdownActive : state.isInchingActive;
|
||||||
|
final displayHours = isActive && state.countdownRemaining != null
|
||||||
final displayHours =
|
? state.countdownRemaining!.inHours
|
||||||
isActive && state.countdownRemaining != Duration.zero
|
|
||||||
? state.countdownRemaining.inHours
|
|
||||||
: (isCountDown ? state.countdownHours : state.inchingHours);
|
: (isCountDown ? state.countdownHours : state.inchingHours);
|
||||||
|
final displayMinutes = isActive && state.countdownRemaining != null
|
||||||
final displayMinutes =
|
? state.countdownRemaining!.inMinutes.remainder(60)
|
||||||
isActive && state.countdownRemaining != Duration.zero
|
|
||||||
? state.countdownRemaining.inMinutes.remainder(60)
|
|
||||||
: (isCountDown ? state.countdownMinutes : state.inchingMinutes);
|
: (isCountDown ? state.countdownMinutes : state.inchingMinutes);
|
||||||
|
final displaySeconds = isActive && state.countdownRemaining != null
|
||||||
|
? state.countdownRemaining!.inSeconds.remainder(60)
|
||||||
|
: (isCountDown ? state.countdownSeconds : state.inchingSeconds);
|
||||||
|
|
||||||
final displaySeconds =
|
_updateControllers(displayHours, displayMinutes, displaySeconds!);
|
||||||
isActive && state.countdownRemaining != Duration.zero
|
|
||||||
? state.countdownRemaining.inSeconds.remainder(60)
|
|
||||||
: (isCountDown ? (state.countdownSeconds ?? 0) : 0);
|
|
||||||
|
|
||||||
_updateControllers(displayHours, displayMinutes, displaySeconds);
|
if (displayHours == 0 && displayMinutes == 0 && displaySeconds == 0) {
|
||||||
|
|
||||||
if (isActive &&
|
|
||||||
displayHours == 0 &&
|
|
||||||
displayMinutes == 0 &&
|
|
||||||
displaySeconds == 0) {
|
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
StopScheduleEvent(
|
StopScheduleEvent(
|
||||||
mode: ScheduleModes.countdown,
|
mode: ScheduleModes.countdown,
|
||||||
deviceId: widget.deviceId,
|
deviceId: widget.deviceId,
|
||||||
countdownCode: '',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,9 +43,7 @@ class InchingModeButtons extends StatelessWidget {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
StopScheduleEvent(
|
StopScheduleEvent(
|
||||||
deviceId: deviceId,
|
deviceId: deviceId, mode: ScheduleModes.inching),
|
||||||
mode: ScheduleModes.inching,
|
|
||||||
countdownCode: ''),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
|
|||||||
@ -18,15 +18,11 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.deviceUuid,
|
required this.deviceUuid,
|
||||||
required this.category,
|
required this.category,
|
||||||
required this.countdownCode,
|
|
||||||
this.code,
|
this.code,
|
||||||
required this.deviceType,
|
|
||||||
});
|
});
|
||||||
final String deviceUuid;
|
final String deviceUuid;
|
||||||
final String category;
|
final String category;
|
||||||
final String? code;
|
final String? code;
|
||||||
final String? countdownCode;
|
|
||||||
final String deviceType;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -35,8 +31,7 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
deviceId: deviceUuid,
|
deviceId: deviceUuid,
|
||||||
)
|
)
|
||||||
..add(ScheduleGetEvent(category: category))
|
..add(ScheduleGetEvent(category: category))
|
||||||
..add(ScheduleFetchStatusEvent(
|
..add(ScheduleFetchStatusEvent(deviceUuid)),
|
||||||
deviceId: deviceUuid, countdownCode: countdownCode ?? '')),
|
|
||||||
child: Dialog(
|
child: Dialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
insetPadding: const EdgeInsets.all(20),
|
insetPadding: const EdgeInsets.all(20),
|
||||||
@ -57,22 +52,18 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
const ScheduleHeader(),
|
const ScheduleHeader(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (deviceType == 'CUR_2')
|
|
||||||
const SizedBox()
|
|
||||||
else
|
|
||||||
ScheduleModeSelector(
|
ScheduleModeSelector(
|
||||||
countdownCode: countdownCode ?? '',
|
|
||||||
currentMode: state.scheduleMode,
|
currentMode: state.scheduleMode,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (state.scheduleMode == ScheduleModes.schedule)
|
if (state.scheduleMode == ScheduleModes.schedule)
|
||||||
ScheduleManagementUI(
|
ScheduleManagementUI(
|
||||||
deviceType: deviceType,
|
|
||||||
category: category,
|
category: category,
|
||||||
deviceUuid: deviceUuid,
|
deviceUuid: deviceUuid,
|
||||||
onAddSchedule: () async {
|
onAddSchedule: () async {
|
||||||
final entry = await ScheduleDialogHelper
|
final entry = await ScheduleDialogHelper
|
||||||
.showAddScheduleDialog(context,
|
.showAddScheduleDialog(
|
||||||
|
context,
|
||||||
schedule: ScheduleEntry(
|
schedule: ScheduleEntry(
|
||||||
category: category,
|
category: category,
|
||||||
time: '',
|
time: '',
|
||||||
@ -82,7 +73,7 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
isEdit: false,
|
isEdit: false,
|
||||||
code: code,
|
code: code,
|
||||||
deviceType: deviceType);
|
);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
ScheduleAddEvent(
|
ScheduleAddEvent(
|
||||||
@ -96,7 +87,6 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (deviceType != 'CUR_2')
|
|
||||||
if (state.scheduleMode == ScheduleModes.countdown ||
|
if (state.scheduleMode == ScheduleModes.countdown ||
|
||||||
state.scheduleMode == ScheduleModes.inching)
|
state.scheduleMode == ScheduleModes.inching)
|
||||||
CountdownInchingView(
|
CountdownInchingView(
|
||||||
@ -105,7 +95,6 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (state.scheduleMode == ScheduleModes.countdown)
|
if (state.scheduleMode == ScheduleModes.countdown)
|
||||||
CountdownModeButtons(
|
CountdownModeButtons(
|
||||||
countDownCode: countdownCode ?? '',
|
|
||||||
isActive: state.isCountdownActive,
|
isActive: state.isCountdownActive,
|
||||||
deviceId: deviceUuid,
|
deviceId: deviceUuid,
|
||||||
hours: state.countdownHours,
|
hours: state.countdownHours,
|
||||||
|
|||||||
@ -8,13 +8,11 @@ class ScheduleManagementUI extends StatelessWidget {
|
|||||||
final String deviceUuid;
|
final String deviceUuid;
|
||||||
final VoidCallback onAddSchedule;
|
final VoidCallback onAddSchedule;
|
||||||
final String category;
|
final String category;
|
||||||
final String deviceType;
|
|
||||||
|
|
||||||
const ScheduleManagementUI({
|
const ScheduleManagementUI({
|
||||||
super.key,
|
super.key,
|
||||||
required this.deviceUuid,
|
required this.deviceUuid,
|
||||||
required this.onAddSchedule,
|
required this.onAddSchedule,
|
||||||
required this.deviceType,
|
|
||||||
this.category = 'switch_1',
|
this.category = 'switch_1',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -46,11 +44,7 @@ class ScheduleManagementUI extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
ScheduleTableWidget(
|
ScheduleTableWidget(deviceUuid: deviceUuid, category: category),
|
||||||
deviceUuid: deviceUuid,
|
|
||||||
category: category,
|
|
||||||
deviceType: deviceType,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,12 +7,10 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|||||||
|
|
||||||
class ScheduleModeSelector extends StatelessWidget {
|
class ScheduleModeSelector extends StatelessWidget {
|
||||||
final ScheduleModes currentMode;
|
final ScheduleModes currentMode;
|
||||||
final String countdownCode;
|
|
||||||
|
|
||||||
const ScheduleModeSelector({
|
const ScheduleModeSelector({
|
||||||
super.key,
|
super.key,
|
||||||
required this.currentMode,
|
required this.currentMode,
|
||||||
required this.countdownCode,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -73,8 +71,7 @@ class ScheduleModeSelector extends StatelessWidget {
|
|||||||
onChanged: (ScheduleModes? value) {
|
onChanged: (ScheduleModes? value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
UpdateScheduleModeEvent(
|
UpdateScheduleModeEvent(scheduleMode: value),
|
||||||
scheduleMode: value, countdownCode: countdownCode),
|
|
||||||
);
|
);
|
||||||
if (value == ScheduleModes.schedule) {
|
if (value == ScheduleModes.schedule) {
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
|
|||||||
@ -12,13 +12,11 @@ import 'package:syncrow_web/utils/format_date_time.dart';
|
|||||||
class ScheduleTableWidget extends StatelessWidget {
|
class ScheduleTableWidget extends StatelessWidget {
|
||||||
final String deviceUuid;
|
final String deviceUuid;
|
||||||
final String category;
|
final String category;
|
||||||
final String deviceType;
|
|
||||||
|
|
||||||
const ScheduleTableWidget({
|
const ScheduleTableWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.deviceUuid,
|
required this.deviceUuid,
|
||||||
this.category = 'switch_1',
|
this.category = 'switch_1',
|
||||||
required this.deviceType,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -27,14 +25,13 @@ class ScheduleTableWidget extends StatelessWidget {
|
|||||||
create: (_) => ScheduleBloc(
|
create: (_) => ScheduleBloc(
|
||||||
deviceId: deviceUuid,
|
deviceId: deviceUuid,
|
||||||
)..add(ScheduleGetEvent(category: category)),
|
)..add(ScheduleGetEvent(category: category)),
|
||||||
child: _ScheduleTableView(deviceType),
|
child: _ScheduleTableView(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ScheduleTableView extends StatelessWidget {
|
class _ScheduleTableView extends StatelessWidget {
|
||||||
final String deviceType;
|
const _ScheduleTableView();
|
||||||
const _ScheduleTableView(this.deviceType);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -84,7 +81,7 @@ class _ScheduleTableView extends StatelessWidget {
|
|||||||
bottomLeft: Radius.circular(20),
|
bottomLeft: Radius.circular(20),
|
||||||
bottomRight: Radius.circular(20)),
|
bottomRight: Radius.circular(20)),
|
||||||
),
|
),
|
||||||
child: _buildTableBody(state.schedules, context, deviceType));
|
child: _buildTableBody(state.schedules, context));
|
||||||
}
|
}
|
||||||
if (state is ScheduleError) {
|
if (state is ScheduleError) {
|
||||||
return Center(child: Text(state.error));
|
return Center(child: Text(state.error));
|
||||||
@ -126,8 +123,7 @@ class _ScheduleTableView extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTableBody(
|
Widget _buildTableBody(List<ScheduleModel> schedules, BuildContext context) {
|
||||||
List<ScheduleModel> schedules, BuildContext context, String deviceType) {
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
@ -136,8 +132,7 @@ class _ScheduleTableView extends StatelessWidget {
|
|||||||
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
||||||
children: [
|
children: [
|
||||||
for (int i = 0; i < schedules.length; i++)
|
for (int i = 0; i < schedules.length; i++)
|
||||||
_buildScheduleRow(schedules[i], i, context,
|
_buildScheduleRow(schedules[i], i, context),
|
||||||
deviceType: deviceType),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -160,19 +155,25 @@ class _ScheduleTableView extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TableRow _buildScheduleRow(
|
TableRow _buildScheduleRow(
|
||||||
ScheduleModel schedule, int index, BuildContext context,
|
ScheduleModel schedule, int index, BuildContext context) {
|
||||||
{required String deviceType}) {
|
|
||||||
return TableRow(
|
return TableRow(
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
behavior: HitTestBehavior.opaque,
|
behavior: HitTestBehavior.opaque,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
bool temp;
|
||||||
|
if (schedule.category == 'CUR_2') {
|
||||||
|
temp = schedule.function.value == 'open' ? true : false;
|
||||||
|
} else {
|
||||||
|
temp = schedule.function.value as bool;
|
||||||
|
}
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
ScheduleUpdateEntryEvent(
|
ScheduleUpdateEntryEvent(
|
||||||
category: schedule.category,
|
category: schedule.category,
|
||||||
scheduleId: schedule.scheduleId,
|
scheduleId: schedule.scheduleId,
|
||||||
functionOn: schedule.function.value,
|
functionOn: temp,
|
||||||
|
// schedule.function.value,
|
||||||
enable: !schedule.enable,
|
enable: !schedule.enable,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -194,11 +195,10 @@ class _ScheduleTableView extends StatelessWidget {
|
|||||||
child: Text(_getSelectedDays(
|
child: Text(_getSelectedDays(
|
||||||
ScheduleModel.parseSelectedDays(schedule.days)))),
|
ScheduleModel.parseSelectedDays(schedule.days)))),
|
||||||
Center(child: Text(formatIsoStringToTime(schedule.time, context))),
|
Center(child: Text(formatIsoStringToTime(schedule.time, context))),
|
||||||
if (deviceType == 'CUR_2')
|
schedule.category == 'CUR_2'
|
||||||
Center(
|
? Center(
|
||||||
child: Text(schedule.function.value == true ? 'open' : 'close'))
|
child: Text(schedule.function.value == true ? 'open' : 'close'))
|
||||||
else
|
: Center(child: Text(schedule.function.value ? 'On' : 'Off')),
|
||||||
Center(child: Text(schedule.function.value ? 'On' : 'Off')),
|
|
||||||
Center(
|
Center(
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
runAlignment: WrapAlignment.center,
|
runAlignment: WrapAlignment.center,
|
||||||
@ -206,27 +206,18 @@ class _ScheduleTableView extends StatelessWidget {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: TextButton.styleFrom(padding: EdgeInsets.zero),
|
style: TextButton.styleFrom(padding: EdgeInsets.zero),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ScheduleDialogHelper.showAddScheduleDialog(context,
|
ScheduleDialogHelper.showAddScheduleDialog(
|
||||||
|
context,
|
||||||
schedule: ScheduleEntry.fromScheduleModel(schedule),
|
schedule: ScheduleEntry.fromScheduleModel(schedule),
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
deviceType: deviceType)
|
).then((updatedSchedule) {
|
||||||
.then((updatedSchedule) {
|
|
||||||
if (updatedSchedule != null) {
|
if (updatedSchedule != null) {
|
||||||
bool temp;
|
|
||||||
if (deviceType == 'CUR_2') {
|
|
||||||
updatedSchedule.function.value == 'open'
|
|
||||||
? temp = true
|
|
||||||
: temp = false;
|
|
||||||
} else {
|
|
||||||
temp = updatedSchedule.function.value;
|
|
||||||
}
|
|
||||||
context.read<ScheduleBloc>().add(
|
context.read<ScheduleBloc>().add(
|
||||||
ScheduleEditEvent(
|
ScheduleEditEvent(
|
||||||
deviceType: deviceType,
|
|
||||||
scheduleId: schedule.scheduleId,
|
scheduleId: schedule.scheduleId,
|
||||||
category: schedule.category,
|
category: schedule.category,
|
||||||
time: updatedSchedule.time,
|
time: updatedSchedule.time,
|
||||||
functionOn: temp,
|
functionOn: updatedSchedule.function.value,
|
||||||
selectedDays: updatedSchedule.days),
|
selectedDays: updatedSchedule.days),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class ThreeGangGlassSwitchBloc
|
|||||||
emit(ThreeGangGlassSwitchLoading());
|
emit(ThreeGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
_listenToChanges(event.deviceId);
|
_listenToChanges(event.deviceId, emit);
|
||||||
deviceStatus =
|
deviceStatus =
|
||||||
ThreeGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
ThreeGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||||
emit(ThreeGangGlassSwitchStatusLoaded(deviceStatus));
|
emit(ThreeGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
@ -50,28 +50,42 @@ class ThreeGangGlassSwitchBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription<DatabaseEvent>? _deviceStatusSubscription;
|
void _listenToChanges(
|
||||||
|
String deviceId,
|
||||||
void _listenToChanges(String deviceId) {
|
Emitter<ThreeGangGlassSwitchState> emit,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
_deviceStatusSubscription = ref.onValue.listen((DatabaseEvent event) async {
|
final stream = ref.onValue;
|
||||||
if (event.snapshot.value == null) return;
|
|
||||||
|
|
||||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
stream.listen((DatabaseEvent event) {
|
||||||
|
final data = event.snapshot.value as Map<dynamic, dynamic>?;
|
||||||
|
if (data == null) return;
|
||||||
|
|
||||||
final statusList = <Status>[];
|
final statusList = <Status>[];
|
||||||
|
if (data['status'] != null) {
|
||||||
usersMap['status'].forEach((element) {
|
for (var element in data['status']) {
|
||||||
statusList.add(Status(code: element['code'], value: element['value']));
|
statusList.add(
|
||||||
});
|
Status(
|
||||||
|
code: element['code'].toString(),
|
||||||
deviceStatus =
|
value: element['value'].toString(),
|
||||||
ThreeGangGlassStatusModel.fromJson(usersMap['productUuid'], statusList);
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (statusList.isNotEmpty) {
|
||||||
|
final newStatus = ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||||
|
if (newStatus != deviceStatus) {
|
||||||
|
deviceStatus = newStatus;
|
||||||
|
if (!isClosed) {
|
||||||
add(StatusUpdated(deviceStatus));
|
add(StatusUpdated(deviceStatus));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (e) {
|
||||||
|
emit(ThreeGangGlassSwitchError('Failed to listen to changes: $e'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onStatusUpdated(
|
void _onStatusUpdated(
|
||||||
@ -170,10 +184,4 @@ class ThreeGangGlassSwitchBloc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() {
|
|
||||||
_deviceStatusSubscription?.cancel();
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,8 +111,6 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: '3GT',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -129,8 +127,6 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_2',
|
category: 'switch_2',
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
countdownCode: 'countdown_2',
|
|
||||||
deviceType: '3GT',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -147,8 +143,6 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_3',
|
category: 'switch_3',
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
countdownCode: 'countdown_3',
|
|
||||||
deviceType: '3GT',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -102,8 +102,6 @@ class LivingRoomDeviceControlsView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: '3G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -120,8 +118,6 @@ class LivingRoomDeviceControlsView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_2',
|
category: 'switch_2',
|
||||||
countdownCode: 'countdown_2',
|
|
||||||
deviceType: '3G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -138,8 +134,6 @@ class LivingRoomDeviceControlsView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_3',
|
category: 'switch_3',
|
||||||
countdownCode: 'countdown_3',
|
|
||||||
deviceType: '3G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/two_g_glass_switch/models/two_gang_glass_status_model.dart';
|
import 'package:syncrow_web/pages/device_managment/two_g_glass_switch/models/two_gang_glass_status_model.dart';
|
||||||
import 'package:syncrow_web/services/batch_control_devices_service.dart';
|
import 'package:syncrow_web/services/batch_control_devices_service.dart';
|
||||||
import 'package:syncrow_web/services/control_device_service.dart';
|
import 'package:syncrow_web/services/control_device_service.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
|
|
||||||
part 'two_gang_glass_switch_event.dart';
|
part 'two_gang_glass_switch_event.dart';
|
||||||
part 'two_gang_glass_switch_state.dart';
|
part 'two_gang_glass_switch_state.dart';
|
||||||
|
|
||||||
class TwoGangGlassSwitchBloc
|
class TwoGangGlassSwitchBloc
|
||||||
extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassSwitchState> {
|
extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassSwitchState> {
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
final ControlDeviceService controlDeviceService;
|
final ControlDeviceService controlDeviceService;
|
||||||
@ -50,28 +51,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription<DatabaseEvent>? _deviceStatusSubscription;
|
|
||||||
|
|
||||||
void _listenToChanges(String deviceId) {
|
void _listenToChanges(String deviceId) {
|
||||||
try {
|
try {
|
||||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
final ref = FirebaseDatabase.instance.ref(
|
||||||
_deviceStatusSubscription = ref.onValue.listen((DatabaseEvent event) async {
|
'device-status/$deviceId',
|
||||||
if (event.snapshot.value == null) return;
|
);
|
||||||
|
|
||||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
ref.onValue.listen((event) {
|
||||||
|
final eventsMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
|
||||||
final statusList = <Status>[];
|
List<Status> statusList = [];
|
||||||
|
eventsMap['status'].forEach((element) {
|
||||||
usersMap['status'].forEach((element) {
|
|
||||||
statusList.add(Status(code: element['code'], value: element['value']));
|
statusList.add(Status(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus =
|
deviceStatus = TwoGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||||
TwoGangGlassStatusModel.fromJson(usersMap['productUuid'], statusList);
|
|
||||||
|
|
||||||
add(StatusUpdated(deviceStatus));
|
add(StatusUpdated(deviceStatus));
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {
|
||||||
|
log(
|
||||||
|
'Error listening to changes',
|
||||||
|
name: 'TwoGangGlassSwitchBloc._listenToChanges',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onControl(
|
Future<void> _onControl(
|
||||||
@ -168,10 +170,4 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() {
|
|
||||||
_deviceStatusSubscription?.cancel();
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,8 +102,6 @@ class TwoGangGlassSwitchControlView extends StatelessWidget
|
|||||||
builder: (ctx) => BlocProvider.value(
|
builder: (ctx) => BlocProvider.value(
|
||||||
value: BlocProvider.of<TwoGangGlassSwitchBloc>(context),
|
value: BlocProvider.of<TwoGangGlassSwitchBloc>(context),
|
||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceType: '2GT',
|
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
),
|
),
|
||||||
@ -120,8 +118,6 @@ class TwoGangGlassSwitchControlView extends StatelessWidget
|
|||||||
builder: (ctx) => BlocProvider.value(
|
builder: (ctx) => BlocProvider.value(
|
||||||
value: BlocProvider.of<TwoGangGlassSwitchBloc>(context),
|
value: BlocProvider.of<TwoGangGlassSwitchBloc>(context),
|
||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceType: '2GT',
|
|
||||||
countdownCode: 'countdown_2',
|
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_2',
|
category: 'switch_2',
|
||||||
),
|
),
|
||||||
|
|||||||
@ -97,8 +97,6 @@ class TwoGangBatchControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
deviceUuid: deviceIds.first,
|
deviceUuid: deviceIds.first,
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: '2G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -116,8 +114,6 @@ class TwoGangBatchControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
category: 'switch_2',
|
category: 'switch_2',
|
||||||
deviceUuid: deviceIds.first,
|
deviceUuid: deviceIds.first,
|
||||||
countdownCode: 'countdown_2',
|
|
||||||
deviceType: '2G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -125,7 +121,10 @@ class TwoGangBatchControlView extends StatelessWidget
|
|||||||
subtitle: 'Scheduling',
|
subtitle: 'Scheduling',
|
||||||
iconPath: Assets.scheduling,
|
iconPath: Assets.scheduling,
|
||||||
),
|
),
|
||||||
|
// FirmwareUpdateWidget(
|
||||||
|
// deviceId: deviceIds.first,
|
||||||
|
// version: 12,
|
||||||
|
// ),
|
||||||
FactoryResetWidget(callFactoryReset: () {
|
FactoryResetWidget(callFactoryReset: () {
|
||||||
context.read<TwoGangSwitchBloc>().add(
|
context.read<TwoGangSwitchBloc>().add(
|
||||||
TwoGangFactoryReset(
|
TwoGangFactoryReset(
|
||||||
|
|||||||
@ -103,8 +103,6 @@ class TwoGangDeviceControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: '2G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
@ -127,8 +125,6 @@ class TwoGangDeviceControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: deviceId,
|
deviceUuid: deviceId,
|
||||||
category: 'switch_2',
|
category: 'switch_2',
|
||||||
countdownCode: 'countdown_2',
|
|
||||||
deviceType: '2G',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -18,21 +18,14 @@ class ScheduleDialogHelper {
|
|||||||
ScheduleEntry? schedule,
|
ScheduleEntry? schedule,
|
||||||
bool isEdit = false,
|
bool isEdit = false,
|
||||||
String? code,
|
String? code,
|
||||||
required String deviceType,
|
|
||||||
}) {
|
}) {
|
||||||
bool temp;
|
|
||||||
if (deviceType == 'CUR_2') {
|
|
||||||
temp = schedule!.function.value == 'open' ? true : false;
|
|
||||||
} else {
|
|
||||||
temp = schedule!.function.value;
|
|
||||||
}
|
|
||||||
final initialTime = schedule != null
|
final initialTime = schedule != null
|
||||||
? _convertStringToTimeOfDay(schedule.time)
|
? _convertStringToTimeOfDay(schedule.time)
|
||||||
: TimeOfDay.now();
|
: TimeOfDay.now();
|
||||||
final initialDays = schedule != null
|
final initialDays = schedule != null
|
||||||
? _convertDaysStringToBooleans(schedule.days)
|
? _convertDaysStringToBooleans(schedule.days)
|
||||||
: List.filled(7, false);
|
: List.filled(7, false);
|
||||||
bool? functionOn = temp;
|
bool? functionOn = schedule?.function.value ?? true;
|
||||||
TimeOfDay selectedTime = initialTime;
|
TimeOfDay selectedTime = initialTime;
|
||||||
List<bool> selectedDays = List.of(initialDays);
|
List<bool> selectedDays = List.of(initialDays);
|
||||||
|
|
||||||
@ -104,7 +97,8 @@ class ScheduleDialogHelper {
|
|||||||
setState(() => selectedDays[i] = v);
|
setState(() => selectedDays[i] = v);
|
||||||
}),
|
}),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_buildFunctionSwitch(deviceType, ctx, functionOn!, (v) {
|
_buildFunctionSwitch(schedule!.category, ctx, functionOn!,
|
||||||
|
(v) {
|
||||||
setState(() => functionOn = v);
|
setState(() => functionOn = v);
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -124,25 +118,28 @@ class ScheduleDialogHelper {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
dynamic temp;
|
dynamic temp;
|
||||||
if (deviceType == 'CUR_2') {
|
if (schedule?.category == 'CUR_2') {
|
||||||
temp = functionOn! ? 'open' : 'close';
|
temp = functionOn! ? 'open' : 'close';
|
||||||
} else {
|
} else {
|
||||||
temp = functionOn;
|
temp = functionOn;
|
||||||
}
|
}
|
||||||
|
print(temp);
|
||||||
final entry = ScheduleEntry(
|
final entry = ScheduleEntry(
|
||||||
category: schedule?.category ?? 'switch_1',
|
category: schedule?.category ?? 'switch_1',
|
||||||
time: _formatTimeOfDayToISO(selectedTime),
|
time: _formatTimeOfDayToISO(selectedTime),
|
||||||
function: Status(
|
function: Status(
|
||||||
code: code ?? 'switch_1',
|
code: code ?? 'switch_1',
|
||||||
value: temp,
|
value: temp,
|
||||||
|
// functionOn,
|
||||||
),
|
),
|
||||||
days: _convertSelectedDaysToStrings(selectedDays),
|
days: _convertSelectedDaysToStrings(selectedDays),
|
||||||
scheduleId: schedule.scheduleId,
|
scheduleId: schedule?.scheduleId,
|
||||||
);
|
);
|
||||||
Navigator.pop(ctx, entry);
|
Navigator.pop(ctx, entry);
|
||||||
},
|
},
|
||||||
child: const Text('Save'),
|
child: const Text('Save'),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -84,8 +84,6 @@ class WaterHeaterDeviceControlView extends StatelessWidget
|
|||||||
child: BuildScheduleView(
|
child: BuildScheduleView(
|
||||||
deviceUuid: device.uuid ?? '',
|
deviceUuid: device.uuid ?? '',
|
||||||
category: 'switch_1',
|
category: 'switch_1',
|
||||||
countdownCode: 'countdown_1',
|
|
||||||
deviceType: 'WH',
|
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -170,7 +170,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadScenes(
|
Future<void> _onLoadScenes(
|
||||||
LoadScenes event, Emitter<RoutineState> emit) async {
|
LoadScenes event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
@ -208,7 +208,7 @@ Future<void> _onLoadScenes(
|
|||||||
loadAutomationErrorMessage: '',
|
loadAutomationErrorMessage: '',
|
||||||
scenes: scenes));
|
scenes: scenes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadAutomation(
|
Future<void> _onLoadAutomation(
|
||||||
LoadAutomation event, Emitter<RoutineState> emit) async {
|
LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||||
@ -936,16 +936,12 @@ Future<void> _onLoadScenes(
|
|||||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
for (var spaceId in spacesList) {
|
|
||||||
devices.addAll(await DevicesManagementApi()
|
devices.addAll(await DevicesManagementApi()
|
||||||
.fetchDevices(communityId, spaceId, projectUuid));
|
.fetchDevices(projectUuid, spacesId: spacesList));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
devices.addAll(await DevicesManagementApi().fetchDevices(projectUuid,
|
||||||
createRoutineBloc.selectedCommunityId,
|
spacesId: [createRoutineBloc.selectedSpaceId]));
|
||||||
createRoutineBloc.selectedSpaceId,
|
|
||||||
projectUuid));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(state.copyWith(isLoading: false, devices: devices));
|
emit(state.copyWith(isLoading: false, devices: devices));
|
||||||
|
|||||||
@ -58,9 +58,7 @@ class CurtainHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
DialogHeader(dialogType == 'THEN'
|
const DialogHeader('AC Functions'),
|
||||||
? 'Curtain Functions'
|
|
||||||
: 'Curtain Conditions'),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
|||||||
@ -58,14 +58,11 @@ class ProductModel {
|
|||||||
'3G': Assets.Gang3SwitchIcon,
|
'3G': Assets.Gang3SwitchIcon,
|
||||||
'3GT': Assets.threeTouchSwitch,
|
'3GT': Assets.threeTouchSwitch,
|
||||||
'CUR': Assets.curtain,
|
'CUR': Assets.curtain,
|
||||||
'CUR_2': Assets.curtain,
|
|
||||||
'GD': Assets.garageDoor,
|
'GD': Assets.garageDoor,
|
||||||
'GW': Assets.SmartGatewayIcon,
|
'GW': Assets.SmartGatewayIcon,
|
||||||
'DL': Assets.DoorLockIcon,
|
'DL': Assets.DoorLockIcon,
|
||||||
'WL': Assets.waterLeakSensor,
|
'WL': Assets.waterLeakSensor,
|
||||||
'WH': Assets.waterHeater,
|
'WH': Assets.waterHeater,
|
||||||
'WM': Assets.waterLeakSensor,
|
|
||||||
'SOS': Assets.sos,
|
|
||||||
'AC': Assets.ac,
|
'AC': Assets.ac,
|
||||||
'CPS': Assets.presenceSensor,
|
'CPS': Assets.presenceSensor,
|
||||||
'PC': Assets.powerClamp,
|
'PC': Assets.powerClamp,
|
||||||
|
|||||||
@ -2,8 +2,10 @@ import 'package:flutter/cupertino.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:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/common/date_time_widget.dart';
|
import 'package:syncrow_web/pages/common/date_time_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_event.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_event.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_state.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_state.dart';
|
||||||
@ -21,8 +23,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
final text = Theme.of(context)
|
var text = Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.bodySmall!
|
.bodySmall!
|
||||||
.copyWith(color: Colors.black, fontSize: 13);
|
.copyWith(color: Colors.black, fontSize: 13);
|
||||||
@ -39,7 +41,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
title: 'Sent Successfully',
|
title: 'Sent Successfully',
|
||||||
widgeta: Column(
|
widgeta: Column(
|
||||||
children: [
|
children: [
|
||||||
if (visitorBloc.passwordStatus!.failedOperations.isNotEmpty)
|
if (visitorBloc
|
||||||
|
.passwordStatus!.failedOperations.isNotEmpty)
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
const Text('Failed Devices'),
|
const Text('Failed Devices'),
|
||||||
@ -53,19 +56,22 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
.passwordStatus!.failedOperations.length,
|
.passwordStatus!.failedOperations.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.all(5),
|
margin: EdgeInsets.all(5),
|
||||||
decoration: containerDecoration,
|
decoration: containerDecoration,
|
||||||
height: 45,
|
height: 45,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(visitorBloc.passwordStatus!
|
child: Text(visitorBloc
|
||||||
.failedOperations[index].deviceName)),
|
.passwordStatus!
|
||||||
|
.failedOperations[index]
|
||||||
|
.deviceName)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (visitorBloc.passwordStatus!.successOperations.isNotEmpty)
|
if (visitorBloc
|
||||||
|
.passwordStatus!.successOperations.isNotEmpty)
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
const Text('Success Devices'),
|
const Text('Success Devices'),
|
||||||
@ -79,12 +85,14 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
.passwordStatus!.successOperations.length,
|
.passwordStatus!.successOperations.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.all(5),
|
margin: EdgeInsets.all(5),
|
||||||
decoration: containerDecoration,
|
decoration: containerDecoration,
|
||||||
height: 45,
|
height: 45,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(visitorBloc.passwordStatus!
|
child: Text(visitorBloc
|
||||||
.successOperations[index].deviceName)),
|
.passwordStatus!
|
||||||
|
.successOperations[index]
|
||||||
|
.deviceName)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -107,14 +115,16 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
|
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
|
||||||
builder: (BuildContext context, VisitorPasswordState state) {
|
builder: (BuildContext context, VisitorPasswordState state) {
|
||||||
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
|
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
|
||||||
final isRepeat =
|
bool isRepeat =
|
||||||
state is IsRepeatState ? state.repeat : visitorBloc.repeat;
|
state is IsRepeatState ? state.repeat : visitorBloc.repeat;
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
title: Text(
|
title: Text(
|
||||||
'Create visitor password',
|
'Create visitor password',
|
||||||
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
|
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
|
||||||
fontWeight: FontWeight.w400, fontSize: 24, color: Colors.black),
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 24,
|
||||||
|
color: Colors.black),
|
||||||
),
|
),
|
||||||
content: state is LoadingInitialState
|
content: state is LoadingInitialState
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator())
|
||||||
@ -300,9 +310,11 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
visitorBloc.accessTypeSelected ==
|
visitorBloc.accessTypeSelected ==
|
||||||
'Offline Password') {
|
'Offline Password') {
|
||||||
visitorBloc.add(SelectTimeEvent(
|
visitorBloc.add(SelectTimeEvent(
|
||||||
context: context, isEffective: false));
|
context: context,
|
||||||
|
isEffective: false));
|
||||||
} else {
|
} else {
|
||||||
visitorBloc.add(SelectTimeVisitorPassword(
|
visitorBloc.add(
|
||||||
|
SelectTimeVisitorPassword(
|
||||||
context: context,
|
context: context,
|
||||||
isStart: false,
|
isStart: false,
|
||||||
isRepeat: false));
|
isRepeat: false));
|
||||||
@ -314,28 +326,31 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
visitorBloc.accessTypeSelected ==
|
visitorBloc.accessTypeSelected ==
|
||||||
'Offline Password') {
|
'Offline Password') {
|
||||||
visitorBloc.add(SelectTimeEvent(
|
visitorBloc.add(SelectTimeEvent(
|
||||||
context: context, isEffective: true));
|
context: context,
|
||||||
|
isEffective: true));
|
||||||
} else {
|
} else {
|
||||||
visitorBloc.add(SelectTimeVisitorPassword(
|
visitorBloc.add(
|
||||||
|
SelectTimeVisitorPassword(
|
||||||
context: context,
|
context: context,
|
||||||
isStart: true,
|
isStart: true,
|
||||||
isRepeat: false));
|
isRepeat: false));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
firstString:
|
firstString: (visitorBloc
|
||||||
(visitorBloc.usageFrequencySelected ==
|
.usageFrequencySelected ==
|
||||||
'Periodic' &&
|
'Periodic' &&
|
||||||
visitorBloc.accessTypeSelected ==
|
visitorBloc.accessTypeSelected ==
|
||||||
'Offline Password')
|
'Offline Password')
|
||||||
? visitorBloc.effectiveTime
|
? visitorBloc.effectiveTime
|
||||||
: visitorBloc.startTimeAccess,
|
: visitorBloc.startTimeAccess
|
||||||
|
.toString(),
|
||||||
secondString: (visitorBloc
|
secondString: (visitorBloc
|
||||||
.usageFrequencySelected ==
|
.usageFrequencySelected ==
|
||||||
'Periodic' &&
|
'Periodic' &&
|
||||||
visitorBloc.accessTypeSelected ==
|
visitorBloc.accessTypeSelected ==
|
||||||
'Offline Password')
|
'Offline Password')
|
||||||
? visitorBloc.expirationTime
|
? visitorBloc.expirationTime
|
||||||
: visitorBloc.endTimeAccess,
|
: visitorBloc.endTimeAccess.toString(),
|
||||||
icon: Assets.calendarIcon),
|
icon: Assets.calendarIcon),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 10,
|
height: 10,
|
||||||
@ -395,7 +410,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
child: CupertinoSwitch(
|
child: CupertinoSwitch(
|
||||||
value: visitorBloc.repeat,
|
value: visitorBloc.repeat,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
visitorBloc.add(ToggleRepeatEvent());
|
visitorBloc
|
||||||
|
.add(ToggleRepeatEvent());
|
||||||
},
|
},
|
||||||
applyTheme: true,
|
applyTheme: true,
|
||||||
),
|
),
|
||||||
@ -426,7 +442,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
).then((listDevice) {
|
).then((listDevice) {
|
||||||
if (listDevice != null) {
|
if (listDevice != null) {
|
||||||
visitorBloc.selectedDevices = listDevice;
|
visitorBloc.selectedDevices =
|
||||||
|
listDevice;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -438,7 +455,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
.bodySmall!
|
.bodySmall!
|
||||||
.copyWith(
|
.copyWith(
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
color: ColorsManager.whiteColors,
|
color:
|
||||||
|
ColorsManager.whiteColors,
|
||||||
fontSize: 12),
|
fontSize: 12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -477,30 +495,37 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (visitorBloc.forgetFormKey.currentState!.validate()) {
|
if (visitorBloc.forgetFormKey.currentState!.validate()) {
|
||||||
if (visitorBloc.selectedDevices.isNotEmpty) {
|
if (visitorBloc.selectedDevices.isNotEmpty) {
|
||||||
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
|
if (visitorBloc.usageFrequencySelected ==
|
||||||
visitorBloc.accessTypeSelected == 'Offline Password') {
|
'One-Time' &&
|
||||||
|
visitorBloc.accessTypeSelected ==
|
||||||
|
'Offline Password') {
|
||||||
setPasswordFunction(context, size, visitorBloc);
|
setPasswordFunction(context, size, visitorBloc);
|
||||||
} else if (visitorBloc.usageFrequencySelected ==
|
} else if (visitorBloc.usageFrequencySelected ==
|
||||||
'Periodic' &&
|
'Periodic' &&
|
||||||
visitorBloc.accessTypeSelected == 'Offline Password') {
|
visitorBloc.accessTypeSelected ==
|
||||||
|
'Offline Password') {
|
||||||
if (visitorBloc.expirationTime != 'End Time' &&
|
if (visitorBloc.expirationTime != 'End Time' &&
|
||||||
visitorBloc.effectiveTime != 'Start Time') {
|
visitorBloc.effectiveTime != 'Start Time') {
|
||||||
setPasswordFunction(context, size, visitorBloc);
|
setPasswordFunction(context, size, visitorBloc);
|
||||||
} else {
|
} else {
|
||||||
visitorBloc.stateDialog(
|
visitorBloc.stateDialog(
|
||||||
context: context,
|
context: context,
|
||||||
message: 'Please select Access Period to continue',
|
message:
|
||||||
|
'Please select Access Period to continue',
|
||||||
title: 'Access Period');
|
title: 'Access Period');
|
||||||
}
|
}
|
||||||
} else if (visitorBloc.endTimeAccess != 'End Time' &&
|
} else if (visitorBloc.endTimeAccess.toString() !=
|
||||||
visitorBloc.startTimeAccess != 'Start Time') {
|
'End Time' &&
|
||||||
|
visitorBloc.startTimeAccess.toString() !=
|
||||||
|
'Start Time') {
|
||||||
if (visitorBloc.effectiveTimeTimeStamp != null &&
|
if (visitorBloc.effectiveTimeTimeStamp != null &&
|
||||||
visitorBloc.expirationTimeTimeStamp != null) {
|
visitorBloc.expirationTimeTimeStamp != null) {
|
||||||
if (isRepeat == true) {
|
if (isRepeat == true) {
|
||||||
if (visitorBloc.expirationTime != 'End Time' &&
|
if (visitorBloc.expirationTime != 'End Time' &&
|
||||||
visitorBloc.effectiveTime != 'Start Time' &&
|
visitorBloc.effectiveTime != 'Start Time' &&
|
||||||
visitorBloc.selectedDays.isNotEmpty) {
|
visitorBloc.selectedDays.isNotEmpty) {
|
||||||
setPasswordFunction(context, size, visitorBloc);
|
setPasswordFunction(
|
||||||
|
context, size, visitorBloc);
|
||||||
} else {
|
} else {
|
||||||
visitorBloc.stateDialog(
|
visitorBloc.stateDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -514,13 +539,15 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
} else {
|
} else {
|
||||||
visitorBloc.stateDialog(
|
visitorBloc.stateDialog(
|
||||||
context: context,
|
context: context,
|
||||||
message: 'Please select Access Period to continue',
|
message:
|
||||||
|
'Please select Access Period to continue',
|
||||||
title: 'Access Period');
|
title: 'Access Period');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
visitorBloc.stateDialog(
|
visitorBloc.stateDialog(
|
||||||
context: context,
|
context: context,
|
||||||
message: 'Please select Access Period to continue',
|
message:
|
||||||
|
'Please select Access Period to continue',
|
||||||
title: 'Access Period');
|
title: 'Access Period');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -566,17 +593,17 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: size.height * 0.25,
|
height: size.height * 0.25,
|
||||||
child: const Center(
|
child: Center(
|
||||||
child: CircularProgressIndicator(), // Display a loading spinner
|
child:
|
||||||
|
CircularProgressIndicator(), // Display a loading spinner
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
backgroundColor: Colors.white,
|
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: size.height * 0.13,
|
height: size.height * 0.25,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
@ -590,16 +617,13 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
width: 35,
|
width: 35,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
Text(
|
Text(
|
||||||
'Set Password',
|
'Set Password',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.headlineLarge!
|
.headlineLarge!
|
||||||
.copyWith(
|
.copyWith(
|
||||||
fontSize: 24,
|
fontSize: 30,
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
),
|
),
|
||||||
@ -607,6 +631,15 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 15),
|
const SizedBox(width: 15),
|
||||||
|
Text(
|
||||||
|
'This action will update all of the selected\n door locks passwords in the property.\n\nAre you sure you want to continue?',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -635,12 +668,12 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
decoration: containerDecoration,
|
decoration: containerDecoration,
|
||||||
width: size.width * 0.1,
|
width: size.width * 0.1,
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
backgroundColor: Color(0xff023DFE),
|
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
|
if (visitorBloc.usageFrequencySelected == 'One-Time' &&
|
||||||
visitorBloc.accessTypeSelected == 'Online Password') {
|
visitorBloc.accessTypeSelected ==
|
||||||
|
'Online Password') {
|
||||||
visitorBloc.add(OnlineOneTimePasswordEvent(
|
visitorBloc.add(OnlineOneTimePasswordEvent(
|
||||||
context: context,
|
context: context,
|
||||||
passwordName: visitorBloc.userNameController.text,
|
passwordName: visitorBloc.userNameController.text,
|
||||||
@ -648,7 +681,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
));
|
));
|
||||||
} else if (visitorBloc.usageFrequencySelected ==
|
} else if (visitorBloc.usageFrequencySelected ==
|
||||||
'Periodic' &&
|
'Periodic' &&
|
||||||
visitorBloc.accessTypeSelected == 'Online Password') {
|
visitorBloc.accessTypeSelected ==
|
||||||
|
'Online Password') {
|
||||||
visitorBloc.add(OnlineMultipleTimePasswordEvent(
|
visitorBloc.add(OnlineMultipleTimePasswordEvent(
|
||||||
passwordName: visitorBloc.userNameController.text,
|
passwordName: visitorBloc.userNameController.text,
|
||||||
email: visitorBloc.emailController.text,
|
email: visitorBloc.emailController.text,
|
||||||
@ -659,7 +693,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
));
|
));
|
||||||
} else if (visitorBloc.usageFrequencySelected ==
|
} else if (visitorBloc.usageFrequencySelected ==
|
||||||
'One-Time' &&
|
'One-Time' &&
|
||||||
visitorBloc.accessTypeSelected == 'Offline Password') {
|
visitorBloc.accessTypeSelected ==
|
||||||
|
'Offline Password') {
|
||||||
visitorBloc.add(OfflineOneTimePasswordEvent(
|
visitorBloc.add(OfflineOneTimePasswordEvent(
|
||||||
context: context,
|
context: context,
|
||||||
passwordName: visitorBloc.userNameController.text,
|
passwordName: visitorBloc.userNameController.text,
|
||||||
@ -667,7 +702,8 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
));
|
));
|
||||||
} else if (visitorBloc.usageFrequencySelected ==
|
} else if (visitorBloc.usageFrequencySelected ==
|
||||||
'Periodic' &&
|
'Periodic' &&
|
||||||
visitorBloc.accessTypeSelected == 'Offline Password') {
|
visitorBloc.accessTypeSelected ==
|
||||||
|
'Offline Password') {
|
||||||
visitorBloc.add(OfflineMultipleTimePasswordEvent(
|
visitorBloc.add(OfflineMultipleTimePasswordEvent(
|
||||||
passwordName: visitorBloc.userNameController.text,
|
passwordName: visitorBloc.userNameController.text,
|
||||||
email: visitorBloc.emailController.text,
|
email: visitorBloc.emailController.text,
|
||||||
@ -679,7 +715,7 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Confirm',
|
'Ok',
|
||||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
color: ColorsManager.whiteColors,
|
color: ColorsManager.whiteColors,
|
||||||
|
|||||||
@ -13,15 +13,13 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
|
|||||||
|
|
||||||
class DevicesManagementApi {
|
class DevicesManagementApi {
|
||||||
Future<List<AllDevicesModel>> fetchDevices(
|
Future<List<AllDevicesModel>> fetchDevices(
|
||||||
String communityId, String spaceId, String projectId) async {
|
String projectId, {
|
||||||
|
List<String>? spacesId,
|
||||||
|
}) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: communityId.isNotEmpty && spaceId.isNotEmpty
|
queryParameters: {if (spacesId != null) 'spaces': spacesId},
|
||||||
? ApiEndpoints.getSpaceDevices
|
path: ApiEndpoints.getAllDevices.replaceAll('{projectId}', projectId),
|
||||||
.replaceAll('{spaceUuid}', spaceId)
|
|
||||||
.replaceAll('{communityUuid}', communityId)
|
|
||||||
.replaceAll('{projectId}', projectId)
|
|
||||||
: ApiEndpoints.getAllDevices.replaceAll('{projectId}', projectId),
|
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
List<dynamic> jsonData = json['data'];
|
List<dynamic> jsonData = json['data'];
|
||||||
@ -416,5 +414,4 @@ class DevicesManagementApi {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ abstract class ApiEndpoints {
|
|||||||
|
|
||||||
static const String getAllDevices = '/projects/{projectId}/devices';
|
static const String getAllDevices = '/projects/{projectId}/devices';
|
||||||
static const String getSpaceDevices =
|
static const String getSpaceDevices =
|
||||||
'/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/devices';
|
'/projects/{projectId}/devices';
|
||||||
static const String getDeviceStatus = '/devices/{uuid}/functions/status';
|
static const String getDeviceStatus = '/devices/{uuid}/functions/status';
|
||||||
static const String getBatchStatus = '/devices/batch';
|
static const String getBatchStatus = '/devices/batch';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user