feat(widgets): 优化 LeetCode 卡片样式和功能

- 添加图表图标和用户击败图标
- 优化难度显示,添加颜色区分
- 调整布局和样式,提升可读性
- 添加圆形头像和对勾图标
- 优化错误和空状态显示
This commit is contained in:
高手 2025-06-10 16:17:27 +08:00
parent 1db7ced409
commit 4d9a554f0d

View File

@ -135,33 +135,81 @@ class _LeetCodeCardState extends State<LeetCodeCard>
_progress!['totalQuestionBeatsPercentage'] as double;
return Card(
elevation: 3,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
margin: const EdgeInsets.symmetric(vertical: 8),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.bar_chart, color: Colors.green),
const SizedBox(width: 8),
const Text(
'解题进度',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
const SizedBox(height: 8),
),
],
),
const SizedBox(height: 12),
...acceptedQuestions.map((q) {
final difficulty = q['difficulty'] as String;
final count = q['count'] as int;
Color difficultyColor = Colors.grey;
if (difficulty == 'Easy')
difficultyColor = Colors.green;
else if (difficulty == 'Medium')
difficultyColor = Colors.orange;
else if (difficulty == 'Hard') difficultyColor = Colors.red;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
padding: const EdgeInsets.symmetric(vertical: 6.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text(difficulty), Text('$count')],
children: [
Row(
children: [
Container(
width: 12,
height: 12,
decoration: BoxDecoration(
color: difficultyColor,
shape: BoxShape.circle,
),
),
const SizedBox(width: 8),
Text(
difficulty == 'EASY'
? '简单'
: difficulty == 'MEDIUM'
? '中等'
: '困难',
style: const TextStyle(fontWeight: FontWeight.w500),
),
],
),
Text('$count', style: const TextStyle(fontSize: 14)),
],
),
);
}),
}).toList(),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('击败用户',
style: TextStyle(fontWeight: FontWeight.bold)),
const Row(
children: [
Icon(Icons.workspace_premium,
size: 18, color: Colors.green),
SizedBox(width: 6),
Text('击败用户', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
Text('${totalBeatsPercentage.toStringAsFixed(1)}%',
style: const TextStyle(
fontWeight: FontWeight.bold,
@ -178,6 +226,9 @@ class _LeetCodeCardState extends State<LeetCodeCard>
@override
Widget build(BuildContext context) {
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
elevation: 4,
margin: const EdgeInsets.all(16),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
@ -188,12 +239,23 @@ class _LeetCodeCardState extends State<LeetCodeCard>
children: [
const Text(
'LeetCode 最近提交',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.green,
),
RotationTransition(
),
Container(
decoration: BoxDecoration(
color: Colors.green.shade100,
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.all(8),
child: RotationTransition(
turns: _refreshController,
child: IconButton(
icon: const Icon(Icons.refresh, size: 28),
icon: const Icon(Icons.refresh,
size: 24, color: Colors.green),
onPressed: _isLoading
? null
: () async {
@ -202,29 +264,43 @@ class _LeetCodeCardState extends State<LeetCodeCard>
},
),
),
),
],
),
if (_isLoading)
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(24.0),
child: AnimatedBuilder(
animation: _refreshController,
builder: (_, child) => Transform.rotate(
angle: _refreshController.value * 2 * 3.14,
child: child,
),
child: const CircularProgressIndicator(),
child: const CircularProgressIndicator(
color: Colors.green,
strokeWidth: 2,
),
),
),
)
else if (_error != null)
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(24.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, color: Colors.red),
const SizedBox(width: 8),
Expanded(
child: Text(
_error!,
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
),
),
],
),
),
)
@ -239,8 +315,11 @@ class _LeetCodeCardState extends State<LeetCodeCard>
const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child:
Text('暂无提交记录', style: TextStyle(fontSize: 16)),
child: Text(
'暂无提交记录',
style:
TextStyle(fontSize: 16, color: Colors.grey),
),
),
)
else
@ -252,20 +331,40 @@ class _LeetCodeCardState extends State<LeetCodeCard>
final submission = _submissions[index];
final question = submission['question'];
return ListTile(
return Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
margin: const EdgeInsets.symmetric(vertical: 6),
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.green,
radius: 16,
child: Text(
question['questionFrontendId'].toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
),
title: Text(
question['translatedTitle'] ??
question['title'],
style: const TextStyle(fontSize: 16),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
'提交时间: ${timeago.format(DateTime.fromMillisecondsSinceEpoch(submission['submitTime'] * 1000), locale: 'zh_CN')}',
style: const TextStyle(fontSize: 14),
),
trailing: Text(
'#${question['questionFrontendId']}',
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.bold),
trailing: const Icon(
Icons.check_circle,
color: Colors.green,
),
),
);
},