mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
working on functions view
This commit is contained in:
58
lib/features/devices/model/functions.dart
Normal file
58
lib/features/devices/model/functions.dart
Normal file
@ -0,0 +1,58 @@
|
||||
class FunctionsEntity {
|
||||
final String productUuid;
|
||||
final String productType;
|
||||
final List<DeviceFunction> functions;
|
||||
|
||||
FunctionsEntity({
|
||||
required this.productUuid,
|
||||
required this.productType,
|
||||
required this.functions,
|
||||
});
|
||||
|
||||
factory FunctionsEntity.fromJson(Map<String, dynamic> json) =>
|
||||
FunctionsEntity(
|
||||
productUuid: json["productUuid"],
|
||||
productType: json["productType"],
|
||||
functions: List<DeviceFunction>.from(
|
||||
json["functions"].map((x) => DeviceFunction.fromJson(x)),
|
||||
),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"productUuid": productUuid,
|
||||
"productType": productType,
|
||||
"functions": List<dynamic>.from(functions.map((x) => x.toJson())),
|
||||
};
|
||||
}
|
||||
|
||||
class DeviceFunction {
|
||||
final String code;
|
||||
final String values;
|
||||
final String dataType;
|
||||
|
||||
DeviceFunction({
|
||||
required this.code,
|
||||
required this.values,
|
||||
required this.dataType,
|
||||
});
|
||||
|
||||
factory DeviceFunction.fromJson(Map<String, dynamic> json) => DeviceFunction(
|
||||
code: _formatCode(json["code"]),
|
||||
values: json["values"],
|
||||
dataType: json["dataType"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"code": code,
|
||||
"values": values,
|
||||
"dataType": dataType,
|
||||
};
|
||||
|
||||
static String _formatCode(String originalCode) {
|
||||
return originalCode
|
||||
.replaceAll('_', ' ')
|
||||
.split(' ')
|
||||
.map((word) => word[0].toUpperCase() + word.substring(1))
|
||||
.join(' ');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user