Version 1.0.4
Fix handling of kcal amount extraction from json
This commit is contained in:
parent
63e9b471b4
commit
b87c288527
@ -15,6 +15,7 @@ android {
|
||||
namespace = "de.swgross.calorimeter"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
@ -33,8 +34,8 @@ android {
|
||||
applicationId = "de.swgross.calorimeter"
|
||||
minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
versionCode = 3
|
||||
versionName = "1.0.3"
|
||||
versionCode = 4
|
||||
versionName = "1.0.4"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
@ -170,14 +170,10 @@ class FoodEntryBloc extends Bloc<FoodEvent, GlobalEntryState> {
|
||||
return;
|
||||
}
|
||||
|
||||
int kcalToDisplay = response.food?.kcalPer100g ?? 0;
|
||||
if (response.food?.kcalPer100gPrepared != 0) {
|
||||
kcalToDisplay = response.food?.kcalPer100gPrepared ?? 0;
|
||||
}
|
||||
var newEntryFinishedWaiting = FoodEntryState(
|
||||
name: response.food?.name ?? "",
|
||||
mass: response.food?.mass ?? 0,
|
||||
kcalPer100: kcalToDisplay,
|
||||
kcalPer100: response.food?.kcalPer100g ?? 0,
|
||||
waitingForNetwork: false,
|
||||
isSelected: false,
|
||||
);
|
||||
|
@ -47,35 +47,50 @@ class FoodFactLookupClient {
|
||||
class FoodFactModel {
|
||||
final String name;
|
||||
final int kcalPer100g;
|
||||
final int kcalPer100gPrepared;
|
||||
final int mass;
|
||||
|
||||
FoodFactModel({
|
||||
required this.name,
|
||||
required this.mass,
|
||||
required this.kcalPer100g,
|
||||
required this.kcalPer100gPrepared,
|
||||
});
|
||||
|
||||
factory FoodFactModel.fromJson(Map<String, dynamic> json) {
|
||||
int kcalPer100g = json['product']['nutriments']['energy-kcal_100g'] ?? 0;
|
||||
int kcalPer100gPrepared =
|
||||
json['product']['nutriments']['energy-kcal_prepared_100g'] ?? 0;
|
||||
|
||||
String quantityString = json['product']['product_quantity'] ?? "0";
|
||||
int quantity;
|
||||
int kcalPer100gForModel = 0;
|
||||
int kcalPer100g = 0;
|
||||
int kcalPer100gPrepared = 0;
|
||||
|
||||
try {
|
||||
quantity = int.parse(quantityString);
|
||||
kcalPer100g = (json['product']['nutriments']['energy-kcal_100g'] as num)
|
||||
.toDouble()
|
||||
.ceil();
|
||||
kcalPer100gForModel = kcalPer100g;
|
||||
} catch (e) {
|
||||
try {
|
||||
kcalPer100gPrepared =
|
||||
(json['product']['nutriments']['energy-kcal_prepared_100g'] as num)
|
||||
.toDouble()
|
||||
.ceil();
|
||||
kcalPer100gForModel = kcalPer100gPrepared;
|
||||
} catch (e) {
|
||||
kcalPer100gForModel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
String quantityString = json['product']['product_quantity'] ?? "0";
|
||||
double quantity;
|
||||
|
||||
try {
|
||||
quantity = double.parse(quantityString);
|
||||
} catch (e) {
|
||||
quantity = 0;
|
||||
}
|
||||
|
||||
return FoodFactModel(
|
||||
name: json['product']['product_name'] ?? "",
|
||||
kcalPer100g: kcalPer100g,
|
||||
kcalPer100gPrepared: kcalPer100gPrepared,
|
||||
mass: quantity);
|
||||
name: json['product']['product_name'] ?? "",
|
||||
kcalPer100g: kcalPer100gForModel,
|
||||
mass: quantity.ceil(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user