mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 10:06:16 +00:00
finished adding tasks and removing them , added error handling
This commit is contained in:
@ -1,51 +1,65 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class SceneStaticFunction {
|
||||
final String icon;
|
||||
final String name;
|
||||
final String deviceName;
|
||||
final String code;
|
||||
final List<StaticFunctionOperationHelper> operationalValues;
|
||||
final List<SceneOperationalValue> operationalValues;
|
||||
final String deviceId;
|
||||
final String operationName;
|
||||
final String uniqueCustomId;
|
||||
|
||||
SceneStaticFunction({
|
||||
required this.icon,
|
||||
required this.name,
|
||||
required this.deviceName,
|
||||
required this.code,
|
||||
required this.operationalValues,
|
||||
});
|
||||
required this.deviceId,
|
||||
required this.operationName,
|
||||
}) : uniqueCustomId = const Uuid().v4();
|
||||
|
||||
SceneStaticFunction copyWith({
|
||||
String? icon,
|
||||
String? name,
|
||||
String? code,
|
||||
List<StaticFunctionOperationHelper>? operationalValues,
|
||||
List<SceneOperationalValue>? operationalValues,
|
||||
String? deviceId,
|
||||
String? operationName,
|
||||
}) {
|
||||
return SceneStaticFunction(
|
||||
icon: icon ?? this.icon,
|
||||
name: name ?? this.name,
|
||||
deviceName: name ?? this.deviceName,
|
||||
code: code ?? this.code,
|
||||
operationalValues: operationalValues ?? this.operationalValues,
|
||||
deviceId: deviceId ?? this.deviceId,
|
||||
operationName: operationName ?? this.operationName,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'icon': icon,
|
||||
'name': name,
|
||||
'name': deviceName,
|
||||
'code': code,
|
||||
'operationalValues': operationalValues.map((x) => x.toMap()).toList(),
|
||||
'deviceId': deviceId,
|
||||
'operationName': operationName
|
||||
};
|
||||
}
|
||||
|
||||
factory SceneStaticFunction.fromMap(Map<String, dynamic> map) {
|
||||
return SceneStaticFunction(
|
||||
icon: map['icon'] ?? '',
|
||||
name: map['name'] ?? '',
|
||||
deviceName: map['name'] ?? '',
|
||||
code: map['code'] ?? '',
|
||||
operationalValues: List<StaticFunctionOperationHelper>.from(
|
||||
map['operationalValues']
|
||||
?.map((x) => StaticFunctionOperationHelper.fromMap(x))),
|
||||
operationalValues: List<SceneOperationalValue>.from(
|
||||
map['operationalValues']?.map((x) => SceneOperationalValue.fromMap(x)),
|
||||
),
|
||||
deviceId: map['deviceId'] ?? '',
|
||||
operationName: map['operationName'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@ -56,7 +70,7 @@ class SceneStaticFunction {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SceneStaticFunction(icon: $icon, name: $name, code: $code, operationalValues: $operationalValues)';
|
||||
return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName)';
|
||||
}
|
||||
|
||||
@override
|
||||
@ -65,34 +79,38 @@ class SceneStaticFunction {
|
||||
|
||||
return other is SceneStaticFunction &&
|
||||
other.icon == icon &&
|
||||
other.name == name &&
|
||||
other.deviceName == deviceName &&
|
||||
other.code == code &&
|
||||
listEquals(other.operationalValues, operationalValues);
|
||||
other.operationName == operationName &&
|
||||
listEquals(other.operationalValues, operationalValues) &&
|
||||
other.deviceId == deviceId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return icon.hashCode ^
|
||||
name.hashCode ^
|
||||
deviceName.hashCode ^
|
||||
code.hashCode ^
|
||||
deviceId.hashCode ^
|
||||
operationName.hashCode ^
|
||||
operationalValues.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class StaticFunctionOperationHelper {
|
||||
class SceneOperationalValue {
|
||||
final String icon;
|
||||
final String value;
|
||||
|
||||
StaticFunctionOperationHelper({
|
||||
SceneOperationalValue({
|
||||
required this.icon,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
StaticFunctionOperationHelper copyWith({
|
||||
SceneOperationalValue copyWith({
|
||||
String? icon,
|
||||
String? value,
|
||||
}) {
|
||||
return StaticFunctionOperationHelper(
|
||||
return SceneOperationalValue(
|
||||
icon: icon ?? this.icon,
|
||||
value: value ?? this.value,
|
||||
);
|
||||
@ -105,8 +123,8 @@ class StaticFunctionOperationHelper {
|
||||
};
|
||||
}
|
||||
|
||||
factory StaticFunctionOperationHelper.fromMap(Map<String, dynamic> map) {
|
||||
return StaticFunctionOperationHelper(
|
||||
factory SceneOperationalValue.fromMap(Map<String, dynamic> map) {
|
||||
return SceneOperationalValue(
|
||||
icon: map['icon'] ?? '',
|
||||
value: map['value'] ?? '',
|
||||
);
|
||||
@ -114,8 +132,8 @@ class StaticFunctionOperationHelper {
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory StaticFunctionOperationHelper.fromJson(String source) =>
|
||||
StaticFunctionOperationHelper.fromMap(json.decode(source));
|
||||
factory SceneOperationalValue.fromJson(String source) =>
|
||||
SceneOperationalValue.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
@ -125,7 +143,7 @@ class StaticFunctionOperationHelper {
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is StaticFunctionOperationHelper &&
|
||||
return other is SceneOperationalValue &&
|
||||
other.icon == icon &&
|
||||
other.value == value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user