76 lines
2.0 KiB
Dart
76 lines
2.0 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|||
|
|
|
|||
|
|
/// 指标卡片:展示设备单项运行指标。
|
|||
|
|
class MetricCard extends StatelessWidget {
|
|||
|
|
const MetricCard({
|
|||
|
|
super.key,
|
|||
|
|
required this.icon,
|
|||
|
|
required this.title,
|
|||
|
|
required this.value,
|
|||
|
|
this.progress,
|
|||
|
|
this.accentColor,
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/// 指标图标。
|
|||
|
|
final IconData icon;
|
|||
|
|
|
|||
|
|
/// 指标名称(如:CPU 使用率)。
|
|||
|
|
final String title;
|
|||
|
|
|
|||
|
|
/// 指标值文本(如:87.0%)。
|
|||
|
|
final String value;
|
|||
|
|
|
|||
|
|
/// 进度(0.0 ~ 1.0),为 null 时不显示进度条。
|
|||
|
|
final double? progress;
|
|||
|
|
|
|||
|
|
/// 强调色,默认使用主题主色。
|
|||
|
|
final Color? accentColor;
|
|||
|
|
|
|||
|
|
@override
|
|||
|
|
Widget build(BuildContext context) {
|
|||
|
|
final color = accentColor ?? Theme.of(context).colorScheme.primary;
|
|||
|
|
final progressValue = progress?.clamp(0.0, 1.0).toDouble();
|
|||
|
|
|
|||
|
|
return Card(
|
|||
|
|
child: Padding(
|
|||
|
|
padding: const EdgeInsets.all(16),
|
|||
|
|
child: Column(
|
|||
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|||
|
|
mainAxisSize: MainAxisSize.min,
|
|||
|
|
children: [
|
|||
|
|
Row(
|
|||
|
|
children: [
|
|||
|
|
Icon(icon, size: 20, color: color),
|
|||
|
|
const SizedBox(width: 8),
|
|||
|
|
Expanded(
|
|||
|
|
child: Text(
|
|||
|
|
title,
|
|||
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|||
|
|
overflow: TextOverflow.ellipsis,
|
|||
|
|
),
|
|||
|
|
),
|
|||
|
|
],
|
|||
|
|
),
|
|||
|
|
const SizedBox(height: 12),
|
|||
|
|
Text(
|
|||
|
|
value,
|
|||
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
|||
|
|
fontWeight: FontWeight.bold,
|
|||
|
|
),
|
|||
|
|
),
|
|||
|
|
if (progressValue != null) ...[
|
|||
|
|
const SizedBox(height: 12),
|
|||
|
|
LinearProgressIndicator(
|
|||
|
|
value: progressValue,
|
|||
|
|
color: color,
|
|||
|
|
backgroundColor: color.withOpacity(0.15),
|
|||
|
|
borderRadius: BorderRadius.circular(4),
|
|||
|
|
),
|
|||
|
|
],
|
|||
|
|
],
|
|||
|
|
),
|
|||
|
|
),
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
}
|