Compare commits

..

No commits in common. "master" and "fix-json-misalignment-and-error-representation" have entirely different histories.

4 changed files with 19 additions and 31 deletions

@ -1 +1 @@
Subproject commit 17025dd88227cd9532c33fa78f5250d548d87e9a Subproject commit dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668

View File

@ -15,7 +15,6 @@ android {
namespace = "de.swgross.calorimeter" namespace = "de.swgross.calorimeter"
compileSdk = flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion ndkVersion = flutter.ndkVersion
dependenciesInfo { dependenciesInfo {
includeInApk = false includeInApk = false
includeInBundle = false includeInBundle = false
@ -34,8 +33,8 @@ android {
applicationId = "de.swgross.calorimeter" applicationId = "de.swgross.calorimeter"
minSdk = flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode = 4 versionCode = 3
versionName = "1.0.4" versionName = "1.0.3"
} }
signingConfigs { signingConfigs {

View File

@ -170,10 +170,14 @@ class FoodEntryBloc extends Bloc<FoodEvent, GlobalEntryState> {
return; return;
} }
int kcalToDisplay = response.food?.kcalPer100g ?? 0;
if (response.food?.kcalPer100gPrepared != 0) {
kcalToDisplay = response.food?.kcalPer100gPrepared ?? 0;
}
var newEntryFinishedWaiting = FoodEntryState( var newEntryFinishedWaiting = FoodEntryState(
name: response.food?.name ?? "", name: response.food?.name ?? "",
mass: response.food?.mass ?? 0, mass: response.food?.mass ?? 0,
kcalPer100: response.food?.kcalPer100g ?? 0, kcalPer100: kcalToDisplay,
waitingForNetwork: false, waitingForNetwork: false,
isSelected: false, isSelected: false,
); );

View File

@ -47,50 +47,35 @@ class FoodFactLookupClient {
class FoodFactModel { class FoodFactModel {
final String name; final String name;
final int kcalPer100g; final int kcalPer100g;
final int kcalPer100gPrepared;
final int mass; final int mass;
FoodFactModel({ FoodFactModel({
required this.name, required this.name,
required this.mass, required this.mass,
required this.kcalPer100g, required this.kcalPer100g,
required this.kcalPer100gPrepared,
}); });
factory FoodFactModel.fromJson(Map<String, dynamic> json) { factory FoodFactModel.fromJson(Map<String, dynamic> json) {
int kcalPer100gForModel = 0; int kcalPer100g = json['product']['nutriments']['energy-kcal_100g'] ?? 0;
int kcalPer100g = 0; int kcalPer100gPrepared =
int kcalPer100gPrepared = 0; json['product']['nutriments']['energy-kcal_prepared_100g'] ?? 0;
try {
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"; String quantityString = json['product']['product_quantity'] ?? "0";
double quantity; int quantity;
try { try {
quantity = double.parse(quantityString); quantity = int.parse(quantityString);
} catch (e) { } catch (e) {
quantity = 0; quantity = 0;
} }
return FoodFactModel( return FoodFactModel(
name: json['product']['product_name'] ?? "", name: json['product']['product_name'] ?? "",
kcalPer100g: kcalPer100gForModel, kcalPer100g: kcalPer100g,
mass: quantity.ceil(), kcalPer100gPrepared: kcalPer100gPrepared,
); mass: quantity);
} }
} }