/opt/canhelp/apps/mobile/lib/models
Edit: /opt/canhelp/apps/mobile/lib/models/category.dart (1294B)
class Category {
final String id;
final String slug;
final String icon;
final Map
names;
final String? parentId;
final List children;
Category({
required this.id,
required this.slug,
required this.icon,
required this.names,
this.parentId,
this.children = const [],
});
String nameFor(String locale) =>
names[locale] ?? names['el'] ?? names.values.firstOrNull ?? slug;
bool get hasRemoteIcon {
final value = icon.trim();
return value.startsWith('/') ||
value.startsWith('http://') ||
value.startsWith('https://');
}
String get uiIcon => hasRemoteIcon ? '' : icon;
factory Category.fromJson(Map json) {
final rawNames = json['names'] as Map?;
final names = rawNames?.map((k, v) => MapEntry(k, v as String)) ?? {};
final rawChildren = json['children'] as List?;
return Category(
id: json['id'] as String,
slug: json['slug'] as String? ?? '',
icon: json['icon'] as String? ?? '',
names: names,
parentId: json['parentId'] as String?,
children:
rawChildren
?.map((e) => Category.fromJson(e as Map))
.toList() ??
[],
);
}
}