✨ Setup data
This commit is contained in:
402
lib/models/food_data.dart
Normal file
402
lib/models/food_data.dart
Normal file
@ -0,0 +1,402 @@
|
||||
class FoodDataQueryResponse {
|
||||
int totalHits;
|
||||
int currentPage;
|
||||
int totalPages;
|
||||
List<int> pageList;
|
||||
FoodSearchCriteria foodSearchCriteria;
|
||||
List<FoodData> foods;
|
||||
Aggregations aggregations;
|
||||
|
||||
FoodDataQueryResponse({
|
||||
required this.totalHits,
|
||||
required this.currentPage,
|
||||
required this.totalPages,
|
||||
required this.pageList,
|
||||
required this.foodSearchCriteria,
|
||||
required this.foods,
|
||||
required this.aggregations,
|
||||
});
|
||||
|
||||
factory FoodDataQueryResponse.fromJson(Map<String, dynamic> json) =>
|
||||
FoodDataQueryResponse(
|
||||
totalHits: json["totalHits"],
|
||||
currentPage: json["currentPage"],
|
||||
totalPages: json["totalPages"],
|
||||
pageList: List<int>.from(json["pageList"].map((x) => x)),
|
||||
foodSearchCriteria:
|
||||
FoodSearchCriteria.fromJson(json["foodSearchCriteria"]),
|
||||
foods:
|
||||
List<FoodData>.from(json["foods"].map((x) => FoodData.fromJson(x))),
|
||||
aggregations: Aggregations.fromJson(json["aggregations"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"totalHits": totalHits,
|
||||
"currentPage": currentPage,
|
||||
"totalPages": totalPages,
|
||||
"pageList": List<dynamic>.from(pageList.map((x) => x)),
|
||||
"foodSearchCriteria": foodSearchCriteria.toJson(),
|
||||
"foods": List<dynamic>.from(foods.map((x) => x.toJson())),
|
||||
"aggregations": aggregations.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class Aggregations {
|
||||
DataType dataType;
|
||||
Nutrients nutrients;
|
||||
|
||||
Aggregations({
|
||||
required this.dataType,
|
||||
required this.nutrients,
|
||||
});
|
||||
|
||||
factory Aggregations.fromJson(Map<String, dynamic> json) => Aggregations(
|
||||
dataType: DataType.fromJson(json["dataType"]),
|
||||
nutrients: Nutrients.fromJson(json["nutrients"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"dataType": dataType.toJson(),
|
||||
"nutrients": nutrients.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class DataType {
|
||||
int branded;
|
||||
int surveyFndds;
|
||||
int srLegacy;
|
||||
int foundation;
|
||||
|
||||
DataType({
|
||||
required this.branded,
|
||||
required this.surveyFndds,
|
||||
required this.srLegacy,
|
||||
required this.foundation,
|
||||
});
|
||||
|
||||
factory DataType.fromJson(Map<String, dynamic> json) => DataType(
|
||||
branded: json["Branded"],
|
||||
surveyFndds: json["Survey (FNDDS)"],
|
||||
srLegacy: json["SR Legacy"],
|
||||
foundation: json["Foundation"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"Branded": branded,
|
||||
"Survey (FNDDS)": surveyFndds,
|
||||
"SR Legacy": srLegacy,
|
||||
"Foundation": foundation,
|
||||
};
|
||||
}
|
||||
|
||||
class Nutrients {
|
||||
Nutrients();
|
||||
|
||||
factory Nutrients.fromJson(Map<String, dynamic> json) => Nutrients();
|
||||
|
||||
Map<String, dynamic> toJson() => {};
|
||||
}
|
||||
|
||||
class FoodSearchCriteria {
|
||||
List<Type> dataType;
|
||||
String query;
|
||||
String generalSearchInput;
|
||||
int pageNumber;
|
||||
String sortBy;
|
||||
String sortOrder;
|
||||
int numberOfResultsPerPage;
|
||||
int pageSize;
|
||||
bool requireAllWords;
|
||||
List<Type> foodTypes;
|
||||
|
||||
FoodSearchCriteria({
|
||||
required this.dataType,
|
||||
required this.query,
|
||||
required this.generalSearchInput,
|
||||
required this.pageNumber,
|
||||
required this.sortBy,
|
||||
required this.sortOrder,
|
||||
required this.numberOfResultsPerPage,
|
||||
required this.pageSize,
|
||||
required this.requireAllWords,
|
||||
required this.foodTypes,
|
||||
});
|
||||
|
||||
factory FoodSearchCriteria.fromJson(Map<String, dynamic> json) =>
|
||||
FoodSearchCriteria(
|
||||
dataType:
|
||||
List<Type>.from(json["dataType"].map((x) => typeValues.map[x]!)),
|
||||
query: json["query"],
|
||||
generalSearchInput: json["generalSearchInput"],
|
||||
pageNumber: json["pageNumber"],
|
||||
sortBy: json["sortBy"],
|
||||
sortOrder: json["sortOrder"],
|
||||
numberOfResultsPerPage: json["numberOfResultsPerPage"],
|
||||
pageSize: json["pageSize"],
|
||||
requireAllWords: json["requireAllWords"],
|
||||
foodTypes:
|
||||
List<Type>.from(json["foodTypes"].map((x) => typeValues.map[x]!)),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"dataType":
|
||||
List<dynamic>.from(dataType.map((x) => typeValues.reverse[x])),
|
||||
"query": query,
|
||||
"generalSearchInput": generalSearchInput,
|
||||
"pageNumber": pageNumber,
|
||||
"sortBy": sortBy,
|
||||
"sortOrder": sortOrder,
|
||||
"numberOfResultsPerPage": numberOfResultsPerPage,
|
||||
"pageSize": pageSize,
|
||||
"requireAllWords": requireAllWords,
|
||||
"foodTypes":
|
||||
List<dynamic>.from(foodTypes.map((x) => typeValues.reverse[x])),
|
||||
};
|
||||
}
|
||||
|
||||
enum Type { FOUNDATION, SR_LEGACY }
|
||||
|
||||
final typeValues =
|
||||
EnumValues({"Foundation": Type.FOUNDATION, "SR Legacy": Type.SR_LEGACY});
|
||||
|
||||
class FoodData {
|
||||
int fdcId;
|
||||
String description;
|
||||
String commonNames;
|
||||
String additionalDescriptions;
|
||||
Type dataType;
|
||||
int ndbNumber;
|
||||
DateTime publishedDate;
|
||||
FoodCategory? foodCategory;
|
||||
DateTime? mostRecentAcquisitionDate;
|
||||
String allHighlightFields;
|
||||
double score;
|
||||
List<dynamic> microbes;
|
||||
List<FoodNutrient> foodNutrients;
|
||||
List<dynamic> finalFoodInputFoods;
|
||||
List<dynamic> foodMeasures;
|
||||
List<dynamic> foodAttributes;
|
||||
List<dynamic> foodAttributeTypes;
|
||||
List<dynamic> foodVersionIds;
|
||||
|
||||
FoodData({
|
||||
required this.fdcId,
|
||||
required this.description,
|
||||
required this.commonNames,
|
||||
required this.additionalDescriptions,
|
||||
required this.dataType,
|
||||
required this.ndbNumber,
|
||||
required this.publishedDate,
|
||||
required this.foodCategory,
|
||||
this.mostRecentAcquisitionDate,
|
||||
required this.allHighlightFields,
|
||||
required this.score,
|
||||
required this.microbes,
|
||||
required this.foodNutrients,
|
||||
required this.finalFoodInputFoods,
|
||||
required this.foodMeasures,
|
||||
required this.foodAttributes,
|
||||
required this.foodAttributeTypes,
|
||||
required this.foodVersionIds,
|
||||
});
|
||||
|
||||
factory FoodData.fromJson(Map<String, dynamic> json) => FoodData(
|
||||
fdcId: json["fdcId"],
|
||||
description: json["description"],
|
||||
commonNames: json["commonNames"],
|
||||
additionalDescriptions: json["additionalDescriptions"],
|
||||
dataType: typeValues.map[json["dataType"]]!,
|
||||
ndbNumber: json["ndbNumber"],
|
||||
publishedDate: DateTime.parse(json["publishedDate"]),
|
||||
foodCategory: foodCategoryValues.map[json["foodCategory"]],
|
||||
mostRecentAcquisitionDate: json["mostRecentAcquisitionDate"] == null
|
||||
? null
|
||||
: DateTime.parse(json["mostRecentAcquisitionDate"]),
|
||||
allHighlightFields: json["allHighlightFields"],
|
||||
score: json["score"]?.toDouble(),
|
||||
microbes: List<dynamic>.from(json["microbes"].map((x) => x)),
|
||||
foodNutrients: List<FoodNutrient>.from(
|
||||
json["foodNutrients"].map((x) => FoodNutrient.fromJson(x))),
|
||||
finalFoodInputFoods:
|
||||
List<dynamic>.from(json["finalFoodInputFoods"].map((x) => x)),
|
||||
foodMeasures: List<dynamic>.from(json["foodMeasures"].map((x) => x)),
|
||||
foodAttributes:
|
||||
List<dynamic>.from(json["foodAttributes"].map((x) => x)),
|
||||
foodAttributeTypes:
|
||||
List<dynamic>.from(json["foodAttributeTypes"].map((x) => x)),
|
||||
foodVersionIds:
|
||||
List<dynamic>.from(json["foodVersionIds"].map((x) => x)),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"fdcId": fdcId,
|
||||
"description": description,
|
||||
"commonNames": commonNames,
|
||||
"additionalDescriptions": additionalDescriptions,
|
||||
"dataType": typeValues.reverse[dataType],
|
||||
"ndbNumber": ndbNumber,
|
||||
"publishedDate":
|
||||
"${publishedDate.year.toString().padLeft(4, '0')}-${publishedDate.month.toString().padLeft(2, '0')}-${publishedDate.day.toString().padLeft(2, '0')}",
|
||||
"foodCategory": foodCategoryValues.reverse[foodCategory],
|
||||
"mostRecentAcquisitionDate":
|
||||
"${mostRecentAcquisitionDate!.year.toString().padLeft(4, '0')}-${mostRecentAcquisitionDate!.month.toString().padLeft(2, '0')}-${mostRecentAcquisitionDate!.day.toString().padLeft(2, '0')}",
|
||||
"allHighlightFields": allHighlightFields,
|
||||
"score": score,
|
||||
"microbes": List<dynamic>.from(microbes.map((x) => x)),
|
||||
"foodNutrients":
|
||||
List<dynamic>.from(foodNutrients.map((x) => x.toJson())),
|
||||
"finalFoodInputFoods":
|
||||
List<dynamic>.from(finalFoodInputFoods.map((x) => x)),
|
||||
"foodMeasures": List<dynamic>.from(foodMeasures.map((x) => x)),
|
||||
"foodAttributes": List<dynamic>.from(foodAttributes.map((x) => x)),
|
||||
"foodAttributeTypes":
|
||||
List<dynamic>.from(foodAttributeTypes.map((x) => x)),
|
||||
"foodVersionIds": List<dynamic>.from(foodVersionIds.map((x) => x)),
|
||||
};
|
||||
}
|
||||
|
||||
enum FoodCategory { DAIRY_AND_EGG_PRODUCTS }
|
||||
|
||||
final foodCategoryValues =
|
||||
EnumValues({"Dairy and Egg Products": FoodCategory.DAIRY_AND_EGG_PRODUCTS});
|
||||
|
||||
class FoodNutrient {
|
||||
int nutrientId;
|
||||
String nutrientName;
|
||||
String nutrientNumber;
|
||||
UnitName unitName;
|
||||
DerivationCode? derivationCode;
|
||||
String? derivationDescription;
|
||||
int? derivationId;
|
||||
double? value;
|
||||
int? foodNutrientSourceId;
|
||||
String? foodNutrientSourceCode;
|
||||
FoodNutrientSourceDescription? foodNutrientSourceDescription;
|
||||
int rank;
|
||||
int indentLevel;
|
||||
int foodNutrientId;
|
||||
int? dataPoints;
|
||||
double? min;
|
||||
double? max;
|
||||
double? median;
|
||||
|
||||
FoodNutrient({
|
||||
required this.nutrientId,
|
||||
required this.nutrientName,
|
||||
required this.nutrientNumber,
|
||||
required this.unitName,
|
||||
this.derivationCode,
|
||||
this.derivationDescription,
|
||||
this.derivationId,
|
||||
this.value,
|
||||
this.foodNutrientSourceId,
|
||||
this.foodNutrientSourceCode,
|
||||
this.foodNutrientSourceDescription,
|
||||
required this.rank,
|
||||
required this.indentLevel,
|
||||
required this.foodNutrientId,
|
||||
this.dataPoints,
|
||||
this.min,
|
||||
this.max,
|
||||
this.median,
|
||||
});
|
||||
|
||||
factory FoodNutrient.fromJson(Map<String, dynamic> json) => FoodNutrient(
|
||||
nutrientId: json["nutrientId"],
|
||||
nutrientName: json["nutrientName"],
|
||||
nutrientNumber: json["nutrientNumber"],
|
||||
unitName: unitNameValues.map[json["unitName"]]!,
|
||||
derivationCode: derivationCodeValues.map[json["derivationCode"]]!,
|
||||
derivationDescription: json["derivationDescription"],
|
||||
derivationId: json["derivationId"],
|
||||
value: json["value"]?.toDouble(),
|
||||
foodNutrientSourceId: json["foodNutrientSourceId"],
|
||||
foodNutrientSourceCode: json["foodNutrientSourceCode"],
|
||||
foodNutrientSourceDescription: foodNutrientSourceDescriptionValues
|
||||
.map[json["foodNutrientSourceDescription"]]!,
|
||||
rank: json["rank"],
|
||||
indentLevel: json["indentLevel"],
|
||||
foodNutrientId: json["foodNutrientId"],
|
||||
dataPoints: json["dataPoints"],
|
||||
min: json["min"]?.toDouble(),
|
||||
max: json["max"]?.toDouble(),
|
||||
median: json["median"]?.toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"nutrientId": nutrientId,
|
||||
"nutrientName": nutrientName,
|
||||
"nutrientNumber": nutrientNumber,
|
||||
"unitName": unitNameValues.reverse[unitName],
|
||||
"derivationCode": derivationCodeValues.reverse[derivationCode],
|
||||
"derivationDescription": derivationDescription,
|
||||
"derivationId": derivationId,
|
||||
"value": value,
|
||||
"foodNutrientSourceId": foodNutrientSourceId,
|
||||
"foodNutrientSourceCode": foodNutrientSourceCode,
|
||||
"foodNutrientSourceDescription": foodNutrientSourceDescriptionValues
|
||||
.reverse[foodNutrientSourceDescription],
|
||||
"rank": rank,
|
||||
"indentLevel": indentLevel,
|
||||
"foodNutrientId": foodNutrientId,
|
||||
"dataPoints": dataPoints,
|
||||
"min": min,
|
||||
"max": max,
|
||||
"median": median,
|
||||
};
|
||||
}
|
||||
|
||||
enum DerivationCode { A, AS, BFFN, BFNN, BFZN, CAZN, LC, NC, NR, T, Z }
|
||||
|
||||
final derivationCodeValues = EnumValues({
|
||||
"A": DerivationCode.A,
|
||||
"AS": DerivationCode.AS,
|
||||
"BFFN": DerivationCode.BFFN,
|
||||
"BFNN": DerivationCode.BFNN,
|
||||
"BFZN": DerivationCode.BFZN,
|
||||
"CAZN": DerivationCode.CAZN,
|
||||
"LC": DerivationCode.LC,
|
||||
"NC": DerivationCode.NC,
|
||||
"NR": DerivationCode.NR,
|
||||
"T": DerivationCode.T,
|
||||
"Z": DerivationCode.Z
|
||||
});
|
||||
|
||||
enum FoodNutrientSourceDescription {
|
||||
ANALYTICAL_OR_DERIVED_FROM_ANALYTICAL,
|
||||
ASSUMED_ZERO,
|
||||
CALCULATED_FROM_NUTRIENT_LABEL_BY_NDL,
|
||||
CALCULATED_OR_IMPUTED
|
||||
}
|
||||
|
||||
final foodNutrientSourceDescriptionValues = EnumValues({
|
||||
"Analytical or derived from analytical":
|
||||
FoodNutrientSourceDescription.ANALYTICAL_OR_DERIVED_FROM_ANALYTICAL,
|
||||
"Assumed zero": FoodNutrientSourceDescription.ASSUMED_ZERO,
|
||||
"Calculated from nutrient label by NDL":
|
||||
FoodNutrientSourceDescription.CALCULATED_FROM_NUTRIENT_LABEL_BY_NDL,
|
||||
"Calculated or imputed": FoodNutrientSourceDescription.CALCULATED_OR_IMPUTED
|
||||
});
|
||||
|
||||
enum UnitName { G, IU, KCAL, K_J, MG, UG }
|
||||
|
||||
final unitNameValues = EnumValues({
|
||||
"G": UnitName.G,
|
||||
"IU": UnitName.IU,
|
||||
"KCAL": UnitName.KCAL,
|
||||
"kJ": UnitName.K_J,
|
||||
"MG": UnitName.MG,
|
||||
"UG": UnitName.UG
|
||||
});
|
||||
|
||||
class EnumValues<T> {
|
||||
Map<String, T> map;
|
||||
late Map<T, String> reverseMap;
|
||||
|
||||
EnumValues(this.map);
|
||||
|
||||
Map<T, String> get reverse {
|
||||
reverseMap = map.map((k, v) => MapEntry(v, k));
|
||||
return reverseMap;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user