import 'dart:convert'; class CategoryModel { CategoryModel({ required this.id, required this.name, required this.translations, required this.icon, }); final int id; final String name; final List translations; final Iconca icon; factory CategoryModel.fromJson( Map json, String currentLang) { final List 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 CategoryModel( id: json["id"] ?? '', name: language, translations: (json['translations'] as List) .map((e) => Translation.fromJson(e)) .toList(), icon: Iconca.fromJson(json["icon"] ?? ''), ); } } class Iconca { Iconca({ required this.id, required this.path, }); final int id; final String path; factory Iconca.fromJson(Map json) => Iconca( id: json["id"] ?? 0, path: json["path"], ); Map toJson() => { "id": id, "path": path, }; } 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 jsn) => Translation( locale: jsn["locale"], modelId: jsn["model_id"], attributeData: json.decode(jsn["attribute_data"]), ); Map toJson() => { "locale": locale, "model_id": modelId, "attribute_data": attributeData, }; }