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

@@ -33,14 +33,14 @@ class _FoodDetailsScreenState extends State<FoodDetailsScreen> {
double? difference;
String name = 'undetected'.tr;
String? unitName;
double? current;
FoodNutrient? current;
for (final nutrient in widget.item.foodNutrients) {
if (item.nutrientId != nutrient.nutrientId) continue;
name = nutrient.nutrientName;
unitName = unitNameValues.reverse[nutrient.unitName];
if (nutrient.value != null) {
current = nutrient;
final value = nutrient.value!;
current = value;
if (value > item.maxValue) {
difference = value - item.maxValue;
isOutOfRange = true;
@@ -54,9 +54,9 @@ class _FoodDetailsScreenState extends State<FoodDetailsScreen> {
_alertDetectResult.add(AlertDetectResult(
config: item,
nutrient: current,
name: name,
unitName: unitName,
current: current,
difference: difference,
isOutOfRange: isOutOfRange,
isUndetected: isUndetected,

View File

@@ -16,6 +16,7 @@ class _AlertSettingsScreenState extends State<AlertSettingsScreen> {
void _addAlert() {
setState(() {
_currentAlerts.add(AlertConfiguration(
name: 'Alert #${_currentAlerts.length}',
nutrientId: 0,
maxValue: 0,
minValue: 0,
@@ -64,16 +65,16 @@ class _AlertSettingsScreenState extends State<AlertSettingsScreen> {
children: [
Expanded(
child: TextFormField(
initialValue: x.nutrientId.toString(),
initialValue: x.name,
decoration: InputDecoration(
border: const OutlineInputBorder(),
label: Text("alertNutrientId".tr),
label: Text("alertName".tr),
isDense: true,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
onChanged: (value) {
x.nutrientId = int.tryParse(value) ?? 0;
x.name = value;
},
),
),
@@ -87,6 +88,20 @@ class _AlertSettingsScreenState extends State<AlertSettingsScreen> {
],
),
const SizedBox(height: 12),
TextFormField(
initialValue: x.nutrientId.toString(),
decoration: InputDecoration(
border: const OutlineInputBorder(),
label: Text("alertNutrientId".tr),
isDense: true,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
onChanged: (value) {
x.nutrientId = int.tryParse(value) ?? 0;
},
),
const SizedBox(height: 12),
Row(
children: [
Expanded(