2024-08-15 07:57:58 +00:00
|
|
|
import 'package:dietary_guard/models/alert_configuration.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
class AlertDetectResultDialog extends StatelessWidget {
|
|
|
|
final List<AlertDetectResult> result;
|
|
|
|
|
|
|
|
const AlertDetectResultDialog({super.key, required this.result});
|
|
|
|
|
|
|
|
Color _getColor(AlertDetectResult result) {
|
|
|
|
if (result.isOutOfRange) {
|
|
|
|
return Colors.red;
|
|
|
|
} else if (result.isUndetected) {
|
|
|
|
return Colors.grey;
|
|
|
|
} else {
|
|
|
|
return Colors.green;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IconData _getIcon(AlertDetectResult result) {
|
|
|
|
if (result.isOutOfRange) {
|
|
|
|
return Icons.close;
|
|
|
|
} else if (result.isUndetected) {
|
|
|
|
return Icons.question_mark;
|
|
|
|
} else {
|
|
|
|
return Icons.check;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height * 0.65,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
right: 24,
|
|
|
|
top: 24,
|
|
|
|
bottom: 8,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
'alertDetectResult'.tr,
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: result.length,
|
|
|
|
itemBuilder: (context, idx) {
|
|
|
|
final item = result[idx];
|
|
|
|
return ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: CircleAvatar(
|
|
|
|
backgroundColor: _getColor(item),
|
|
|
|
child: Icon(_getIcon(item), color: Colors.white),
|
|
|
|
),
|
|
|
|
title: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2024-08-15 14:50:00 +00:00
|
|
|
Text(item.config.name),
|
2024-08-15 07:57:58 +00:00
|
|
|
const SizedBox(width: 6),
|
|
|
|
Badge(label: Text('#${item.config.nutrientId}'))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
2024-08-15 14:50:00 +00:00
|
|
|
'${item.nutrient?.value ?? 'undetected'.tr} ${(item.difference ?? 0) > 0 ? '↑' : '↓'}${item.difference?.abs().toPrecision(2) ?? '-'} ${item.unitName ?? ''}',
|
2024-08-15 07:57:58 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|