init
This commit is contained in:
48
client/lib/features/home/models/learning_progress_model.dart
Normal file
48
client/lib/features/home/models/learning_progress_model.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
/// 学习进度模型
|
||||
class LearningProgress {
|
||||
final String id;
|
||||
final String title;
|
||||
final String category;
|
||||
final int totalWords;
|
||||
final int learnedWords;
|
||||
final double progress;
|
||||
final DateTime? lastStudyDate;
|
||||
|
||||
LearningProgress({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.category,
|
||||
required this.totalWords,
|
||||
required this.learnedWords,
|
||||
required this.progress,
|
||||
this.lastStudyDate,
|
||||
});
|
||||
|
||||
factory LearningProgress.fromJson(Map<String, dynamic> json) {
|
||||
return LearningProgress(
|
||||
id: json['id'] as String? ?? '',
|
||||
title: json['title'] as String? ?? '',
|
||||
category: json['category'] as String? ?? '',
|
||||
totalWords: json['total_words'] as int? ?? 0,
|
||||
learnedWords: json['learned_words'] as int? ?? 0,
|
||||
progress: (json['progress'] as num?)?.toDouble() ?? 0.0,
|
||||
lastStudyDate: json['last_study_date'] != null
|
||||
? DateTime.tryParse(json['last_study_date'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'category': category,
|
||||
'total_words': totalWords,
|
||||
'learned_words': learnedWords,
|
||||
'progress': progress,
|
||||
'last_study_date': lastStudyDate?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
String get progressPercentage => '${(progress * 100).toInt()}%';
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../models/learning_progress_model.dart';
|
||||
import '../services/learning_progress_service.dart';
|
||||
|
||||
/// 学习进度状态
|
||||
class LearningProgressState {
|
||||
final List<LearningProgress> progressList;
|
||||
final bool isLoading;
|
||||
final String? error;
|
||||
|
||||
LearningProgressState({
|
||||
this.progressList = const [],
|
||||
this.isLoading = false,
|
||||
this.error,
|
||||
});
|
||||
|
||||
LearningProgressState copyWith({
|
||||
List<LearningProgress>? progressList,
|
||||
bool? isLoading,
|
||||
String? error,
|
||||
}) {
|
||||
return LearningProgressState(
|
||||
progressList: progressList ?? this.progressList,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
error: error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 学习进度Notifier
|
||||
class LearningProgressNotifier extends StateNotifier<LearningProgressState> {
|
||||
final LearningProgressService _service = LearningProgressService();
|
||||
|
||||
LearningProgressNotifier() : super(LearningProgressState());
|
||||
|
||||
/// 加载学习进度
|
||||
Future<void> loadLearningProgress() async {
|
||||
state = state.copyWith(isLoading: true, error: null);
|
||||
|
||||
try {
|
||||
final response = await _service.getUserLearningProgress();
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
state = state.copyWith(
|
||||
progressList: response.data!,
|
||||
isLoading: false,
|
||||
);
|
||||
} else {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
error: response.message,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
error: '加载学习进度失败: $e',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新学习进度(强制重新加载,不使用缓存)
|
||||
Future<void> refreshLearningProgress() async {
|
||||
state = state.copyWith(isLoading: true, error: null);
|
||||
|
||||
try {
|
||||
// 强制重新加载,传入不同的时间戳来绕过缓存
|
||||
final response = await _service.getUserLearningProgress();
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
print('=== 刷新学习进度成功 ===');
|
||||
print('数据条数: ${response.data!.length}');
|
||||
state = state.copyWith(
|
||||
progressList: response.data!,
|
||||
isLoading: false,
|
||||
);
|
||||
} else {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
error: response.message,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('刷新学习进度失败: $e');
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
error: '刷新学习进度失败: $e',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 学习进度Provider
|
||||
final learningProgressProvider = StateNotifierProvider<LearningProgressNotifier, LearningProgressState>(
|
||||
(ref) => LearningProgressNotifier(),
|
||||
);
|
||||
|
||||
/// 学习进度列表Provider(便捷访问)
|
||||
final learningProgressListProvider = Provider<List<LearningProgress>>((ref) {
|
||||
return ref.watch(learningProgressProvider).progressList;
|
||||
});
|
||||
|
||||
/// 学习进度加载状态Provider
|
||||
final learningProgressLoadingProvider = Provider<bool>((ref) {
|
||||
return ref.watch(learningProgressProvider).isLoading;
|
||||
});
|
||||
800
client/lib/features/home/screens/home_screen.dart
Normal file
800
client/lib/features/home/screens/home_screen.dart
Normal file
@@ -0,0 +1,800 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/routes/app_routes.dart';
|
||||
import '../../vocabulary/providers/vocabulary_provider.dart';
|
||||
import '../../vocabulary/models/word_model.dart';
|
||||
import '../../auth/providers/auth_provider.dart';
|
||||
import '../../../shared/providers/notification_provider.dart';
|
||||
import '../../../core/services/tts_service.dart';
|
||||
|
||||
/// 首页界面
|
||||
class HomeScreen extends ConsumerStatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends ConsumerState<HomeScreen> {
|
||||
final TTSService _ttsService = TTSService();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 初始化TTS服务
|
||||
_ttsService.initialize();
|
||||
|
||||
// 页面首帧后触发数据加载(今日单词与统计)
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
print('=== HomeScreen: 开始加载数据 ===');
|
||||
final user = ref.read(currentUserProvider);
|
||||
print('当前用户: ${user?.username}, ID: ${user?.id}');
|
||||
|
||||
try {
|
||||
// 加载未读通知数量
|
||||
ref.read(notificationProvider.notifier).loadUnreadCount();
|
||||
|
||||
// 直接调用 Notifier 的方法
|
||||
final notifier = ref.read(vocabularyProvider.notifier);
|
||||
|
||||
print('开始加载今日单词...');
|
||||
await notifier.loadTodayStudyWords(userId: user?.id);
|
||||
print('今日单词加载完成,数量: ${ref.read(todayWordsProvider).length}');
|
||||
|
||||
print('开始加载统计数据...');
|
||||
await notifier.loadUserVocabularyOverallStats();
|
||||
await notifier.loadWeeklyStudyStats();
|
||||
print('统计数据加载完成');
|
||||
} catch (e, stack) {
|
||||
print('数据加载失败: $e');
|
||||
print('堆栈: $stack');
|
||||
}
|
||||
print('=== HomeScreen: 数据加载结束 ===');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 释放TTS资源
|
||||
_ttsService.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF5F5F5),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
const SizedBox(height: 20),
|
||||
_buildQuickActions(context),
|
||||
const SizedBox(height: 20),
|
||||
_buildLearningStats(context),
|
||||
const SizedBox(height: 20),
|
||||
_buildTodayWords(),
|
||||
const SizedBox(height: 20),
|
||||
_buildAIRecommendation(context),
|
||||
const SizedBox(height: 100), // 底部导航栏空间
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
// 直接使用StateNotifierProvider获取认证状态
|
||||
final authState = ref.watch(authProvider);
|
||||
final user = authState.user;
|
||||
final isAuthenticated = authState.isAuthenticated;
|
||||
final unreadCount = ref.watch(unreadCountProvider);
|
||||
final avatarUrl = user?.profile?.avatar ?? user?.avatar;
|
||||
final displayName = user?.profile?.realName ?? user?.username ?? '未登录用户';
|
||||
final motto = user?.profile?.bio ?? '欢迎来到AI英语学习';
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
// 点击头部跳转:未登录->登录页,已登录->个人中心
|
||||
if (isAuthenticated) {
|
||||
Navigator.pushNamed(context, Routes.profile);
|
||||
} else {
|
||||
Navigator.pushNamed(context, Routes.login);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF2196F3), Color(0xFF1976D2)],
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 25,
|
||||
backgroundColor: Colors.white,
|
||||
backgroundImage: avatarUrl != null && avatarUrl.isNotEmpty
|
||||
? NetworkImage(avatarUrl)
|
||||
: null,
|
||||
child: (avatarUrl == null || avatarUrl.isEmpty)
|
||||
? Icon(
|
||||
Icons.person,
|
||||
color: isAuthenticated ? const Color(0xFF2196F3) : Colors.grey,
|
||||
size: 24,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
displayName,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
motto,
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Stack(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// TODO: 跳转到通知页面
|
||||
Navigator.pushNamed(context, '/notifications');
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.notifications_outlined,
|
||||
color: Colors.white,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
if (unreadCount > 0)
|
||||
Positioned(
|
||||
right: 8,
|
||||
top: 8,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.red,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 18,
|
||||
minHeight: 18,
|
||||
),
|
||||
child: Text(
|
||||
unreadCount > 99 ? '99+' : unreadCount.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildQuickActions(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 4, bottom: 12),
|
||||
child: Text(
|
||||
'快速功能',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF333333),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildQuickActionCard(
|
||||
context,
|
||||
'智能复习',
|
||||
'基于记忆曲线',
|
||||
Icons.psychology,
|
||||
const Color(0xFF4CAF50),
|
||||
() => Navigator.pushNamed(context, '/vocabulary/smart-review'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildQuickActionCard(
|
||||
context,
|
||||
'词汇测试',
|
||||
'检测学习效果',
|
||||
Icons.quiz,
|
||||
const Color(0xFFFF9800),
|
||||
() => Navigator.pushNamed(context, '/vocabulary/test'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildQuickActionCard(
|
||||
context,
|
||||
'生词本',
|
||||
'收藏重要单词',
|
||||
Icons.bookmark,
|
||||
const Color(0xFF9C27B0),
|
||||
() => Navigator.pushNamed(context, '/vocabulary/word-book'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildQuickActionCard(
|
||||
context,
|
||||
'学习计划',
|
||||
'制定学习目标',
|
||||
Icons.schedule,
|
||||
const Color(0xFF2196F3),
|
||||
() => Navigator.pushNamed(context, '/vocabulary/study-plan'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickActionCard(
|
||||
BuildContext context,
|
||||
String title,
|
||||
String subtitle,
|
||||
IconData icon,
|
||||
Color color,
|
||||
VoidCallback onTap,
|
||||
) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF333333),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLearningStats(BuildContext context) {
|
||||
final statistics = ref.watch(todayStatisticsProvider);
|
||||
final dailyStats = ref.watch(dailyVocabularyStatsProvider);
|
||||
final weeklyStudied = ref.watch(weeklyWordsStudiedProvider);
|
||||
final overallStats = ref.watch(overallVocabularyStatsProvider) ?? {};
|
||||
final user = ref.watch(currentUserProvider);
|
||||
final todayStudied = dailyStats?.wordsLearned ?? statistics?.wordsStudied ?? 0;
|
||||
final totalStudied = (overallStats['total_studied'] as int?) ?? 0;
|
||||
final weeklyGoal = ((user?.settings?.dailyWordGoal ?? 20) * 7);
|
||||
final progress = weeklyGoal > 0 ? (weeklyStudied / weeklyGoal).clamp(0.0, 1.0) : 0.0;
|
||||
final progressPercentText = '${(progress * 100).toInt()}%';
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'学习统计',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF333333),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(Routes.learningStatsDetail);
|
||||
},
|
||||
child: const Text(
|
||||
'查看详情',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF2196F3),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
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: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStatCard(todayStudied.toString(), '今日学习', Icons.today, const Color(0xFF4CAF50)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildStatCard(weeklyStudied.toString(), '本周学习', Icons.date_range, const Color(0xFF2196F3)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildStatCard(totalStudied.toString(), '总词汇量', Icons.library_books, const Color(0xFFFF9800)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2196F3).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.trending_up,
|
||||
color: Color(0xFF2196F3),
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'本周学习进度',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF333333),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
progressPercentText,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF2196F3),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 60,
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: progress,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2196F3),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard(String value, String label, IconData icon, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodayWords() {
|
||||
final words = ref.watch(todayWordsProvider);
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'今日单词',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, Routes.dailyWords);
|
||||
},
|
||||
child: const Text('查看更多'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
words.isEmpty
|
||||
? Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.book_outlined,
|
||||
size: 48,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'暂无今日单词',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// 触发加载今日单词
|
||||
final notifier = ref.read(vocabularyProvider.notifier);
|
||||
final user = ref.read(currentUserProvider);
|
||||
await notifier.loadTodayStudyWords(userId: user?.id);
|
||||
},
|
||||
child: const Text('加载今日单词'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
_buildWordItem(words[0]),
|
||||
if (words.length > 1) ...[
|
||||
const SizedBox(height: 12),
|
||||
_buildWordItem(words[1]),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodayWordsOld() {
|
||||
final vocabAsync = ref.watch(vocabularyProvider);
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
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: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'今日单词',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, Routes.dailyWords);
|
||||
},
|
||||
child: const Text('查看更多'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final state = ref.watch(vocabularyProvider);
|
||||
final words = state.todayWords;
|
||||
if (words.isEmpty) {
|
||||
return Column(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.book_outlined,
|
||||
size: 48,
|
||||
color: Colors.grey,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'暂无今日单词',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final user = ref.read(currentUserProvider);
|
||||
final notifier = ref.read(vocabularyProvider.notifier);
|
||||
await notifier.loadTodayStudyWords(userId: user?.id);
|
||||
},
|
||||
child: const Text('刷新'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
_buildWordItem(words[0]),
|
||||
if (words.length > 1) ...[
|
||||
const SizedBox(height: 12),
|
||||
_buildWordItem(words[1]),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWordItem(Word word) {
|
||||
final meaning = word.definitions.isNotEmpty ? word.definitions.first.definition : '';
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
word.word,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
meaning,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
// 播放单词发音
|
||||
await _ttsService.speak(word.word);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.volume_up,
|
||||
color: Color(0xFF2196F3),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAIRecommendation(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, '/ai');
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
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: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2196F3).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.smart_toy,
|
||||
color: Color(0xFF2196F3),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'AI 智能助手',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'写作批改 • 口语评估 • 智能推荐\n点击体验AI学习助手',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
color: Colors.grey,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,722 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../shared/widgets/custom_app_bar.dart';
|
||||
import '../../../shared/widgets/custom_card.dart';
|
||||
import '../../vocabulary/models/learning_stats_model.dart';
|
||||
import '../../vocabulary/services/learning_stats_service.dart';
|
||||
import '../../../core/services/storage_service.dart';
|
||||
import '../../../core/network/api_client.dart';
|
||||
|
||||
/// 学习统计详情页面
|
||||
class LearningStatsDetailScreen extends ConsumerStatefulWidget {
|
||||
const LearningStatsDetailScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<LearningStatsDetailScreen> createState() => _LearningStatsDetailScreenState();
|
||||
}
|
||||
|
||||
class _LearningStatsDetailScreenState extends ConsumerState<LearningStatsDetailScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
LearningStats? _stats;
|
||||
bool _isLoading = true;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
_loadStats();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadStats() async {
|
||||
try {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
final storageService = await StorageService.getInstance();
|
||||
final apiClient = ApiClient.instance;
|
||||
|
||||
final statsService = LearningStatsService(
|
||||
apiClient: apiClient,
|
||||
storageService: storageService,
|
||||
);
|
||||
|
||||
// 从本地存储加载统计数据
|
||||
final stats = await statsService.getUserStats();
|
||||
|
||||
setState(() {
|
||||
_stats = stats;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
print('❌ 加载学习统计失败: $e');
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: CustomAppBar(
|
||||
title: '学习统计详情',
|
||||
automaticallyImplyLeading: true,
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _error != null
|
||||
? _buildErrorWidget()
|
||||
: _buildContent(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorWidget() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: AppColors.error,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'加载失败',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_error ?? '未知错误',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: _loadStats,
|
||||
child: const Text('重试'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
if (_stats == null) return const SizedBox.shrink();
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildOverviewCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTabBar(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildDailyTab(),
|
||||
_buildWeeklyTab(),
|
||||
_buildMonthlyTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOverviewCard() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
child: CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'总体统计',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildOverviewItem(
|
||||
'学习天数',
|
||||
'${_stats!.totalStudyDays}',
|
||||
'天',
|
||||
Icons.calendar_today,
|
||||
AppColors.primary,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _buildOverviewItem(
|
||||
'连续学习',
|
||||
'${_stats!.currentStreak}',
|
||||
'天',
|
||||
Icons.local_fire_department,
|
||||
AppColors.warning,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildOverviewItem(
|
||||
'学习单词',
|
||||
'${_stats!.totalWordsLearned}',
|
||||
'个',
|
||||
Icons.school,
|
||||
AppColors.success,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _buildOverviewItem(
|
||||
'学习时长',
|
||||
'${_stats!.totalStudyHours.toStringAsFixed(1)}',
|
||||
'小时',
|
||||
Icons.access_time,
|
||||
AppColors.info,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildProgressBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOverviewItem(String title, String value, String unit, IconData icon, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: value,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: ' $unit',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProgressBar() {
|
||||
final progress = _stats!.progressPercentage;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'本周学习进度',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${(progress * 100).toInt()}%',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
value: progress,
|
||||
backgroundColor: AppColors.surfaceVariant,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppColors.primary),
|
||||
minHeight: 8,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBar() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceVariant,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
indicator: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: AppColors.onSurfaceVariant,
|
||||
tabs: const [
|
||||
Tab(text: '每日'),
|
||||
Tab(text: '每周'),
|
||||
Tab(text: '每月'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDailyTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildDailyChart(),
|
||||
const SizedBox(height: 16),
|
||||
_buildDailyStats(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeeklyTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildWeeklyChart(),
|
||||
const SizedBox(height: 16),
|
||||
_buildWeeklyStats(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMonthlyTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildMonthlyChart(),
|
||||
const SizedBox(height: 16),
|
||||
_buildMonthlyStats(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDailyChart() {
|
||||
return CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'每日学习趋势',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: LineChart(
|
||||
LineChartData(
|
||||
gridData: FlGridData(show: false),
|
||||
titlesData: FlTitlesData(
|
||||
leftTitles: AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
rightTitles: AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
topTitles: AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
interval: 1,
|
||||
getTitlesWidget: (value, meta) {
|
||||
const days = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
final index = value.toInt();
|
||||
if (index >= 0 && index < days.length) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
days[index],
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
);
|
||||
}
|
||||
return const Text('');
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
spots: _generateDailySpots(),
|
||||
isCurved: true,
|
||||
color: AppColors.primary,
|
||||
barWidth: 3,
|
||||
dotData: FlDotData(show: true),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeeklyChart() {
|
||||
// 计算最大值,用于设置柱状图的y轴范围
|
||||
double maxY = 100;
|
||||
if (_stats != null && _stats!.monthlyStats.weeklyRecords.isNotEmpty) {
|
||||
final maxWords = _stats!.monthlyStats.weeklyRecords
|
||||
.map((r) => r.wordsLearned)
|
||||
.reduce((a, b) => a > b ? a : b);
|
||||
maxY = (maxWords * 1.2).ceilToDouble(); // 留有20%的上边距
|
||||
if (maxY < 10) maxY = 10; // 最小值10
|
||||
}
|
||||
|
||||
return CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'每周学习统计',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: BarChart(
|
||||
BarChartData(
|
||||
alignment: BarChartAlignment.spaceAround,
|
||||
maxY: maxY,
|
||||
barTouchData: BarTouchData(enabled: false),
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTitlesWidget: (value, meta) {
|
||||
const weeks = ['第1周', '第2周', '第3周', '第4周'];
|
||||
if (value.toInt() >= 0 && value.toInt() < weeks.length) {
|
||||
return Text(
|
||||
weeks[value.toInt()],
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
);
|
||||
}
|
||||
return const Text('');
|
||||
},
|
||||
),
|
||||
),
|
||||
leftTitles: AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
topTitles: AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
rightTitles: AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
barGroups: _generateWeeklyBars(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMonthlyChart() {
|
||||
return CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'月度学习分析',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
height: 200,
|
||||
child: PieChart(
|
||||
PieChartData(
|
||||
sections: _generatePieChartSections(),
|
||||
centerSpaceRadius: 40,
|
||||
sectionsSpace: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDailyStats() {
|
||||
return CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'今日详情',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildStatRow('学习单词', '${_stats!.weeklyStats.wordsLearned ~/ 7}', '个'),
|
||||
_buildStatRow('复习单词', '${_stats!.weeklyStats.wordsReviewed ~/ 7}', '个'),
|
||||
_buildStatRow('学习时长', '${(_stats!.weeklyStats.studyHours / 7).toStringAsFixed(1)}', '小时'),
|
||||
_buildStatRow('准确率', '${(_stats!.weeklyStats.accuracyRate * 100).toInt()}', '%'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeeklyStats() {
|
||||
return CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'本周详情',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildStatRow('学习天数', '${_stats!.weeklyStats.studyDays}', '天'),
|
||||
_buildStatRow('学习单词', '${_stats!.weeklyStats.wordsLearned}', '个'),
|
||||
_buildStatRow('复习单词', '${_stats!.weeklyStats.wordsReviewed}', '个'),
|
||||
_buildStatRow('学习时长', '${_stats!.weeklyStats.studyHours.toStringAsFixed(1)}', '小时'),
|
||||
_buildStatRow('准确率', '${(_stats!.weeklyStats.accuracyRate * 100).toInt()}', '%'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMonthlyStats() {
|
||||
return CustomCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'本月详情',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildStatRow('学习天数', '${_stats!.monthlyStats.studyDays}', '天'),
|
||||
_buildStatRow('学习单词', '${_stats!.monthlyStats.wordsLearned}', '个'),
|
||||
_buildStatRow('复习单词', '${_stats!.monthlyStats.wordsReviewed}', '个'),
|
||||
_buildStatRow('学习时长', '${(_stats!.monthlyStats.studyTimeMinutes / 60).toStringAsFixed(1)}', '小时'),
|
||||
_buildStatRow('准确率', '${(_stats!.monthlyStats.accuracyRate * 100).toInt()}', '%'),
|
||||
_buildStatRow('完成词汇书', '${_stats!.monthlyStats.completedBooks}', '本'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatRow(String label, String value, String unit) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: value,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: ' $unit',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<FlSpot> _generateDailySpots() {
|
||||
if (_stats == null || _stats!.weeklyStats.dailyRecords.isEmpty) {
|
||||
// 如果没有数据,返回空数组
|
||||
return [];
|
||||
}
|
||||
|
||||
// 使用最近7天的真实数据
|
||||
final dailyRecords = _stats!.weeklyStats.dailyRecords;
|
||||
final spots = <FlSpot>[];
|
||||
|
||||
// 获取最近7天的记录
|
||||
final now = DateTime.now();
|
||||
for (int i = 6; i >= 0; i--) {
|
||||
final targetDate = now.subtract(Duration(days: i));
|
||||
final dateStr = '${targetDate.year}-${targetDate.month.toString().padLeft(2, '0')}-${targetDate.day.toString().padLeft(2, '0')}';
|
||||
|
||||
// 查找该日期的记录
|
||||
final record = dailyRecords.where((r) {
|
||||
final recordDateStr = '${r.date.year}-${r.date.month.toString().padLeft(2, '0')}-${r.date.day.toString().padLeft(2, '0')}';
|
||||
return recordDateStr == dateStr;
|
||||
}).firstOrNull;
|
||||
|
||||
// 添加数据点(x轴:0-6表示周一到周日,y轴:学习单词数)
|
||||
final wordsCount = record?.wordsLearned.toDouble() ?? 0.0;
|
||||
spots.add(FlSpot((6 - i).toDouble(), wordsCount));
|
||||
}
|
||||
|
||||
return spots;
|
||||
}
|
||||
|
||||
List<BarChartGroupData> _generateWeeklyBars() {
|
||||
if (_stats == null || _stats!.monthlyStats.weeklyRecords.isEmpty) {
|
||||
// 如果没有数据,返回空数组
|
||||
return [];
|
||||
}
|
||||
|
||||
// 使用月度统计中的周记录
|
||||
final weeklyRecords = _stats!.monthlyStats.weeklyRecords;
|
||||
final bars = <BarChartGroupData>[];
|
||||
|
||||
// 最多显示4周的数据
|
||||
for (int i = 0; i < weeklyRecords.length && i < 4; i++) {
|
||||
final record = weeklyRecords[i];
|
||||
bars.add(
|
||||
BarChartGroupData(
|
||||
x: i,
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: record.wordsLearned.toDouble(),
|
||||
color: AppColors.primary,
|
||||
width: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return bars;
|
||||
}
|
||||
|
||||
List<PieChartSectionData> _generatePieChartSections() {
|
||||
if (_stats == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 使用月度统计数据计算比例
|
||||
final monthlyStats = _stats!.monthlyStats;
|
||||
final totalWords = monthlyStats.wordsLearned + monthlyStats.wordsReviewed;
|
||||
|
||||
if (totalWords == 0) {
|
||||
// 如果没有数据,显示默认状态
|
||||
return [
|
||||
PieChartSectionData(
|
||||
color: AppColors.surfaceVariant,
|
||||
value: 100,
|
||||
title: '暂无数据',
|
||||
radius: 60,
|
||||
titleStyle: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
// 计算新学单词和复习单词的比例
|
||||
final newWordsPercent = (monthlyStats.wordsLearned / totalWords * 100).toInt();
|
||||
final reviewWordsPercent = (monthlyStats.wordsReviewed / totalWords * 100).toInt();
|
||||
|
||||
return [
|
||||
PieChartSectionData(
|
||||
color: AppColors.primary,
|
||||
value: monthlyStats.wordsLearned.toDouble(),
|
||||
title: '新学\n$newWordsPercent%',
|
||||
radius: 60,
|
||||
titleStyle: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
PieChartSectionData(
|
||||
color: AppColors.success,
|
||||
value: monthlyStats.wordsReviewed.toDouble(),
|
||||
title: '复习\n$reviewWordsPercent%',
|
||||
radius: 60,
|
||||
titleStyle: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
54
client/lib/features/home/screens/simple_home_screen.dart
Normal file
54
client/lib/features/home/screens/simple_home_screen.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 简化版主页面 - 用于测试应用启动
|
||||
class SimpleHomeScreen extends StatelessWidget {
|
||||
const SimpleHomeScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('AI英语学习平台'),
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.school,
|
||||
size: 100,
|
||||
color: Colors.blue,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
Text(
|
||||
'欢迎使用AI英语学习平台',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'智能化英语学习体验',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
Text(
|
||||
'应用启动成功!',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.green,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import '../../../core/models/api_response.dart';
|
||||
import '../../../core/services/enhanced_api_service.dart';
|
||||
import '../models/learning_progress_model.dart';
|
||||
|
||||
/// 学习进度服务
|
||||
class LearningProgressService {
|
||||
static final LearningProgressService _instance = LearningProgressService._internal();
|
||||
factory LearningProgressService() => _instance;
|
||||
LearningProgressService._internal();
|
||||
|
||||
final EnhancedApiService _enhancedApiService = EnhancedApiService();
|
||||
|
||||
// 缓存时长配置
|
||||
static const Duration _shortCacheDuration = Duration(minutes: 5);
|
||||
|
||||
/// 获取用户学习进度列表
|
||||
Future<ApiResponse<List<LearningProgress>>> getUserLearningProgress({
|
||||
int page = 1,
|
||||
int limit = 20,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _enhancedApiService.get<List<LearningProgress>>(
|
||||
'/user/learning-progress',
|
||||
queryParameters: {
|
||||
'page': page,
|
||||
'limit': limit,
|
||||
},
|
||||
cacheDuration: _shortCacheDuration,
|
||||
fromJson: (data) {
|
||||
final progressList = data['progress'] as List?;
|
||||
print('=== 学习进度数据解析 ===');
|
||||
print('progress字段: $progressList');
|
||||
print('数据条数: ${progressList?.length ?? 0}');
|
||||
if (progressList == null || progressList.isEmpty) {
|
||||
// 返回空列表,不使用默认数据
|
||||
print('后端返回空数据,显示空状态');
|
||||
return [];
|
||||
}
|
||||
final result = progressList.map((json) => LearningProgress.fromJson(json)).toList();
|
||||
print('解析后的数据条数: ${result.length}');
|
||||
return result;
|
||||
},
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
return ApiResponse.success(message: '获取成功', data: response.data!);
|
||||
} else {
|
||||
// 如果API失败,返回空列表
|
||||
return ApiResponse.success(
|
||||
message: '获取失败',
|
||||
data: [],
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// 出错时返回空列表
|
||||
print('获取学习进度异常: $e');
|
||||
return ApiResponse.success(
|
||||
message: '获取失败',
|
||||
data: [],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 获取用户学习统计
|
||||
Future<ApiResponse<Map<String, dynamic>>> getUserStats({
|
||||
String timeRange = 'all',
|
||||
}) async {
|
||||
try {
|
||||
final response = await _enhancedApiService.get<Map<String, dynamic>>(
|
||||
'/user/stats',
|
||||
queryParameters: {
|
||||
'time_range': timeRange,
|
||||
},
|
||||
cacheDuration: _shortCacheDuration,
|
||||
fromJson: (data) => data,
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
return ApiResponse.success(message: '获取成功', data: response.data!);
|
||||
} else {
|
||||
return ApiResponse.error(message: response.message);
|
||||
}
|
||||
} catch (e) {
|
||||
return ApiResponse.error(message: '获取统计数据失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
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