feat(widgets): 优化 LeetCode 卡片样式和功能
- 添加图表图标和用户击败图标 - 优化难度显示,添加颜色区分 - 调整布局和样式,提升可读性 - 添加圆形头像和对勾图标 - 优化错误和空状态显示
This commit is contained in:
parent
1db7ced409
commit
4d9a554f0d
@ -135,33 +135,81 @@ class _LeetCodeCardState extends State<LeetCodeCard>
|
|||||||
_progress!['totalQuestionBeatsPercentage'] as double;
|
_progress!['totalQuestionBeatsPercentage'] as double;
|
||||||
|
|
||||||
return Card(
|
return Card(
|
||||||
|
elevation: 3,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.bar_chart, color: Colors.green),
|
||||||
|
const SizedBox(width: 8),
|
||||||
const Text(
|
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) {
|
...acceptedQuestions.map((q) {
|
||||||
final difficulty = q['difficulty'] as String;
|
final difficulty = q['difficulty'] as String;
|
||||||
final count = q['count'] as int;
|
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(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
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(),
|
const Divider(),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Text('击败用户',
|
const Row(
|
||||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
children: [
|
||||||
|
Icon(Icons.workspace_premium,
|
||||||
|
size: 18, color: Colors.green),
|
||||||
|
SizedBox(width: 6),
|
||||||
|
Text('击败用户', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
|
],
|
||||||
|
),
|
||||||
Text('${totalBeatsPercentage.toStringAsFixed(1)}%',
|
Text('${totalBeatsPercentage.toStringAsFixed(1)}%',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -178,6 +226,9 @@ class _LeetCodeCardState extends State<LeetCodeCard>
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
|
elevation: 4,
|
||||||
|
margin: const EdgeInsets.all(16),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -188,12 +239,23 @@ class _LeetCodeCardState extends State<LeetCodeCard>
|
|||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text(
|
||||||
'LeetCode 最近提交',
|
'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,
|
turns: _refreshController,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Icons.refresh, size: 28),
|
icon: const Icon(Icons.refresh,
|
||||||
|
size: 24, color: Colors.green),
|
||||||
onPressed: _isLoading
|
onPressed: _isLoading
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
@ -202,29 +264,43 @@ class _LeetCodeCardState extends State<LeetCodeCard>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (_isLoading)
|
if (_isLoading)
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
child: AnimatedBuilder(
|
child: AnimatedBuilder(
|
||||||
animation: _refreshController,
|
animation: _refreshController,
|
||||||
builder: (_, child) => Transform.rotate(
|
builder: (_, child) => Transform.rotate(
|
||||||
angle: _refreshController.value * 2 * 3.14,
|
angle: _refreshController.value * 2 * 3.14,
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
child: const CircularProgressIndicator(),
|
child: const CircularProgressIndicator(
|
||||||
|
color: Colors.green,
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else if (_error != null)
|
else if (_error != null)
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
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(
|
child: Text(
|
||||||
_error!,
|
_error!,
|
||||||
style: const TextStyle(color: Colors.red),
|
style: const TextStyle(color: Colors.red),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -239,8 +315,11 @@ class _LeetCodeCardState extends State<LeetCodeCard>
|
|||||||
const Center(
|
const Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(16.0),
|
padding: EdgeInsets.all(16.0),
|
||||||
child:
|
child: Text(
|
||||||
Text('暂无提交记录', style: TextStyle(fontSize: 16)),
|
'暂无提交记录',
|
||||||
|
style:
|
||||||
|
TextStyle(fontSize: 16, color: Colors.grey),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
@ -252,20 +331,40 @@ class _LeetCodeCardState extends State<LeetCodeCard>
|
|||||||
final submission = _submissions[index];
|
final submission = _submissions[index];
|
||||||
final question = submission['question'];
|
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(
|
title: Text(
|
||||||
question['translatedTitle'] ??
|
question['translatedTitle'] ??
|
||||||
question['title'],
|
question['title'],
|
||||||
style: const TextStyle(fontSize: 16),
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'提交时间: ${timeago.format(DateTime.fromMillisecondsSinceEpoch(submission['submitTime'] * 1000), locale: 'zh_CN')}',
|
'提交时间: ${timeago.format(DateTime.fromMillisecondsSinceEpoch(submission['submitTime'] * 1000), locale: 'zh_CN')}',
|
||||||
style: const TextStyle(fontSize: 14),
|
style: const TextStyle(fontSize: 14),
|
||||||
),
|
),
|
||||||
trailing: Text(
|
trailing: const Icon(
|
||||||
'#${question['questionFrontendId']}',
|
Icons.check_circle,
|
||||||
style: const TextStyle(
|
color: Colors.green,
|
||||||
fontSize: 14, fontWeight: FontWeight.bold),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user