Files
flutterApp/lib/features/v2/home/presentation/widgets/stats_grid.dart

246 lines
6.6 KiB
Dart
Raw Normal View History

2026-05-19 08:46:35 +08:00
import 'package:flutter/material.dart';
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/home_entity.dart';
class StatsGrid extends StatelessWidget {
final HomeEntity data;
const StatsGrid({super.key, required this.data});
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 2,
childAspectRatio: 1.8,
2026-05-19 08:46:35 +08:00
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
mainAxisSpacing: 8,
crossAxisSpacing: 8,
padding: EdgeInsets.zero,
2026-05-19 08:46:35 +08:00
children: [
_buildStatCard(
title: '今日发电量',
value: _formatNumber(data.todayGeneration),
2026-05-19 08:46:35 +08:00
unit: 'kWh',
valueColor: const Color(0xFF00B42A),
showArrow: false,
2026-05-19 08:46:35 +08:00
),
_buildStatCard(
title: '等效小时数',
value: data.equivalentHours.toStringAsFixed(1),
unit: 'h',
valueColor: const Color(0xFF165DFF),
showArrow: false,
2026-05-19 08:46:35 +08:00
),
_buildAlarmCard(data.alarmCount),
_buildWorkOrderCard(data.pendingWorkOrders),
],
);
}
Widget _buildStatCard({
required String title,
required String value,
required String unit,
required Color valueColor,
bool showArrow = false,
2026-05-19 08:46:35 +08:00
}) {
return Container(
padding: const EdgeInsets.all(8),
2026-05-19 08:46:35 +08:00
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (showArrow)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: const TextStyle(
color: Color(0xFF4E5969),
fontSize: 14,
),
2026-05-19 08:46:35 +08:00
),
const Icon(
Icons.arrow_forward_ios,
size: 14,
color: Color(0xFF86909C),
),
],
)
else
Text(
title,
style: const TextStyle(
color: Color(0xFF4E5969),
fontSize: 14,
2026-05-19 08:46:35 +08:00
),
),
2026-05-19 08:46:35 +08:00
const Spacer(),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
value,
style: TextStyle(
color: valueColor,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 4),
Text(
unit,
style: const TextStyle(
color: Color(0xFF4E5969),
fontSize: 14,
),
),
],
),
],
),
);
}
Widget _buildAlarmCard(int count) {
return Container(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
2026-05-19 08:46:35 +08:00
decoration: BoxDecoration(
color: const Color(0xFFFFF0F0),
borderRadius: BorderRadius.circular(16),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'告警数',
style: TextStyle(
color: Color(0xFFF53F3F),
fontSize: 13,
2026-05-19 08:46:35 +08:00
),
),
const SizedBox(height: 4),
2026-05-19 08:46:35 +08:00
Text(
count.toString(),
style: const TextStyle(
color: Color(0xFFF53F3F),
fontSize: 28,
2026-05-19 08:46:35 +08:00
fontWeight: FontWeight.bold,
),
),
],
),
),
Container(
width: 44,
height: 44,
2026-05-19 08:46:35 +08:00
decoration: const BoxDecoration(
color: Color(0xFFFFE8E8),
shape: BoxShape.circle,
),
child: const Icon(
Icons.notifications_none,
size: 24,
2026-05-19 08:46:35 +08:00
color: Color(0xFFF53F3F),
),
),
],
),
);
}
Widget _buildWorkOrderCard(int count) {
return Container(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
2026-05-19 08:46:35 +08:00
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: const [
BoxShadow(
color: Color(0x0D000000),
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'待办工单',
style: TextStyle(
color: Color(0xFF4E5969),
fontSize: 13,
2026-05-19 08:46:35 +08:00
),
),
const SizedBox(height: 4),
2026-05-19 08:46:35 +08:00
Text(
count.toString(),
style: const TextStyle(
color: Color(0xFF1D2129),
fontSize: 28,
2026-05-19 08:46:35 +08:00
fontWeight: FontWeight.bold,
),
),
],
),
),
Container(
width: 44,
height: 44,
2026-05-19 08:46:35 +08:00
decoration: const BoxDecoration(
color: Color(0xFFE8F3FF),
shape: BoxShape.circle,
),
child: const Icon(
Icons.content_paste,
size: 24,
2026-05-19 08:46:35 +08:00
color: Color(0xFF165DFF),
),
),
],
),
);
}
String _formatNumber(double number) {
final formatted = number.toStringAsFixed(0);
final parts = formatted.split('.');
final intPart = parts[0];
final buffer = StringBuffer();
for (int i = 0; i < intPart.length; i++) {
if (i > 0 && (intPart.length - i) % 3 == 0) {
buffer.write(',');
}
buffer.write(intPart[i]);
}
return buffer.toString();
}
2026-05-19 08:46:35 +08:00
}