Files
recipe-app/flutter/lib/features/pantry/domain/pantry_product.dart
T

29 lines
704 B
Dart

class PantryProduct {
final int id;
final String name;
final String? canonicalName;
final String? category;
const PantryProduct({
required this.id,
required this.name,
this.canonicalName,
this.category,
});
String get displayName {
if (canonicalName != null && canonicalName!.trim().isNotEmpty) {
return canonicalName!;
}
return name;
}
factory PantryProduct.fromJson(Map<String, dynamic> json) {
return PantryProduct(
id: (json['id'] as num).toInt(),
name: (json['name'] ?? '').toString(),
canonicalName: json['canonicalName']?.toString(),
category: json['category']?.toString(),
);
}
}