112 lines
2.9 KiB
Dart
112 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:food_hub_app/models/stats.dart';
|
|
import 'package:food_hub_app/widgets/common/index.dart';
|
|
|
|
class StatisticCard extends StatelessWidget {
|
|
final IconData icon;
|
|
final Color color;
|
|
final String title;
|
|
final num value;
|
|
final String unit;
|
|
|
|
const StatisticCard({
|
|
super.key,
|
|
required this.icon,
|
|
required this.color,
|
|
required this.title,
|
|
required this.value,
|
|
required this.unit,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return buildCard(
|
|
context: context,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
SizedBox(
|
|
width: 40,
|
|
height: 40,
|
|
child: Icon(icon, color: color, size: 40),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(title, style: TextStyle(fontSize: 20, color: color)),
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
value.toString(),
|
|
style: TextStyle(fontSize: 20, color: color),
|
|
),
|
|
const SizedBox(width: 5),
|
|
Text(unit, style: TextStyle(fontSize: 20, color: color)),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// 获取排名对应的颜色
|
|
Color _getRankColor(int index) {
|
|
switch (index) {
|
|
case 0: // 第1名
|
|
return Colors.amber; // 金色
|
|
case 1: // 第2名
|
|
return Colors.grey; // 银色
|
|
case 2: // 第3名
|
|
return Colors.orange[700]!; // 铜色
|
|
default:
|
|
return Colors.black; // 普通颜色
|
|
}
|
|
}
|
|
|
|
Widget rankChart(List<ChartData> items) {
|
|
return ListView.builder(
|
|
itemCount: items.length,
|
|
itemBuilder: (context, index) {
|
|
final item = items[index];
|
|
final rank = index + 1;
|
|
return SizedBox(
|
|
height: 35,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 25,
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
'$rank.',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: _getRankColor(index),
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
item.name,
|
|
style: TextStyle(color: _getRankColor(index)),
|
|
),
|
|
],
|
|
),
|
|
Text(
|
|
'${item.value.toStringAsFixed(0)} 次',
|
|
style: TextStyle(color: _getRankColor(index)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|