261 lines
7.5 KiB
Dart
261 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
|
import 'package:maibu_satabot_v2/core/theme/AppTheme.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,
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
mainAxisSpacing: 8,
|
|
crossAxisSpacing: 8,
|
|
padding: EdgeInsets.zero,
|
|
children: [
|
|
_buildStatCard(
|
|
context,
|
|
title: AppLocalizations.of(
|
|
context,
|
|
).translate('home_v2.today_generation'),
|
|
value: _formatNumber(data.todayGeneration),
|
|
unit: 'kWh',
|
|
valueColor: context.appColors.success,
|
|
showArrow: false,
|
|
),
|
|
_buildStatCard(
|
|
context,
|
|
title: AppLocalizations.of(
|
|
context,
|
|
).translate('home_v2.equivalent_hours'),
|
|
value: data.equivalentHours.toStringAsFixed(1),
|
|
unit: 'h',
|
|
valueColor: context.appColors.primary,
|
|
showArrow: false,
|
|
),
|
|
_buildAlarmCard(context, data.alarmCount),
|
|
_buildWorkOrderCard(context, data.pendingWorkOrders),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildStatCard(
|
|
BuildContext context, {
|
|
required String title,
|
|
required String value,
|
|
required String unit,
|
|
required Color valueColor,
|
|
bool showArrow = false,
|
|
}) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: context.appColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: context.appColors.cardShadow,
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (showArrow)
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: TextStyle(
|
|
color: context.appColors.textSecondary,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.arrow_forward_ios,
|
|
size: 14,
|
|
color: context.appColors.textTertiary,
|
|
),
|
|
],
|
|
)
|
|
else
|
|
Text(
|
|
title,
|
|
style: TextStyle(
|
|
color: context.appColors.textSecondary,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
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: TextStyle(
|
|
color: context.appColors.textSecondary,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAlarmCard(BuildContext context, int count) {
|
|
return Container(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
|
|
decoration: BoxDecoration(
|
|
color: context.appColors.danger.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: context.appColors.cardShadow,
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context).translate('home_v2.alarm_count'),
|
|
style: TextStyle(
|
|
color: context.appColors.danger,
|
|
fontSize: 13,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
count.toString(),
|
|
style: TextStyle(
|
|
color: context.appColors.danger,
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
width: 44,
|
|
height: 44,
|
|
decoration: BoxDecoration(
|
|
color: context.appColors.danger.withOpacity(0.15),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(
|
|
Icons.notifications_none,
|
|
size: 24,
|
|
color: context.appColors.danger,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildWorkOrderCard(BuildContext context, int count) {
|
|
return Container(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
|
|
decoration: BoxDecoration(
|
|
color: context.appColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: context.appColors.cardShadow,
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(
|
|
context,
|
|
).translate('home_v2.pending_work_order'),
|
|
style: TextStyle(
|
|
color: context.appColors.textSecondary,
|
|
fontSize: 13,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
count.toString(),
|
|
style: TextStyle(
|
|
color: context.appColors.textPrimary,
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
width: 44,
|
|
height: 44,
|
|
decoration: BoxDecoration(
|
|
color: context.appColors.primary.withOpacity(0.1),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(
|
|
Icons.content_paste,
|
|
size: 24,
|
|
color: context.appColors.primary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|