80 lines
2.3 KiB
Dart
80 lines
2.3 KiB
Dart
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: [
|
|
Text(item.name),
|
|
const SizedBox(width: 6),
|
|
Badge(label: Text('#${item.config.nutrientId}'))
|
|
],
|
|
),
|
|
subtitle: Text(
|
|
'${item.current} ${(item.difference ?? 0) > 0 ? '↑' : '↓'}${item.difference?.abs()} ${item.unitName}',
|
|
),
|
|
);
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|