Files
food-ai/client/lib/shared/models/product.dart
dbastrikin 8d33a4eb30 feat: product search screen with catalog add and success feedback
- Add product search screen (/products/search) as primary add flow;
  "Add" button on products list opens search, manual entry remains as fallback
- Add to shelf bottom sheet with AnimatedSwitcher success view (green checkmark)
  and SnackBar confirmation on the search screen via onAdded callback
- Manual add (AddProductScreen) shows SnackBar on success before popping back
- Extend AddProductScreen with optional nutrition fields (calories, protein,
  fat, carbs, fiber); auto-fills from catalog selection and auto-expands section
- Auto-upsert catalog product on backend when nutrition data is provided
  without a primary_product_id, linking the user product to the catalog
- Add fiber_per_100g field to CatalogProduct model and CreateRequest
- Add 16 new L10n keys across all 12 locales (addProduct, addManually,
  searchProducts, quantity, storageDays, addToShelf, nutritionOptional,
  calories, protein, fat, carbs, fiber, productAddedToShelf, etc.)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 14:04:58 +02:00

53 lines
1.4 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
part 'product.g.dart';
/// Catalog product (shared nutrition database entry).
@JsonSerializable()
class CatalogProduct {
final String id;
@JsonKey(name: 'canonical_name')
final String canonicalName;
@JsonKey(name: 'category_name')
final String? categoryName;
final String? category;
@JsonKey(name: 'default_unit')
final String? defaultUnit;
@JsonKey(name: 'storage_days')
final int? storageDays;
final String? barcode;
@JsonKey(name: 'calories_per_100g')
final double? caloriesPer100g;
@JsonKey(name: 'protein_per_100g')
final double? proteinPer100g;
@JsonKey(name: 'fat_per_100g')
final double? fatPer100g;
@JsonKey(name: 'carbs_per_100g')
final double? carbsPer100g;
@JsonKey(name: 'fiber_per_100g')
final double? fiberPer100g;
const CatalogProduct({
required this.id,
required this.canonicalName,
this.categoryName,
this.category,
this.defaultUnit,
this.storageDays,
this.barcode,
this.caloriesPer100g,
this.proteinPer100g,
this.fatPer100g,
this.carbsPer100g,
this.fiberPer100g,
});
/// Display name is the server-resolved canonical name (language-aware from backend).
String get displayName => canonicalName;
factory CatalogProduct.fromJson(Map<String, dynamic> json) =>
_$CatalogProductFromJson(json);
Map<String, dynamic> toJson() => _$CatalogProductToJson(this);
}