61 lines
1.6 KiB
Dart
61 lines
1.6 KiB
Dart
import 'dart:convert';
|
|
|
|
class DetailsModel {
|
|
DetailsModel({
|
|
required this.id,
|
|
required this.name,
|
|
required this.categoryId,
|
|
required this.description,
|
|
// required this.translations,
|
|
});
|
|
|
|
final int id;
|
|
final String name;
|
|
final int categoryId;
|
|
final String description;
|
|
// final List<Translation> translations;
|
|
|
|
factory DetailsModel.fromJson(Map<String, dynamic> json) {
|
|
// final List<Translation> translations = (json['translations'] as List)
|
|
// .map((e) => Translation.fromJson(e))
|
|
// .toList();
|
|
// String language = json['name'] ?? '';
|
|
|
|
// for (Translation item in translations) {
|
|
// if (item.locale == currentLang) language = item.attributeData['name'];
|
|
// }
|
|
return DetailsModel(
|
|
id: json["id"] ?? 0,
|
|
name: json['name'] ?? '',
|
|
description: json["description"] ?? '',
|
|
categoryId: json["category_id"] ?? 0,
|
|
// translations: List<Translation>.from(
|
|
// json["translations"].map((x) => Translation.fromJson(x))),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Translation {
|
|
Translation({
|
|
required this.locale,
|
|
required this.modelId,
|
|
required this.attributeData,
|
|
});
|
|
|
|
final String locale;
|
|
final String modelId;
|
|
final Map attributeData;
|
|
|
|
factory Translation.fromJson(Map<String, dynamic> jsn) => Translation(
|
|
locale: jsn["locale"] ?? '',
|
|
modelId: jsn["model_id"] ?? '',
|
|
attributeData: json.decode(jsn["attribute_data"]),
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"locale": locale,
|
|
"model_id": modelId,
|
|
"attribute_data": attributeData,
|
|
};
|
|
}
|