app mobile allarmi prima
This commit is contained in:
102
lib/widgets/allarme_card.dart
Normal file
102
lib/widgets/allarme_card.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/allarme.dart';
|
||||
import '../utils/constants.dart';
|
||||
import '../screens/allarme_detail_screen.dart';
|
||||
|
||||
class AllarmeCard extends StatelessWidget {
|
||||
final Allarme allarme;
|
||||
|
||||
const AllarmeCard({super.key, required this.allarme});
|
||||
|
||||
Color _getSeverityColor() {
|
||||
switch (allarme.severita) {
|
||||
case 'critical': return AppColors.critical;
|
||||
case 'warning': return AppColors.warning;
|
||||
case 'info': return AppColors.info;
|
||||
default: return AppColors.textSecondary;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: AppSizes.paddingM),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => AllarmeDetailScreen(allarme: allarme),
|
||||
),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSizes.paddingM),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _getSeverityColor(),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(allarme.severitaReadable, style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.info.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(allarme.statoReadable, style: const TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(allarme.titolo, style: AppTextStyles.h3, maxLines: 2),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(AlarmTypeIcons.getIcon(allarme.tipo), size: 16, color: AppColors.textSecondary),
|
||||
const SizedBox(width: 8),
|
||||
Text(allarme.tipoReadable, style: AppTextStyles.bodyMedium.copyWith(color: AppColors.textSecondary)),
|
||||
],
|
||||
),
|
||||
if (allarme.descrizione != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(allarme.descrizione!, style: AppTextStyles.bodyMedium, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
if (allarme.valoreRilevato != null && allarme.valoreSoglia != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: _getSeverityColor().withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.show_chart, size: 16, color: _getSeverityColor()),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Valore: ${allarme.valoreRilevato!.toStringAsFixed(2)} ${allarme.unitaMisura ?? ''} (soglia: ${allarme.valoreSoglia!.toStringAsFixed(2)})',
|
||||
style: AppTextStyles.bodySmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user