mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
push functions static data
This commit is contained in:
135
lib/features/scene/model/scene_static_function.dart
Normal file
135
lib/features/scene/model/scene_static_function.dart
Normal file
@ -0,0 +1,135 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class SceneStaticFunction {
|
||||
final String icon;
|
||||
final String name;
|
||||
final String code;
|
||||
final List<StaticFunctionOperationHelper> operationalValues;
|
||||
|
||||
SceneStaticFunction({
|
||||
required this.icon,
|
||||
required this.name,
|
||||
required this.code,
|
||||
required this.operationalValues,
|
||||
});
|
||||
|
||||
SceneStaticFunction copyWith({
|
||||
String? icon,
|
||||
String? name,
|
||||
String? code,
|
||||
List<StaticFunctionOperationHelper>? operationalValues,
|
||||
}) {
|
||||
return SceneStaticFunction(
|
||||
icon: icon ?? this.icon,
|
||||
name: name ?? this.name,
|
||||
code: code ?? this.code,
|
||||
operationalValues: operationalValues ?? this.operationalValues,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'icon': icon,
|
||||
'name': name,
|
||||
'code': code,
|
||||
'operationalValues': operationalValues.map((x) => x.toMap()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
factory SceneStaticFunction.fromMap(Map<String, dynamic> map) {
|
||||
return SceneStaticFunction(
|
||||
icon: map['icon'] ?? '',
|
||||
name: map['name'] ?? '',
|
||||
code: map['code'] ?? '',
|
||||
operationalValues: List<StaticFunctionOperationHelper>.from(
|
||||
map['operationalValues']
|
||||
?.map((x) => StaticFunctionOperationHelper.fromMap(x))),
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory SceneStaticFunction.fromJson(String source) =>
|
||||
SceneStaticFunction.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SceneStaticFunction(icon: $icon, name: $name, code: $code, operationalValues: $operationalValues)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is SceneStaticFunction &&
|
||||
other.icon == icon &&
|
||||
other.name == name &&
|
||||
other.code == code &&
|
||||
listEquals(other.operationalValues, operationalValues);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return icon.hashCode ^
|
||||
name.hashCode ^
|
||||
code.hashCode ^
|
||||
operationalValues.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class StaticFunctionOperationHelper {
|
||||
final String icon;
|
||||
final String value;
|
||||
|
||||
StaticFunctionOperationHelper({
|
||||
required this.icon,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
StaticFunctionOperationHelper copyWith({
|
||||
String? icon,
|
||||
String? value,
|
||||
}) {
|
||||
return StaticFunctionOperationHelper(
|
||||
icon: icon ?? this.icon,
|
||||
value: value ?? this.value,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'icon': icon,
|
||||
'value': value,
|
||||
};
|
||||
}
|
||||
|
||||
factory StaticFunctionOperationHelper.fromMap(Map<String, dynamic> map) {
|
||||
return StaticFunctionOperationHelper(
|
||||
icon: map['icon'] ?? '',
|
||||
value: map['value'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory StaticFunctionOperationHelper.fromJson(String source) =>
|
||||
StaticFunctionOperationHelper.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'StaticFunctionOperationHelper(icon: $icon, value: $value)';
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is StaticFunctionOperationHelper &&
|
||||
other.icon == icon &&
|
||||
other.value == value;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => icon.hashCode ^ value.hashCode;
|
||||
}
|
Reference in New Issue
Block a user