This commit is contained in:
sjk
2025-11-17 13:39:05 +08:00
commit d4cfe2b9de
479 changed files with 109324 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
import 'package:flutter/material.dart';
import '../models/writing_task.dart';
import '../screens/writing_list_screen.dart';
/// 写作模式卡片组件
class WritingModeCard extends StatelessWidget {
final String title;
final String subtitle;
final IconData icon;
final Color color;
final WritingType? type;
final WritingDifficulty? difficulty;
const WritingModeCard({
super.key,
required this.title,
required this.subtitle,
required this.icon,
required this.color,
this.type,
this.difficulty,
});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WritingListScreen(
title: title,
type: type,
difficulty: difficulty,
),
),
);
},
borderRadius: BorderRadius.circular(16),
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
icon,
color: color,
size: 24,
),
),
const SizedBox(height: 16),
Text(
title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
subtitle,
style: const TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
const SizedBox(height: 16),
Row(
children: [
Text(
'开始练习',
style: TextStyle(
fontSize: 14,
color: color,
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_forward,
size: 16,
color: color,
),
],
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,360 @@
import 'package:flutter/material.dart';
import '../models/writing_stats.dart';
class WritingStatsCard extends StatelessWidget {
final WritingStats stats;
final bool showDetails;
const WritingStatsCard({
super.key,
required this.stats,
this.showDetails = false,
});
@override
Widget build(BuildContext context) {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: LinearGradient(
colors: [
Colors.purple.shade50,
Colors.purple.shade100,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题
Row(
children: [
Icon(
Icons.analytics,
color: Colors.purple.shade700,
size: 20,
),
const SizedBox(width: 8),
Text(
'写作统计',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.purple.shade700,
),
),
const Spacer(),
if (showDetails)
Icon(
Icons.keyboard_arrow_down,
color: Colors.purple.shade700,
),
],
),
const SizedBox(height: 16),
// 主要统计数据
Row(
children: [
Expanded(
child: _buildStatItem(
icon: Icons.assignment,
label: '完成任务',
value: '${stats.completedTasks}',
total: '${stats.totalTasks}',
color: Colors.blue,
),
),
const SizedBox(width: 16),
Expanded(
child: _buildStatItem(
icon: Icons.text_fields,
label: '总字数',
value: _formatNumber(stats.totalWords),
color: Colors.green,
),
),
const SizedBox(width: 16),
Expanded(
child: _buildStatItem(
icon: Icons.star,
label: '平均分',
value: stats.averageScore.toStringAsFixed(1),
color: Colors.orange,
),
),
],
),
if (showDetails) ...[
const SizedBox(height: 16),
const Divider(),
const SizedBox(height: 16),
// 详细统计
_buildDetailedStats(),
],
],
),
),
);
}
Widget _buildStatItem({
required IconData icon,
required String label,
required String value,
String? total,
required Color color,
}) {
return Column(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
icon,
color: color,
size: 24,
),
),
const SizedBox(height: 8),
Text(
total != null ? '$value/$total' : value,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
label,
style: TextStyle(
fontSize: 12,
color: Colors.grey.shade600,
),
textAlign: TextAlign.center,
),
],
);
}
Widget _buildDetailedStats() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 任务类型统计
Text(
'任务类型分布',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade700,
),
),
const SizedBox(height: 8),
_buildTypeStats(),
const SizedBox(height: 16),
// 难度分布
Text(
'难度分布',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade700,
),
),
const SizedBox(height: 8),
_buildDifficultyStats(),
const SizedBox(height: 16),
// 技能分析
// 技能分析
Text(
'技能分析',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade700,
),
),
const SizedBox(height: 8),
_buildSkillAnalysis(),
],
);
}
Widget _buildTypeStats() {
return Wrap(
spacing: 8,
runSpacing: 8,
children: stats.taskTypeStats.entries.map((entry) {
final percentage = stats.totalTasks > 0
? (entry.value / stats.totalTasks * 100).toInt()
: 0;
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: Colors.blue.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.blue.withValues(alpha: 0.3),
),
),
child: Text(
'${entry.key}: ${entry.value} ($percentage%)',
style: TextStyle(
fontSize: 12,
color: Colors.blue.shade700,
),
),
);
}).toList(),
);
}
Widget _buildDifficultyStats() {
return Wrap(
spacing: 8,
runSpacing: 8,
children: stats.difficultyStats.entries.map((entry) {
final percentage = stats.totalTasks > 0
? (entry.value / stats.totalTasks * 100).toInt()
: 0;
Color color;
switch (entry.key) {
case 'beginner':
case 'elementary':
color = Colors.green;
break;
case 'intermediate':
case 'upperIntermediate':
color = Colors.orange;
break;
case 'advanced':
color = Colors.red;
break;
default:
color = Colors.grey;
}
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: color.withValues(alpha: 0.3),
),
),
child: Text(
'${entry.key}: ${entry.value} ($percentage%)',
style: TextStyle(
fontSize: 12,
color: Colors.grey[700],
),
),
);
}).toList(),
);
}
Widget _buildSkillAnalysis() {
final analysis = stats.skillAnalysis;
return Column(
children: [
...analysis.criteriaScores.entries.map((entry) {
Color color;
switch (entry.key) {
case 'grammar':
color = Colors.blue;
break;
case 'vocabulary':
color = Colors.green;
break;
case 'structure':
color = Colors.orange;
break;
case 'content':
color = Colors.purple;
break;
default:
color = Colors.grey;
}
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: _buildSkillBar(entry.key, entry.value * 100, color),
);
}),
],
);
}
Widget _buildSkillBar(String skill, double score, Color color) {
return Row(
children: [
SizedBox(
width: 60,
child: Text(
skill,
style: TextStyle(
fontSize: 12,
color: Colors.grey.shade600,
),
),
),
Expanded(
child: LinearProgressIndicator(
value: score / 100,
backgroundColor: Colors.grey.shade200,
valueColor: AlwaysStoppedAnimation<Color>(color),
),
),
const SizedBox(width: 8),
Text(
'${score.toInt()}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: color,
),
),
],
);
}
String _formatNumber(int number) {
if (number >= 1000000) {
return '${(number / 1000000).toStringAsFixed(1)}M';
} else if (number >= 1000) {
return '${(number / 1000).toStringAsFixed(1)}K';
} else {
return number.toString();
}
}
}

