init
This commit is contained in:
261
client/lib/features/home/widgets/daily_goal_card.dart
Normal file
261
client/lib/features/home/widgets/daily_goal_card.dart
Normal file
@@ -0,0 +1,261 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 每日目标卡片组件
|
||||
class DailyGoalCard extends StatelessWidget {
|
||||
const DailyGoalCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.track_changes,
|
||||
color: AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
Text(
|
||||
'今日目标进度',
|
||||
style: AppTextStyles.titleMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 单词学习目标
|
||||
_buildGoalItem(
|
||||
icon: Icons.book,
|
||||
title: '单词学习',
|
||||
current: 15,
|
||||
target: 20,
|
||||
unit: '个',
|
||||
color: AppColors.primary,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 学习时长目标
|
||||
_buildGoalItem(
|
||||
icon: Icons.timer,
|
||||
title: '学习时长',
|
||||
current: 25,
|
||||
target: 30,
|
||||
unit: '分钟',
|
||||
color: AppColors.secondary,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 练习题目标
|
||||
_buildGoalItem(
|
||||
icon: Icons.quiz,
|
||||
title: '练习题',
|
||||
current: 8,
|
||||
target: 10,
|
||||
unit: '道',
|
||||
color: AppColors.tertiary,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 总体进度
|
||||
_buildOverallProgress(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建目标项
|
||||
Widget _buildGoalItem({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required int current,
|
||||
required int target,
|
||||
required String unit,
|
||||
required Color color,
|
||||
}) {
|
||||
final progress = current / target;
|
||||
final isCompleted = current >= target;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.bodyMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'$current/$target $unit',
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: isCompleted ? AppColors.success : AppColors.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
if (isCompleted) ...[
|
||||
const SizedBox(width: AppDimensions.spacingXs),
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: AppColors.success,
|
||||
size: 16,
|
||||
),
|
||||
]
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
// 进度条
|
||||
Container(
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: progress.clamp(0.0, 1.0),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isCompleted ? AppColors.success : color,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建总体进度
|
||||
Widget _buildOverallProgress() {
|
||||
const totalProgress = 0.75; // 75% 完成
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
AppColors.secondary.withOpacity(0.1),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusSm),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'今日完成度',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${(totalProgress * 100).toInt()}%',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
// 总体进度条
|
||||
Container(
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: totalProgress,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.secondary,
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
Text(
|
||||
totalProgress >= 1.0
|
||||
? '🎉 恭喜!今日目标已完成!'
|
||||
: '继续加油,距离完成目标还有一点点!',
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
352
client/lib/features/home/widgets/learning_stats_card.dart
Normal file
352
client/lib/features/home/widgets/learning_stats_card.dart
Normal file
@@ -0,0 +1,352 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 学习统计卡片组件
|
||||
class LearningStatsCard extends StatelessWidget {
|
||||
const LearningStatsCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.analytics_outlined,
|
||||
color: AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
Text(
|
||||
'本周学习数据',
|
||||
style: AppTextStyles.titleMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 统计数据网格
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStatItem(
|
||||
title: '学习天数',
|
||||
value: '5',
|
||||
unit: '天',
|
||||
icon: Icons.calendar_today,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
Expanded(
|
||||
child: _buildStatItem(
|
||||
title: '学习时长',
|
||||
value: '2.5',
|
||||
unit: '小时',
|
||||
icon: Icons.access_time,
|
||||
color: AppColors.secondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStatItem(
|
||||
title: '掌握单词',
|
||||
value: '128',
|
||||
unit: '个',
|
||||
icon: Icons.psychology,
|
||||
color: AppColors.success,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
Expanded(
|
||||
child: _buildStatItem(
|
||||
title: '练习题目',
|
||||
value: '45',
|
||||
unit: '道',
|
||||
icon: Icons.quiz,
|
||||
color: AppColors.warning,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 学习排名
|
||||
_buildRankingSection(),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 成就徽章
|
||||
_buildAchievementSection(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建统计项
|
||||
Widget _buildStatItem({
|
||||
required String title,
|
||||
required String value,
|
||||
required String unit,
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusSm),
|
||||
border: Border.all(
|
||||
color: color.withOpacity(0.1),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 20,
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'+12%',
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: color,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: value,
|
||||
style: AppTextStyles.headlineSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: ' $unit',
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建排名部分
|
||||
Widget _buildRankingSection() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
AppColors.secondary.withOpacity(0.1),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusSm),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.emoji_events,
|
||||
color: AppColors.onPrimary,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'学习排名',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'本周排名第 8 位,超越了 76% 的用户',
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Text(
|
||||
'#8',
|
||||
style: AppTextStyles.headlineSmall.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建成就部分
|
||||
Widget _buildAchievementSection() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'最新成就',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
_buildAchievementBadge(
|
||||
icon: Icons.local_fire_department,
|
||||
title: '连续学习',
|
||||
subtitle: '5天',
|
||||
color: AppColors.error,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
_buildAchievementBadge(
|
||||
icon: Icons.speed,
|
||||
title: '快速学习',
|
||||
subtitle: '今日',
|
||||
color: AppColors.success,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
_buildAchievementBadge(
|
||||
icon: Icons.star,
|
||||
title: '完美答题',
|
||||
subtitle: '昨日',
|
||||
color: AppColors.warning,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建成就徽章
|
||||
Widget _buildAchievementBadge({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required Color color,
|
||||
}) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingSm),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusXs),
|
||||
border: Border.all(
|
||||
color: color.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
subtitle,
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
fontSize: 10,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
156
client/lib/features/home/widgets/learning_trend_chart.dart
Normal file
156
client/lib/features/home/widgets/learning_trend_chart.dart
Normal file
@@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
|
||||
/// 学习趋势图表
|
||||
class LearningTrendChart extends StatelessWidget {
|
||||
final List<Map<String, dynamic>> weeklyData;
|
||||
|
||||
const LearningTrendChart({
|
||||
super.key,
|
||||
required this.weeklyData,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (weeklyData.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'暂无学习数据',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: 200,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: LineChart(
|
||||
LineChartData(
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
drawVerticalLine: false,
|
||||
horizontalInterval: 20,
|
||||
getDrawingHorizontalLine: (value) {
|
||||
return FlLine(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
strokeWidth: 1,
|
||||
);
|
||||
},
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
rightTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
topTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 30,
|
||||
interval: 1,
|
||||
getTitlesWidget: (value, meta) {
|
||||
final index = value.toInt();
|
||||
if (index < 0 || index >= weeklyData.length) {
|
||||
return const Text('');
|
||||
}
|
||||
|
||||
final date = DateTime.parse(weeklyData[index]['date']);
|
||||
final dayLabel = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'][date.weekday - 1];
|
||||
|
||||
return Text(
|
||||
dayLabel,
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 10,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
leftTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
interval: 20,
|
||||
reservedSize: 35,
|
||||
getTitlesWidget: (value, meta) {
|
||||
return Text(
|
||||
value.toInt().toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 10,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
borderData: FlBorderData(
|
||||
show: true,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.grey.withOpacity(0.2)),
|
||||
left: BorderSide(color: Colors.grey.withOpacity(0.2)),
|
||||
),
|
||||
),
|
||||
minX: 0,
|
||||
maxX: (weeklyData.length - 1).toDouble(),
|
||||
minY: 0,
|
||||
maxY: _getMaxY(),
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
spots: _generateSpots(),
|
||||
isCurved: true,
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF2196F3), Color(0xFF1976D2)],
|
||||
),
|
||||
barWidth: 3,
|
||||
isStrokeCapRound: true,
|
||||
dotData: FlDotData(
|
||||
show: true,
|
||||
getDotPainter: (spot, percent, barData, index) {
|
||||
return FlDotCirclePainter(
|
||||
radius: 4,
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
strokeColor: const Color(0xFF2196F3),
|
||||
);
|
||||
},
|
||||
),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
const Color(0xFF2196F3).withOpacity(0.2),
|
||||
const Color(0xFF2196F3).withOpacity(0.05),
|
||||
],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<FlSpot> _generateSpots() {
|
||||
return List.generate(
|
||||
weeklyData.length,
|
||||
(index) {
|
||||
final wordsStudied = (weeklyData[index]['words_studied'] ?? 0) as int;
|
||||
return FlSpot(index.toDouble(), wordsStudied.toDouble());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
double _getMaxY() {
|
||||
if (weeklyData.isEmpty) return 100;
|
||||
|
||||
final maxWords = weeklyData.map((data) => (data['words_studied'] ?? 0) as int).reduce((a, b) => a > b ? a : b);
|
||||
|
||||
// 向上取整到最近的10的倍数,并加20作为上边距
|
||||
return ((maxWords / 10).ceil() * 10 + 20).toDouble();
|
||||
}
|
||||
}
|
||||
387
client/lib/features/home/widgets/progress_chart.dart
Normal file
387
client/lib/features/home/widgets/progress_chart.dart
Normal file
@@ -0,0 +1,387 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 进度图表组件
|
||||
class ProgressChart extends StatefulWidget {
|
||||
const ProgressChart({super.key});
|
||||
|
||||
@override
|
||||
State<ProgressChart> createState() => _ProgressChartState();
|
||||
}
|
||||
|
||||
class _ProgressChartState extends State<ProgressChart>
|
||||
with TickerProviderStateMixin {
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _animation;
|
||||
|
||||
// 模拟数据
|
||||
final List<ChartData> _weeklyData = [
|
||||
ChartData('周一', 45, AppColors.primary),
|
||||
ChartData('周二', 60, AppColors.secondary),
|
||||
ChartData('周三', 30, AppColors.tertiary),
|
||||
ChartData('周四', 80, AppColors.success),
|
||||
ChartData('周五', 55, AppColors.warning),
|
||||
ChartData('周六', 70, AppColors.info),
|
||||
ChartData('周日', 40, AppColors.error),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_animation = Tween<double>(
|
||||
begin: 0.0,
|
||||
end: 1.0,
|
||||
).animate(CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeInOutCubic,
|
||||
));
|
||||
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.trending_up,
|
||||
color: AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
Text(
|
||||
'本周学习时长',
|
||||
style: AppTextStyles.titleMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// 时间选择器
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.spacingSm,
|
||||
vertical: AppDimensions.spacingXs,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusXs),
|
||||
),
|
||||
child: Text(
|
||||
'本周',
|
||||
style: AppTextStyles.labelMedium.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 总计信息
|
||||
_buildSummaryInfo(),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 图表
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return CustomPaint(
|
||||
size: const Size(double.infinity, 200),
|
||||
painter: BarChartPainter(
|
||||
data: _weeklyData,
|
||||
animationValue: _animation.value,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 图例
|
||||
_buildLegend(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建总计信息
|
||||
Widget _buildSummaryInfo() {
|
||||
final totalMinutes = _weeklyData.fold<int>(0, (sum, data) => sum + data.value);
|
||||
final avgMinutes = totalMinutes / _weeklyData.length;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildSummaryItem(
|
||||
title: '总时长',
|
||||
value: '${(totalMinutes / 60).toStringAsFixed(1)}',
|
||||
unit: '小时',
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
Expanded(
|
||||
child: _buildSummaryItem(
|
||||
title: '日均时长',
|
||||
value: avgMinutes.toStringAsFixed(0),
|
||||
unit: '分钟',
|
||||
color: AppColors.secondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
Expanded(
|
||||
child: _buildSummaryItem(
|
||||
title: '最长单日',
|
||||
value: _weeklyData.map((e) => e.value).reduce((a, b) => a > b ? a : b).toString(),
|
||||
unit: '分钟',
|
||||
color: AppColors.success,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建总计项
|
||||
Widget _buildSummaryItem({
|
||||
required String title,
|
||||
required String value,
|
||||
required String unit,
|
||||
required Color color,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingSm),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusXs),
|
||||
border: Border.all(
|
||||
color: color.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: value,
|
||||
style: AppTextStyles.titleLarge.copyWith(
|
||||
color: color,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: unit,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建图例
|
||||
Widget _buildLegend() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildLegendItem(
|
||||
color: AppColors.primary,
|
||||
label: '目标: 60分钟/天',
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
_buildLegendItem(
|
||||
color: AppColors.success,
|
||||
label: '已完成',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建图例项
|
||||
Widget _buildLegendItem({
|
||||
required Color color,
|
||||
required String label,
|
||||
}) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingXs),
|
||||
Text(
|
||||
label,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 图表数据模型
|
||||
class ChartData {
|
||||
final String label;
|
||||
final int value;
|
||||
final Color color;
|
||||
|
||||
ChartData(this.label, this.value, this.color);
|
||||
}
|
||||
|
||||
/// 柱状图绘制器
|
||||
class BarChartPainter extends CustomPainter {
|
||||
final List<ChartData> data;
|
||||
final double animationValue;
|
||||
|
||||
BarChartPainter({
|
||||
required this.data,
|
||||
required this.animationValue,
|
||||
});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint = Paint();
|
||||
final maxValue = data.map((e) => e.value).reduce((a, b) => a > b ? a : b).toDouble();
|
||||
final barWidth = (size.width - (data.length + 1) * 16) / data.length;
|
||||
final chartHeight = size.height - 40; // 留出底部标签空间
|
||||
|
||||
// 绘制网格线
|
||||
_drawGridLines(canvas, size, chartHeight);
|
||||
|
||||
// 绘制柱状图
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
final item = data[i];
|
||||
final x = 16 + i * (barWidth + 16);
|
||||
final barHeight = (item.value / maxValue) * chartHeight * animationValue;
|
||||
final y = chartHeight - barHeight;
|
||||
|
||||
// 绘制柱子
|
||||
paint.color = item.color.withOpacity(0.8);
|
||||
final rect = RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(x, y, barWidth, barHeight),
|
||||
const Radius.circular(4),
|
||||
);
|
||||
canvas.drawRRect(rect, paint);
|
||||
|
||||
// 绘制数值标签
|
||||
if (animationValue > 0.8) {
|
||||
final textPainter = TextPainter(
|
||||
text: TextSpan(
|
||||
text: '${item.value}',
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
textPainter.layout();
|
||||
textPainter.paint(
|
||||
canvas,
|
||||
Offset(
|
||||
x + (barWidth - textPainter.width) / 2,
|
||||
y - textPainter.height - 4,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 绘制底部标签
|
||||
final labelPainter = TextPainter(
|
||||
text: TextSpan(
|
||||
text: item.label,
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
labelPainter.layout();
|
||||
labelPainter.paint(
|
||||
canvas,
|
||||
Offset(
|
||||
x + (barWidth - labelPainter.width) / 2,
|
||||
chartHeight + 8,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制网格线
|
||||
void _drawGridLines(Canvas canvas, Size size, double chartHeight) {
|
||||
final paint = Paint()
|
||||
..color = AppColors.outline.withOpacity(0.1)
|
||||
..strokeWidth = 1;
|
||||
|
||||
// 绘制水平网格线
|
||||
for (int i = 0; i <= 4; i++) {
|
||||
final y = chartHeight * i / 4;
|
||||
canvas.drawLine(
|
||||
Offset(0, y),
|
||||
Offset(size.width, y),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
152
client/lib/features/home/widgets/quick_actions_grid.dart
Normal file
152
client/lib/features/home/widgets/quick_actions_grid.dart
Normal file
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 快捷操作网格组件
|
||||
class QuickActionsGrid extends StatelessWidget {
|
||||
const QuickActionsGrid({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisSpacing: AppDimensions.spacingMd,
|
||||
mainAxisSpacing: AppDimensions.spacingMd,
|
||||
childAspectRatio: 1.2,
|
||||
children: [
|
||||
_buildActionCard(
|
||||
context: context,
|
||||
icon: Icons.book_outlined,
|
||||
title: '单词学习',
|
||||
subtitle: '智能背词',
|
||||
color: AppColors.primary,
|
||||
onTap: () => Navigator.pushNamed(context, '/vocabulary'),
|
||||
),
|
||||
_buildActionCard(
|
||||
context: context,
|
||||
icon: Icons.headphones_outlined,
|
||||
title: '听力训练',
|
||||
subtitle: '提升听力',
|
||||
color: AppColors.secondary,
|
||||
onTap: () => Navigator.pushNamed(context, '/listening'),
|
||||
),
|
||||
_buildActionCard(
|
||||
context: context,
|
||||
icon: Icons.article_outlined,
|
||||
title: '阅读理解',
|
||||
subtitle: '分级阅读',
|
||||
color: AppColors.tertiary,
|
||||
onTap: () => Navigator.pushNamed(context, '/reading'),
|
||||
),
|
||||
_buildActionCard(
|
||||
context: context,
|
||||
icon: Icons.edit_outlined,
|
||||
title: '写作练习',
|
||||
subtitle: 'AI批改',
|
||||
color: AppColors.success,
|
||||
onTap: () => Navigator.pushNamed(context, '/writing'),
|
||||
),
|
||||
_buildActionCard(
|
||||
context: context,
|
||||
icon: Icons.mic_outlined,
|
||||
title: '口语练习',
|
||||
subtitle: '发音评估',
|
||||
color: AppColors.warning,
|
||||
onTap: () => Navigator.pushNamed(context, '/speaking'),
|
||||
),
|
||||
_buildActionCard(
|
||||
context: context,
|
||||
icon: Icons.quiz_outlined,
|
||||
title: '模拟考试',
|
||||
subtitle: '综合测试',
|
||||
color: AppColors.info,
|
||||
onTap: () => Navigator.pushNamed(context, '/exam'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建操作卡片
|
||||
Widget _buildActionCard({
|
||||
required BuildContext context,
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
border: Border.all(
|
||||
color: color.withOpacity(0.1),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// 图标容器
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusSm),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 标题
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
// 副标题
|
||||
Text(
|
||||
subtitle,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
250
client/lib/features/home/widgets/recent_activities_card.dart
Normal file
250
client/lib/features/home/widgets/recent_activities_card.dart
Normal file
@@ -0,0 +1,250 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 最近活动卡片组件
|
||||
class RecentActivitiesCard extends StatelessWidget {
|
||||
const RecentActivitiesCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.history,
|
||||
color: AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
Text(
|
||||
'最近活动',
|
||||
style: AppTextStyles.titleMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 活动列表
|
||||
..._buildActivityList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建活动列表
|
||||
List<Widget> _buildActivityList() {
|
||||
final activities = [
|
||||
ActivityItem(
|
||||
icon: Icons.book_outlined,
|
||||
title: '完成单词学习',
|
||||
subtitle: '学习了20个新单词',
|
||||
time: '2小时前',
|
||||
color: AppColors.primary,
|
||||
score: 95,
|
||||
),
|
||||
ActivityItem(
|
||||
icon: Icons.headphones_outlined,
|
||||
title: '听力练习',
|
||||
subtitle: '完成日常英语对话练习',
|
||||
time: '4小时前',
|
||||
color: AppColors.secondary,
|
||||
score: 88,
|
||||
),
|
||||
ActivityItem(
|
||||
icon: Icons.quiz_outlined,
|
||||
title: '语法测试',
|
||||
subtitle: '时态练习测试',
|
||||
time: '昨天',
|
||||
color: AppColors.success,
|
||||
score: 92,
|
||||
),
|
||||
ActivityItem(
|
||||
icon: Icons.article_outlined,
|
||||
title: '阅读理解',
|
||||
subtitle: '科技类文章阅读',
|
||||
time: '昨天',
|
||||
color: AppColors.tertiary,
|
||||
score: 85,
|
||||
),
|
||||
ActivityItem(
|
||||
icon: Icons.mic_outlined,
|
||||
title: '口语练习',
|
||||
subtitle: '日常对话场景训练',
|
||||
time: '2天前',
|
||||
color: AppColors.warning,
|
||||
score: 90,
|
||||
),
|
||||
];
|
||||
|
||||
return activities.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final activity = entry.value;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildActivityItem(activity),
|
||||
if (index < activities.length - 1)
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// 构建活动项
|
||||
Widget _buildActivityItem(ActivityItem activity) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: activity.color.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusSm),
|
||||
border: Border.all(
|
||||
color: activity.color.withOpacity(0.1),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 图标容器
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: activity.color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusXs),
|
||||
),
|
||||
child: Icon(
|
||||
activity.icon,
|
||||
color: activity.color,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingMd),
|
||||
|
||||
// 活动信息
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
activity.title,
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
if (activity.score != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _getScoreColor(activity.score!).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusXs),
|
||||
),
|
||||
child: Text(
|
||||
'${activity.score}分',
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: _getScoreColor(activity.score!),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
Text(
|
||||
activity.subtitle,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
size: 14,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingXs),
|
||||
Text(
|
||||
activity.time,
|
||||
style: AppTextStyles.labelSmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 箭头图标
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 获取分数颜色
|
||||
Color _getScoreColor(int score) {
|
||||
if (score >= 90) {
|
||||
return AppColors.success;
|
||||
} else if (score >= 80) {
|
||||
return AppColors.warning;
|
||||
} else if (score >= 70) {
|
||||
return AppColors.info;
|
||||
} else {
|
||||
return AppColors.error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 活动项数据模型
|
||||
class ActivityItem {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final String time;
|
||||
final Color color;
|
||||
final int? score;
|
||||
|
||||
ActivityItem({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.time,
|
||||
required this.color,
|
||||
this.score,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user