ui细节优化

This commit is contained in:
Developer
2026-04-01 04:45:33 +08:00
parent 6517a78c7e
commit 79f7269319
23 changed files with 3299 additions and 885 deletions

View File

@@ -3,6 +3,8 @@ import '../../constants/app_constants.dart';
import '../../utils/http/http_client.dart';
import '../../models/poetry_model.dart';
import '../../controllers/load/locally.dart';
import '../../controllers/history_controller.dart';
import '../../services/network_listener_service.dart';
/// 时间: 2026-03-25
/// 功能: 热门页面
@@ -19,7 +21,11 @@ class PopularPage extends StatefulWidget {
class _PopularPageState extends State<PopularPage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
final List<String> _tabCategories = ['总榜', '日榜', '月榜'];
final List<Map<String, dynamic>> _tabCategories = [
{'label': '总榜', 'icon': Icons.bar_chart},
{'label': '日榜', 'icon': Icons.today},
{'label': '月榜', 'icon': Icons.calendar_today},
];
List<PoetryModel> _rankList = [];
bool _loading = false;
@@ -46,36 +52,46 @@ class _PopularPageState extends State<PopularPage>
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
body: Column(
children: [
// Tab栏
Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: TabBar(
controller: _tabController,
tabs: _tabCategories
.map((category) => Tab(text: category))
.toList(),
labelColor: AppConstants.primaryColor,
unselectedLabelColor: Colors.grey[600],
indicatorColor: AppConstants.primaryColor,
indicatorWeight: 3,
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
),
return Column(
children: [
// 黑色分割线
Container(height: 1, color: Colors.black.withValues(alpha: 0.1)),
// Tab栏
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: TabBar(
controller: _tabController,
tabs: _tabCategories
.map(
(category) => Tab(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(category['icon'], size: 16),
const SizedBox(width: 6),
Text(category['label']),
],
),
),
)
.toList(),
labelColor: AppConstants.primaryColor,
unselectedLabelColor: Colors.grey[600],
indicatorColor: AppConstants.primaryColor,
indicatorWeight: 3,
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
),
// 内容区域
Expanded(
child: TabBarView(
controller: _tabController,
children: _tabCategories.map((category) {
return _buildRankContent(category);
}).toList(),
),
),
// 内容区域
Expanded(
child: TabBarView(
controller: _tabController,
children: _tabCategories.map((category) {
return _buildRankContent(category['label']);
}).toList(),
),
],
),
),
],
);
}
@@ -158,8 +174,50 @@ class _PopularPageState extends State<PopularPage>
);
}
Future<void> _createNoteFromPoetry(PoetryModel poetry) async {
try {
final title = poetry.name.isNotEmpty ? poetry.name : '诗词笔记';
final category = poetry.alias.isNotEmpty ? poetry.alias : '诗词';
final contentBuffer = StringBuffer();
if (poetry.url.isNotEmpty) {
contentBuffer.writeln('出处:${poetry.url}');
}
if (poetry.name.isNotEmpty) {
contentBuffer.writeln('诗句:${poetry.name}');
}
if (poetry.alias.isNotEmpty) {
contentBuffer.writeln('朝代:${poetry.alias}');
}
final noteId = await HistoryController.saveNote(
title: title,
content: contentBuffer.toString().trim(),
category: category,
);
if (noteId != null) {
NetworkListenerService().sendSuccessEvent(
NetworkEventType.noteUpdate,
data: noteId,
);
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('已创建笔记')));
}
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('创建笔记失败: $e')));
}
}
}
Widget _buildRankItem(PoetryModel poetry, int index) {
final rank = poetry.rank > 0 ? poetry.rank : index; // 优先使用API返回的rank
final rank = poetry.rank > 0 ? poetry.rank : index;
final isTopThree = rank <= 3;
return Card(
@@ -179,120 +237,177 @@ class _PopularPageState extends State<PopularPage>
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
child: Stack(
clipBehavior: Clip.none,
children: [
// 排名徽章
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: isTopThree
? AppConstants.primaryColor
: AppConstants.primaryColor.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(20),
border: isTopThree
? null
: Border.all(
color: AppConstants.primaryColor.withValues(
alpha: 0.2,
),
width: 1,
),
),
child: Center(
child: Text(
rank.toString(),
style: TextStyle(
Row(
children: [
// 排名徽章
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: isTopThree
? Colors.white
: AppConstants.primaryColor.withValues(alpha: 0.8),
fontWeight: FontWeight.bold,
fontSize: 16,
? AppConstants.primaryColor
: AppConstants.primaryColor.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(20),
border: isTopThree
? null
: Border.all(
color: AppConstants.primaryColor.withValues(
alpha: 0.2,
),
width: 1,
),
),
child: Center(
child: Text(
rank.toString(),
style: TextStyle(
color: isTopThree
? Colors.white
: AppConstants.primaryColor.withValues(
alpha: 0.8,
),
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
),
),
const SizedBox(width: 12),
const SizedBox(width: 12),
// 内容区域
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题
Text(
poetry.name,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
// 朝代和作者
if (poetry.alias.isNotEmpty || poetry.url.isNotEmpty)
Row(
children: [
if (poetry.alias.isNotEmpty) ...[
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: AppConstants.primaryColor.withValues(
alpha: 0.1,
),
borderRadius: BorderRadius.circular(8),
),
child: Text(
poetry.alias,
style: TextStyle(
fontSize: 10,
color: AppConstants.primaryColor,
),
),
),
const SizedBox(width: 8),
],
if (poetry.url.isNotEmpty)
Expanded(
child: Text(
poetry.url,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 8),
// 统计数据
Row(
// 内容区域
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildStatItem(
'👁',
poetry.hitsTotal.toString(),
'总浏览',
// 标题
Text(
poetry.name,
style: Theme.of(context).textTheme.titleMedium
?.copyWith(fontWeight: FontWeight.bold),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(width: 16),
_buildStatItem('💖', poetry.like.toString(), '点赞'),
const SizedBox(width: 16),
if (_tabController.index == 1) // 日榜
_buildStatItem('📅', poetry.hitsDay.toString(), '今日'),
if (_tabController.index == 2) // 月榜
_buildStatItem(
'📊',
poetry.hitsMonth.toString(),
'本月',
const SizedBox(height: 4),
// 朝代和作者
if (poetry.alias.isNotEmpty || poetry.url.isNotEmpty)
Row(
children: [
if (poetry.alias.isNotEmpty) ...[
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: AppConstants.primaryColor.withValues(
alpha: 0.1,
),
borderRadius: BorderRadius.circular(8),
),
child: Text(
poetry.alias,
style: TextStyle(
fontSize: 10,
color: AppConstants.primaryColor,
),
),
),
const SizedBox(width: 8),
],
if (poetry.url.isNotEmpty)
Expanded(
child: Text(
poetry.url,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 8),
// 统计数据
Row(
children: [
_buildStatItem(
'👁',
poetry.hitsTotal.toString(),
'总浏览',
),
const SizedBox(width: 16),
_buildStatItem('💖', poetry.like.toString(), '点赞'),
const SizedBox(width: 16),
if (_tabController.index == 1)
_buildStatItem(
'📅',
poetry.hitsDay.toString(),
'今日',
),
if (_tabController.index == 2)
_buildStatItem(
'📊',
poetry.hitsMonth.toString(),
'本月',
),
],
),
],
),
],
),
],
),
// 添加笔记按钮 - 位于右下角,可遮挡字段
Positioned(
bottom: -8,
right: -8,
child: GestureDetector(
onTap: () => _createNoteFromPoetry(poetry),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 6,
),
decoration: BoxDecoration(
color: Colors.orange[700],
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.15),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.note_add,
size: 14,
color: Colors.white,
),
const SizedBox(width: 4),
const Text(
'笔记',
style: TextStyle(
fontSize: 11,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
),
],