View File

@@ -0,0 +1,271 @@
import 'package:flutter/material.dart';
import '../models/writing_task.dart';
class WritingTaskCard extends StatelessWidget {
final WritingTask task;
final VoidCallback? onTap;
final bool showProgress;
const WritingTaskCard({
Key? key,
required this.task,
this.onTap,
this.showProgress = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题和类型
Row(
children: [
Expanded(
child: Text(
task.title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
_buildTypeChip(),
],
),
const SizedBox(height: 8),
// 描述
Text(
task.description,
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 14,
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 12),
// 任务信息
Row(
children: [
_buildInfoChip(
icon: Icons.signal_cellular_alt,
label: task.difficulty.displayName,
color: _getDifficultyColor(),
),
const SizedBox(width: 8),
if (task.timeLimit > 0)
_buildInfoChip(
icon: Icons.timer,
label: '${task.timeLimit}分钟',
color: Colors.blue,
),
const SizedBox(width: 8),
if (task.wordLimit > 0)
_buildInfoChip(
icon: Icons.text_fields,
label: '${task.wordLimit}',
color: Colors.green,
),
],
),
// 关键词
if (task.keywords.isNotEmpty) ...[
const SizedBox(height: 12),
Wrap(
spacing: 6,
runSpacing: 6,
children: task.keywords.take(3).map((keyword) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: Colors.purple.shade50,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Colors.purple.shade200,
width: 1,
),
),
child: Text(
keyword,
style: TextStyle(
color: Colors.purple.shade700,
fontSize: 12,
),
),
);
}).toList(),
),
],
// 进度条(如果需要显示)
if (showProgress) ...[
const SizedBox(height: 12),
_buildProgressBar(),
],
],
),
),
),
);
}
Widget _buildTypeChip() {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: _getTypeColor().withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: _getTypeColor(),
width: 1,
),
),
child: Text(
task.type.displayName,
style: TextStyle(
color: _getTypeColor(),
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
);
}
Widget _buildInfoChip({
required IconData icon,
required String label,
required Color color,
}) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 14,
color: color,
),
const SizedBox(width: 4),
Text(
label,
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
],
),
);
}
Widget _buildProgressBar() {
// TODO: 实现进度条逻辑
const progress = 0.6; // 示例进度
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'完成进度',
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 12,
),
),
Text(
'${(progress * 100).toInt()}%',
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
],
),
const SizedBox(height: 4),
LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey.shade200,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.purple.shade600,
),
),
],
);
}
Color _getTypeColor() {
switch (task.type) {
case WritingType.essay:
return Colors.blue;
case WritingType.letter:
return Colors.green;
case WritingType.report:
return Colors.orange;
case WritingType.story:
return Colors.purple;
case WritingType.review:
return Colors.red;
case WritingType.argument:
return Colors.teal;
case WritingType.article:
return Colors.indigo;
case WritingType.email:
return Colors.cyan;
case WritingType.diary:
return Colors.pink;
case WritingType.description:
return Colors.amber;
}
}
Color _getDifficultyColor() {
switch (task.difficulty) {
case WritingDifficulty.beginner:
return Colors.green;
case WritingDifficulty.elementary:
return Colors.lightGreen;
case WritingDifficulty.intermediate:
return Colors.orange;
case WritingDifficulty.upperIntermediate:
return Colors.deepOrange;
case WritingDifficulty.advanced:
return Colors.red;
}
}
}