Merge pull request 'main' (#1) from eatvio/eatvio_app:main into main

Reviewed-on: mso7nueh/eatvio_app#1
This commit is contained in:
mso7nueh
2025-05-21 08:29:58 +00:00
13 changed files with 473 additions and 193 deletions

View File

@@ -132,6 +132,12 @@ enum Portion {
return null;
}
}
String getValue() => switch (this) {
Portion.grams => 'gr',
Portion.milliliters => 'milliliters',
Portion.pcs => 'pcs',
};
}
@freezed

View File

@@ -63,7 +63,7 @@ PlanType planTypeFromJson(dynamic json) {
@freezed
class PacketOptions with _$PacketOptions {
const factory PacketOptions({
@JsonKey(name: "items") required List<String> items,
@JsonKey(name: "items", fromJson: _parseItems) required List<String> items,
@JsonKey(name: "price") required dynamic price,
@JsonKey(name: "short") required String short,
@JsonKey(name: "description_md") required String description,
@@ -71,7 +71,14 @@ class PacketOptions with _$PacketOptions {
factory PacketOptions.fromJson(Map<String, dynamic> json) => _$PacketOptionsFromJson(json);
factory PacketOptions.empty() => const PacketOptions(items: [], price: 1200, short: '', description: '');
factory PacketOptions.empty() => PacketOptions(items: [], price: double.parse('1200'), short: '', description: '');
}
List<String> _parseItems(json) {
if (json is Map<String, dynamic>) {
return json.values.map((e) => e as String).toList();
}
return (json as List<dynamic>).map((e) => e as String).toList();
}
@freezed

View File

@@ -44,11 +44,21 @@ class Tag with _$Tag {
@freezed
class Ingredient with _$Ingredient {
const factory Ingredient({required String name, String? unit, required String portion}) = _Ingredient;
const factory Ingredient({
required String name,
String? unit,
required String portion,
@JsonKey(name: 'product_nutritional_id', fromJson: _parseProductId) required int productId,
}) = _Ingredient;
factory Ingredient.fromJson(Map<String, Object?> json) => _$IngredientFromJson(json);
}
int _parseProductId(json) {
if (json is String) {
return int.parse(json);
}
return json as int;
}
@freezed
class Step with _$Step {
const factory Step({required String image, @JsonKey(name: 'description_md') required String description}) = _Step;