Support named alert config

This commit is contained in:
2024-08-15 22:50:00 +08:00
parent 22b863f2bf
commit cfa61e1a8a
7 changed files with 34 additions and 11 deletions

View File

@ -1,15 +1,20 @@
import 'package:dietary_guard/models/food_data.dart';
class AlertConfiguration {
String name;
int nutrientId;
double maxValue;
double minValue;
AlertConfiguration({
required this.name,
required this.nutrientId,
required this.maxValue,
required this.minValue,
});
Map<String, dynamic> toJson() => {
'name': name,
'nutrient_id': nutrientId,
'min_value': minValue,
'max_value': maxValue,
@ -17,6 +22,7 @@ class AlertConfiguration {
factory AlertConfiguration.fromJson(Map<String, dynamic> json) =>
AlertConfiguration(
name: json['name'],
nutrientId: json['nutrient_id'],
minValue: json['min_value'],
maxValue: json['max_value'],
@ -25,18 +31,18 @@ class AlertConfiguration {
class AlertDetectResult {
AlertConfiguration config;
FoodNutrient? nutrient;
String name;
String? unitName;
double? current;
double? difference;
bool isOutOfRange;
bool isUndetected;
AlertDetectResult({
required this.config,
required this.nutrient,
required this.name,
required this.unitName,
required this.current,
required this.difference,
required this.isOutOfRange,
required this.isUndetected,