init
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:arcx/app/app_theme.dart';
|
||||
import 'package:arcx/features/stats/application/stats.dart';
|
||||
|
||||
class StatsCard extends StatelessWidget {
|
||||
const StatsCard({super.key, required this.stats});
|
||||
|
||||
final StatsSummary stats;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasData = stats.hasData;
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'训练统计',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'今日',
|
||||
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_StatGrid(
|
||||
items: [
|
||||
_StatItem(
|
||||
label: '今日射箭',
|
||||
value: hasData ? '${stats.todayArrowCount}' : '-',
|
||||
unit: '支',
|
||||
),
|
||||
_StatItem(
|
||||
label: '今日消耗',
|
||||
value: hasData ? stats.todayCalories.toStringAsFixed(1) : '-',
|
||||
unit: '千卡',
|
||||
),
|
||||
_StatItem(
|
||||
label: '运动强度',
|
||||
value: hasData ? stats.todayIntensityLabel : '-',
|
||||
unit: hasData
|
||||
? stats.todayIntensityRaw.toStringAsFixed(1)
|
||||
: '',
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 28),
|
||||
_StatGrid(
|
||||
items: [
|
||||
_StatItem(
|
||||
label: '训练天数',
|
||||
value: hasData ? '${stats.trainingDays}' : '-',
|
||||
unit: '天',
|
||||
),
|
||||
_StatItem(
|
||||
label: '累计射箭',
|
||||
value: hasData ? '${stats.totalArrowCount}' : '-',
|
||||
unit: '支',
|
||||
),
|
||||
_StatItem(
|
||||
label: '平均环数',
|
||||
value: hasData ? stats.averageScoreLabel : '-',
|
||||
unit: '环',
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatGrid extends StatelessWidget {
|
||||
const _StatGrid({required this.items});
|
||||
final List<_StatItem> items;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
for (var i = 0; i < items.length; i++) ...[
|
||||
Expanded(child: items[i]),
|
||||
if (i < items.length - 1) const SizedBox(width: 8),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatItem extends StatelessWidget {
|
||||
const _StatItem({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.unit,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
final String unit;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppTheme.primaryDark,
|
||||
),
|
||||
),
|
||||
if (unit.isNotEmpty) ...[
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
unit,
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user