深色模式、首页设置页面和功能优化
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,14 @@
|
||||
/// 时间: 2025-03-22
|
||||
/// 功能: 诗词页面组件部分
|
||||
/// 介绍: 包含诗词卡片、操作按钮、统计信息等组件的独立文件
|
||||
/// 最新变化: 重构代码结构,使用工具类简化代码
|
||||
/// 最新变化: 2026-04-02 支持深色模式
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import '../../../utils/http/poetry_api.dart';
|
||||
import '../../../utils/audio_manager.dart';
|
||||
import 'home_components.dart';
|
||||
import 'set/home_components.dart';
|
||||
|
||||
/// 诗词卡片组件 - 优化版本,防止拉伸和处理文本溢出
|
||||
class PoetryCard extends StatefulWidget {
|
||||
@@ -18,6 +17,7 @@ class PoetryCard extends StatefulWidget {
|
||||
final VoidCallback? onTap;
|
||||
final Map<String, bool>? sectionLoadingStates;
|
||||
final GlobalKey? repaintKey;
|
||||
final bool isDark;
|
||||
|
||||
const PoetryCard({
|
||||
super.key,
|
||||
@@ -26,6 +26,7 @@ class PoetryCard extends StatefulWidget {
|
||||
this.onTap,
|
||||
this.sectionLoadingStates,
|
||||
this.repaintKey,
|
||||
this.isDark = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -35,12 +36,12 @@ class PoetryCard extends StatefulWidget {
|
||||
class _PoetryCardState extends State<PoetryCard> {
|
||||
bool _showCopyTip = true;
|
||||
bool _showRecommendation = false;
|
||||
bool _globalTipsEnabled = true; // 添加全局Tips开关状态
|
||||
bool _globalTipsEnabled = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadGlobalTipsSettings(); // 加载全局Tips设置
|
||||
_loadGlobalTipsSettings();
|
||||
}
|
||||
|
||||
String _getTimeOfDayGreeting() {
|
||||
@@ -85,7 +86,6 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载全局Tips设置
|
||||
Future<void> _loadGlobalTipsSettings() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -95,7 +95,6 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果加载失败,默认开启
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_globalTipsEnabled = true;
|
||||
@@ -106,11 +105,10 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = widget.isDark;
|
||||
final card = GestureDetector(
|
||||
onTap: () {
|
||||
// 播放点击音效(不等待完成)
|
||||
AudioManager().playClickSound();
|
||||
// 调用原始的onTap回调
|
||||
widget.onTap?.call();
|
||||
},
|
||||
child: Stack(
|
||||
@@ -118,11 +116,11 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
color: isDark ? const Color(0xFF1E1E1E) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(10),
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 10),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@@ -131,19 +129,18 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildTimeBar(),
|
||||
_buildTimeBar(isDark),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildTitleSection(),
|
||||
_buildTitleSection(isDark),
|
||||
if (widget.poetryData.drtime.isNotEmpty) ...[
|
||||
_buildContentSection(context),
|
||||
_buildContentSection(context, isDark),
|
||||
const SizedBox(height: 3),
|
||||
],
|
||||
// 精选诗句标签 - 放在缝隙位置
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Container(
|
||||
@@ -173,14 +170,14 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildNameSection(),
|
||||
_buildNameSection(isDark),
|
||||
const SizedBox(height: 12),
|
||||
if (widget.keywordList.isNotEmpty) ...[
|
||||
_buildKeywordSection(),
|
||||
_buildKeywordSection(isDark),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
if (widget.poetryData.introduce.isNotEmpty) ...[
|
||||
_buildIntroductionSection(context),
|
||||
_buildIntroductionSection(context, isDark),
|
||||
],
|
||||
],
|
||||
),
|
||||
@@ -188,7 +185,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildCopyTip(),
|
||||
_buildCopyTip(isDark),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -199,7 +196,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
return card;
|
||||
}
|
||||
|
||||
Widget _buildTimeBar() {
|
||||
Widget _buildTimeBar(bool isDark) {
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
@@ -254,7 +251,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCopyTip() {
|
||||
Widget _buildCopyTip(bool isDark) {
|
||||
if (!_globalTipsEnabled || !_showCopyTip) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
@@ -299,7 +296,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTitleSection() {
|
||||
Widget _buildTitleSection(bool isDark) {
|
||||
final isLoading = widget.sectionLoadingStates?['title'] ?? false;
|
||||
|
||||
return SizedBox(
|
||||
@@ -313,6 +310,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
context,
|
||||
widget.poetryData.url,
|
||||
'诗人和标题',
|
||||
isDark: isDark,
|
||||
),
|
||||
child: isLoading
|
||||
? Row(
|
||||
@@ -332,7 +330,9 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
'出处加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
color: isDark
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
@@ -340,10 +340,10 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
)
|
||||
: Text(
|
||||
"出处: ${widget.poetryData.url}",
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: Colors.black,
|
||||
color: isDark ? Colors.grey[200] : Colors.black,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -357,7 +357,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNameSection() {
|
||||
Widget _buildNameSection(bool isDark) {
|
||||
final isLoading = widget.sectionLoadingStates?['name'] ?? false;
|
||||
|
||||
return Container(
|
||||
@@ -366,21 +366,27 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
margin: EdgeInsets.zero,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppConstants.primaryColor.withAlpha(26),
|
||||
AppConstants.primaryColor.withAlpha(13),
|
||||
],
|
||||
colors: isDark
|
||||
? [const Color(0xFF2A2A2A), const Color(0xFF252525)]
|
||||
: [
|
||||
AppConstants.primaryColor.withAlpha(26),
|
||||
AppConstants.primaryColor.withAlpha(13),
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppConstants.primaryColor.withAlpha(51),
|
||||
color: isDark
|
||||
? Colors.grey[700]!
|
||||
: AppConstants.primaryColor.withAlpha(51),
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.primaryColor.withAlpha(26),
|
||||
color: isDark
|
||||
? Colors.black.withAlpha(40)
|
||||
: AppConstants.primaryColor.withAlpha(26),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@@ -390,8 +396,12 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onLongPress: () =>
|
||||
CopyUtils.showCopyDialog(context, widget.poetryData.name, '诗词'),
|
||||
onLongPress: () => CopyUtils.showCopyDialog(
|
||||
context,
|
||||
widget.poetryData.name,
|
||||
'诗词',
|
||||
isDark: isDark,
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
child: Column(
|
||||
@@ -411,7 +421,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
'诗句加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -419,10 +429,10 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
)
|
||||
: Text(
|
||||
_formatPoetryText(widget.poetryData.name),
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
color: isDark ? Colors.grey[100] : Colors.black87,
|
||||
height: 1.4,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
@@ -434,30 +444,25 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
}
|
||||
|
||||
String _formatPoetryText(String text) {
|
||||
// 检查文本长度(文字+符号)
|
||||
if (text.length < 10) {
|
||||
return text; // 小于10个字,不换行
|
||||
return text;
|
||||
}
|
||||
|
||||
// 找到第一个逗号的位置
|
||||
final commaIndex = text.indexOf(',');
|
||||
if (commaIndex != -1) {
|
||||
// 在第一个逗号处添加换行
|
||||
return text.replaceFirst(',', ',\n');
|
||||
}
|
||||
|
||||
return text; // 没有逗号,保持原样
|
||||
return text;
|
||||
}
|
||||
|
||||
Widget _buildKeywordSection() {
|
||||
Widget _buildKeywordSection(bool isDark) {
|
||||
final isLoading = widget.sectionLoadingStates?['keywords'] ?? false;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// 第一行:关键词和朝代(左边)vs 星星和点赞(右边)
|
||||
Row(
|
||||
children: [
|
||||
// 左边:关键词和朝代
|
||||
Expanded(
|
||||
child: isLoading
|
||||
? Center(
|
||||
@@ -479,7 +484,9 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
'关键词加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
color: isDark
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -490,39 +497,43 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
if (widget.keywordList.isNotEmpty)
|
||||
...widget.keywordList
|
||||
.map(
|
||||
(keyword) => Builder(
|
||||
builder: (context) => GestureDetector(
|
||||
onLongPress: () => CopyUtils.showCopyDialog(
|
||||
context,
|
||||
keyword,
|
||||
'关键词',
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.secondaryColor
|
||||
.withAlpha(26),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
keyword,
|
||||
style: TextStyle(
|
||||
color: AppConstants.secondaryColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
...widget.keywordList.map(
|
||||
(keyword) => Builder(
|
||||
builder: (context) => GestureDetector(
|
||||
onLongPress: () => CopyUtils.showCopyDialog(
|
||||
context,
|
||||
keyword,
|
||||
'关键词',
|
||||
isDark: isDark,
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark
|
||||
? AppConstants.secondaryColor.withAlpha(
|
||||
40,
|
||||
)
|
||||
: AppConstants.secondaryColor.withAlpha(
|
||||
26,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
keyword,
|
||||
style: TextStyle(
|
||||
color: AppConstants.secondaryColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.poetryData.alias.isNotEmpty)
|
||||
Builder(
|
||||
builder: (context) => GestureDetector(
|
||||
@@ -530,6 +541,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
context,
|
||||
widget.poetryData.alias,
|
||||
'朝代',
|
||||
isDark: isDark,
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
@@ -537,9 +549,9 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.primaryColor.withAlpha(
|
||||
26,
|
||||
),
|
||||
color: isDark
|
||||
? AppConstants.primaryColor.withAlpha(40)
|
||||
: AppConstants.primaryColor.withAlpha(26),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
@@ -558,7 +570,6 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
],
|
||||
),
|
||||
),
|
||||
// 右边:星星和点赞
|
||||
if (!isLoading)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -570,14 +581,20 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
PoetryDataUtils.generateLikeText(widget.poetryData.like),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
PoetryDataUtils.generateViewText(
|
||||
widget.poetryData.hitsTotal,
|
||||
),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -587,344 +604,162 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContentSection(BuildContext context) {
|
||||
Widget _buildContentSection(BuildContext context, bool isDark) {
|
||||
final isLoading = widget.sectionLoadingStates?['content'] ?? false;
|
||||
|
||||
return GestureDetector(
|
||||
onLongPress: () =>
|
||||
CopyUtils.showCopyDialog(context, widget.poetryData.drtime, '原文'),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
constraints: const BoxConstraints(maxHeight: 200),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8F8F8),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
return Builder(
|
||||
builder: (context) => GestureDetector(
|
||||
onLongPress: () => CopyUtils.showCopyDialog(
|
||||
context,
|
||||
widget.poetryData.drtime,
|
||||
'时间',
|
||||
isDark: isDark,
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppConstants.primaryColor,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark
|
||||
? Colors.grey[800]!.withAlpha(80)
|
||||
: AppConstants.primaryColor.withAlpha(20),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'时间加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'诗词原文',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isDark
|
||||
? Colors.grey[300]
|
||||
: AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'原文加载中...',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||
widget.poetryData.drtime,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Text(
|
||||
widget.poetryData.drtime,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
height: 1.6,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIntroductionSection(BuildContext context) {
|
||||
Widget _buildIntroductionSection(BuildContext context, bool isDark) {
|
||||
final isLoading = widget.sectionLoadingStates?['introduction'] ?? false;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'译文',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppConstants.primaryColor,
|
||||
),
|
||||
return Builder(
|
||||
builder: (context) => GestureDetector(
|
||||
onLongPress: () => CopyUtils.showCopyDialog(
|
||||
context,
|
||||
widget.poetryData.introduce,
|
||||
'简介',
|
||||
isDark: isDark,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onLongPress: () => CopyUtils.showCopyDialog(
|
||||
context,
|
||||
widget.poetryData.introduce,
|
||||
'译文',
|
||||
),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
constraints: const BoxConstraints(maxHeight: 150),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.infoColor.withAlpha(13),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppConstants.infoColor.withAlpha(51)),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF252525) : Colors.grey[50],
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: isDark ? Colors.grey[700]! : Colors.grey[200]!,
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'简介加载中...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 16,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'译文加载中...',
|
||||
'简介',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isDark ? Colors.grey[300] : Colors.grey[700],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Text(
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
widget.poetryData.introduce,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.6,
|
||||
color: Colors.black87,
|
||||
height: 1.5,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮上一条按钮组件
|
||||
class FloatingPreviousButton extends StatelessWidget {
|
||||
final VoidCallback onPrevious;
|
||||
|
||||
const FloatingPreviousButton({super.key, required this.onPrevious});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: 'beta功能',
|
||||
child: Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.secondaryColor,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.secondaryColor.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
AudioManager().playClickSound();
|
||||
onPrevious();
|
||||
},
|
||||
child: const Center(
|
||||
child: Icon(Icons.arrow_back, color: Colors.white, size: 28),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮下一条按钮组件
|
||||
class FloatingNextButton extends StatelessWidget {
|
||||
final VoidCallback onNext;
|
||||
|
||||
const FloatingNextButton({super.key, required this.onNext});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.primaryColor,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.primaryColor.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
AudioManager().playNextSound();
|
||||
onNext();
|
||||
},
|
||||
child: const Center(
|
||||
child: Icon(Icons.arrow_forward, color: Colors.white, size: 28),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮点赞按钮组件
|
||||
class FloatingLikeButton extends StatelessWidget {
|
||||
final bool isLiked;
|
||||
final bool isLoadingLike;
|
||||
final VoidCallback onToggleLike;
|
||||
|
||||
const FloatingLikeButton({
|
||||
super.key,
|
||||
required this.isLiked,
|
||||
required this.isLoadingLike,
|
||||
required this.onToggleLike,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: isLiked ? AppConstants.errorColor : AppConstants.primaryColor,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color:
|
||||
(isLiked ? AppConstants.errorColor : AppConstants.primaryColor)
|
||||
.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: isLoadingLike
|
||||
? null
|
||||
: () {
|
||||
HapticFeedback.mediumImpact();
|
||||
AudioManager().playLikeSound();
|
||||
onToggleLike();
|
||||
},
|
||||
child: Center(
|
||||
child: isLoadingLike
|
||||
? const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white70),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
isLiked ? Icons.favorite : Icons.favorite_border,
|
||||
color: Colors.white,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 统计信息卡片组件
|
||||
class StatsCard extends StatelessWidget {
|
||||
final PoetryData poetryData;
|
||||
|
||||
const StatsCard({super.key, required this.poetryData});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(5),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'统计信息',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
_buildStatItem('今日', poetryData.hitsDay.toString()),
|
||||
const SizedBox(width: 20),
|
||||
_buildStatItem('本月', poetryData.hitsMonth.toString()),
|
||||
const SizedBox(width: 20),
|
||||
_buildStatItem('总计', poetryData.hitsTotal.toString()),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatItem(String label, String value) {
|
||||
return Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(label, style: const TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@
|
||||
/// 最新变化: 新建文件
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../utils/http/poetry_api.dart';
|
||||
import '../../../../utils/http/poetry_api.dart';
|
||||
import '../../../../constants/app_constants.dart';
|
||||
|
||||
class SecondaryButtonsManager {
|
||||
static const String _hideSecondaryButtonsKey = 'hide_secondary_buttons';
|
||||
@@ -51,6 +55,7 @@ class AutoRefreshManager {
|
||||
Timer? _refreshTimer;
|
||||
bool _isEnabled = false;
|
||||
VoidCallback? _onRefresh;
|
||||
final ValueNotifier<bool> _enabledNotifier = ValueNotifier<bool>(false);
|
||||
|
||||
AutoRefreshManager._internal();
|
||||
|
||||
@@ -62,12 +67,19 @@ class AutoRefreshManager {
|
||||
Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_isEnabled = prefs.getBool(_autoRefreshKey) ?? false;
|
||||
_enabledNotifier.value = _isEnabled;
|
||||
|
||||
if (_isEnabled) {
|
||||
_startTimer();
|
||||
}
|
||||
}
|
||||
|
||||
bool get isEnabled => _isEnabled;
|
||||
ValueNotifier<bool> get enabledNotifier => _enabledNotifier;
|
||||
|
||||
Future<void> setEnabled(bool enabled) async {
|
||||
_isEnabled = enabled;
|
||||
_enabledNotifier.value = enabled;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_autoRefreshKey, enabled);
|
||||
|
||||
@@ -113,8 +125,7 @@ class DebugInfoManager {
|
||||
|
||||
static DebugInfoManager? _instance;
|
||||
bool _isEnabled = false;
|
||||
final ValueNotifier<String> _messageNotifier = ValueNotifier<String>('');
|
||||
Timer? _messageTimer;
|
||||
final ValueNotifier<bool> _enabledNotifier = ValueNotifier<bool>(false);
|
||||
|
||||
DebugInfoManager._internal();
|
||||
|
||||
@@ -126,30 +137,42 @@ class DebugInfoManager {
|
||||
Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_isEnabled = prefs.getBool(_debugInfoKey) ?? false;
|
||||
_enabledNotifier.value = _isEnabled;
|
||||
}
|
||||
|
||||
bool get isEnabled => _isEnabled;
|
||||
ValueNotifier<String> get messageNotifier => _messageNotifier;
|
||||
ValueNotifier<bool> get enabledNotifier => _enabledNotifier;
|
||||
|
||||
Future<void> setEnabled(bool enabled) async {
|
||||
_isEnabled = enabled;
|
||||
_enabledNotifier.value = enabled;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_debugInfoKey, enabled);
|
||||
|
||||
if (!enabled) {
|
||||
_messageNotifier.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
void showMessage(String message) {
|
||||
if (!_isEnabled) return;
|
||||
|
||||
_messageNotifier.value = message;
|
||||
|
||||
_messageTimer?.cancel();
|
||||
_messageTimer = Timer(const Duration(seconds: 2), () {
|
||||
_messageNotifier.value = '';
|
||||
});
|
||||
Get.snackbar(
|
||||
'调试信息',
|
||||
message,
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.transparent,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 2),
|
||||
margin: const EdgeInsets.all(16),
|
||||
borderRadius: 20,
|
||||
animationDuration: const Duration(milliseconds: 300),
|
||||
snackbarStatus: (status) {},
|
||||
maxWidth: Get.width - 32,
|
||||
overlayBlur: 0.1,
|
||||
overlayColor: Colors.transparent,
|
||||
isDismissible: true,
|
||||
padding: EdgeInsets.zero,
|
||||
shouldIconPulse: false,
|
||||
barBlur: 20,
|
||||
// backgroundColor: Colors.black.withValues(alpha: 0.15),
|
||||
);
|
||||
}
|
||||
|
||||
void showRefreshSuccess() {
|
||||
@@ -192,10 +215,7 @@ class DebugInfoManager {
|
||||
showMessage('复制失败');
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_messageTimer?.cancel();
|
||||
_messageNotifier.value = '';
|
||||
}
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
class OfflineDataManager {
|
||||
@@ -337,3 +357,38 @@ class OfflineDataManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalTipsManager {
|
||||
static const String _globalTipsKey = 'global_tips_enabled';
|
||||
|
||||
static GlobalTipsManager? _instance;
|
||||
bool _isEnabled = true;
|
||||
final ValueNotifier<bool> _enabledNotifier = ValueNotifier<bool>(true);
|
||||
|
||||
GlobalTipsManager._internal();
|
||||
|
||||
factory GlobalTipsManager() {
|
||||
_instance ??= GlobalTipsManager._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_isEnabled = prefs.getBool(_globalTipsKey) ?? true;
|
||||
_enabledNotifier.value = _isEnabled;
|
||||
}
|
||||
|
||||
bool get isEnabled => _isEnabled;
|
||||
ValueNotifier<bool> get enabledNotifier => _enabledNotifier;
|
||||
|
||||
Future<void> setEnabled(bool enabled) async {
|
||||
_isEnabled = enabled;
|
||||
_enabledNotifier.value = enabled;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_globalTipsKey, enabled);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_enabledNotifier.value = true;
|
||||
}
|
||||
}
|
||||
190
lib/views/home/set/home-set.dart
Normal file
190
lib/views/home/set/home-set.dart
Normal file
@@ -0,0 +1,190 @@
|
||||
/// 时间: 2026-04-02
|
||||
/// 功能: 主页设置和控制组件
|
||||
/// 介绍: 包含收起/恢复悬浮按钮的管理器和组件
|
||||
/// 最新变化: 2026-04-02 初始创建
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../../constants/app_constants.dart';
|
||||
|
||||
/// 悬浮按钮收起管理器
|
||||
class FloatingButtonsVisibilityManager {
|
||||
static const String _key = 'floating_buttons_visible';
|
||||
|
||||
static FloatingButtonsVisibilityManager? _instance;
|
||||
bool _isVisible = true;
|
||||
bool _isFlashing = false;
|
||||
int _flashCount = 0;
|
||||
final ValueNotifier<bool> _visibleNotifier = ValueNotifier<bool>(true);
|
||||
final ValueNotifier<bool> _flashingNotifier = ValueNotifier<bool>(false);
|
||||
Timer? _hideTimer;
|
||||
Timer? _flashTimer;
|
||||
|
||||
FloatingButtonsVisibilityManager._internal();
|
||||
|
||||
factory FloatingButtonsVisibilityManager() {
|
||||
_instance ??= FloatingButtonsVisibilityManager._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_isVisible = prefs.getBool(_key) ?? true;
|
||||
_visibleNotifier.value = _isVisible;
|
||||
}
|
||||
|
||||
bool get isVisible => _isVisible;
|
||||
bool get isFlashing => _isFlashing;
|
||||
ValueNotifier<bool> get visibleNotifier => _visibleNotifier;
|
||||
ValueNotifier<bool> get flashingNotifier => _flashingNotifier;
|
||||
|
||||
Future<void> toggle() async {
|
||||
if (_isFlashing) {
|
||||
await _restoreFromFlashing();
|
||||
return;
|
||||
}
|
||||
|
||||
_isVisible = !_isVisible;
|
||||
_visibleNotifier.value = _isVisible;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_key, _isVisible);
|
||||
|
||||
if (!_isVisible) {
|
||||
_startHideTimer();
|
||||
} else {
|
||||
_cancelAllTimers();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreFromFlashing() async {
|
||||
_cancelAllTimers();
|
||||
_isFlashing = false;
|
||||
_flashingNotifier.value = false;
|
||||
_isVisible = true;
|
||||
_visibleNotifier.value = true;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_key, true);
|
||||
}
|
||||
|
||||
void _startHideTimer() {
|
||||
_cancelAllTimers();
|
||||
_hideTimer = Timer(const Duration(seconds: 5), () {
|
||||
_startFlashing();
|
||||
});
|
||||
}
|
||||
|
||||
void _startFlashing() {
|
||||
_isFlashing = true;
|
||||
_flashingNotifier.value = true;
|
||||
_flashCount = 0;
|
||||
_flashTimer = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
_flashCount++;
|
||||
_flashingNotifier.value = !_flashingNotifier.value;
|
||||
|
||||
if (_flashCount >= 6) {
|
||||
timer.cancel();
|
||||
_isFlashing = false;
|
||||
_flashingNotifier.value = false;
|
||||
_isVisible = false;
|
||||
_visibleNotifier.value = false;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_key, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _cancelAllTimers() {
|
||||
if (_hideTimer != null) {
|
||||
_hideTimer!.cancel();
|
||||
_hideTimer = null;
|
||||
}
|
||||
if (_flashTimer != null) {
|
||||
_flashTimer!.cancel();
|
||||
_flashTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_cancelAllTimers();
|
||||
_visibleNotifier.value = true;
|
||||
_flashingNotifier.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 收起/恢复悬浮按钮组件
|
||||
class FloatingButtonsToggleButton extends StatelessWidget {
|
||||
final FloatingButtonsVisibilityManager manager;
|
||||
final bool isDark;
|
||||
|
||||
const FloatingButtonsToggleButton({
|
||||
super.key,
|
||||
required this.manager,
|
||||
required this.isDark,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: manager.flashingNotifier,
|
||||
builder: (context, isFlashing, child) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: manager.visibleNotifier,
|
||||
builder: (context, isVisible, child) {
|
||||
final shouldShow = isFlashing ? !isFlashing : isVisible;
|
||||
|
||||
return SizedBox(
|
||||
width: 44,
|
||||
height: 44,
|
||||
child: shouldShow || isFlashing
|
||||
? Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 20),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
onTap: () {
|
||||
manager.toggle();
|
||||
},
|
||||
child: Center(
|
||||
child: Icon(
|
||||
isFlashing
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: isFlashing
|
||||
? AppConstants.primaryColor
|
||||
: (isDark
|
||||
? Colors.grey[300]
|
||||
: AppConstants.primaryColor),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
onTap: () {
|
||||
manager.toggle();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,29 @@
|
||||
/// 时间: 2025-03-22
|
||||
/// 功能: 诗词页面通用组件和工具函数
|
||||
/// 介绍: 从 home_page.dart 和 home_part.dart 中提取的公共组件,用于代码复用和简化
|
||||
/// 最新变化: 2026-04-02 支持深色模式
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import '../../constants/app_constants.dart';
|
||||
import '../../utils/http/poetry_api.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import '../../../utils/http/poetry_api.dart';
|
||||
import 'home-load.dart';
|
||||
|
||||
/// 加载状态组件
|
||||
class LoadingWidget extends StatelessWidget {
|
||||
const LoadingWidget({super.key});
|
||||
final bool isDark;
|
||||
|
||||
const LoadingWidget({super.key, this.isDark = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@@ -28,10 +32,13 @@ class LoadingWidget extends StatelessWidget {
|
||||
AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'加载中...',
|
||||
style: TextStyle(fontSize: 16, color: const Color(0xFF757575)),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: isDark ? Colors.grey[400] : const Color(0xFF757575),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -41,78 +48,62 @@ class LoadingWidget extends StatelessWidget {
|
||||
|
||||
/// 截图和分享工具类
|
||||
class ShareImageUtils {
|
||||
/// 将 Widget 截图并分享
|
||||
static Future<void> captureAndShare(
|
||||
BuildContext context,
|
||||
GlobalKey repaintKey, {
|
||||
String? subject,
|
||||
}) async {
|
||||
try {
|
||||
PoetryStateManager.showSnackBar(
|
||||
context,
|
||||
'正在生成图片...',
|
||||
backgroundColor: AppConstants.primaryColor,
|
||||
);
|
||||
Get.snackbar('提示', '正在生成图片...');
|
||||
|
||||
final boundary =
|
||||
repaintKey.currentContext?.findRenderObject()
|
||||
as RenderRepaintBoundary?;
|
||||
if (boundary == null) {
|
||||
if (context.mounted) {
|
||||
PoetryStateManager.showSnackBar(
|
||||
context,
|
||||
'生成图片失败',
|
||||
backgroundColor: AppConstants.errorColor,
|
||||
);
|
||||
}
|
||||
Get.snackbar('错误', '生成图片失败');
|
||||
return;
|
||||
}
|
||||
|
||||
ui.Image image = await boundary.toImage(pixelRatio: 3.0);
|
||||
ByteData? byteData = await image.toByteData(
|
||||
format: ui.ImageByteFormat.png,
|
||||
);
|
||||
|
||||
final image = await boundary.toImage(pixelRatio: 3.0);
|
||||
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
if (byteData == null) {
|
||||
if (context.mounted) {
|
||||
PoetryStateManager.showSnackBar(
|
||||
context,
|
||||
'生成图片失败',
|
||||
backgroundColor: AppConstants.errorColor,
|
||||
);
|
||||
}
|
||||
Get.snackbar('错误', '生成图片失败');
|
||||
return;
|
||||
}
|
||||
|
||||
Uint8List pngBytes = byteData.buffer.asUint8List();
|
||||
|
||||
final pngBytes = byteData.buffer.asUint8List();
|
||||
final directory = await getTemporaryDirectory();
|
||||
final file = File(
|
||||
'${directory.path}/poetry_${DateTime.now().millisecondsSinceEpoch}.png',
|
||||
);
|
||||
await file.writeAsBytes(pngBytes);
|
||||
|
||||
final result = await Share.shareXFiles([
|
||||
XFile(file.path),
|
||||
], subject: subject ?? '诗词分享');
|
||||
await Share.shareXFiles([XFile(file.path)], subject: subject ?? '诗词分享');
|
||||
|
||||
if (result.status == ShareResultStatus.success) {
|
||||
if (context.mounted) {
|
||||
PoetryStateManager.showSnackBar(
|
||||
context,
|
||||
'分享成功!',
|
||||
backgroundColor: AppConstants.successColor,
|
||||
);
|
||||
}
|
||||
}
|
||||
Get.snackbar(
|
||||
'成功',
|
||||
'分享成功!',
|
||||
|
||||
// snackPosition: SnackPosition.TOP,
|
||||
// backgroundColor: Colors.transparent,
|
||||
// colorText: Colors.white,
|
||||
// duration: const Duration(seconds: 2),
|
||||
// margin: const EdgeInsets.all(16),
|
||||
// borderRadius: 20,
|
||||
// animationDuration: const Duration(milliseconds: 300),
|
||||
// maxWidth: Get.width - 32,
|
||||
// overlayBlur: 0.1,
|
||||
// overlayColor: Colors.transparent,
|
||||
// isDismissible: true,
|
||||
// padding: EdgeInsets.zero,
|
||||
// shouldIconPulse: false,
|
||||
// barBlur: 20,
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
PoetryStateManager.showSnackBar(
|
||||
context,
|
||||
'分享失败:${e.toString().substring(0, e.toString().length > 50 ? 50 : e.toString().length)}',
|
||||
backgroundColor: AppConstants.errorColor,
|
||||
);
|
||||
}
|
||||
Get.snackbar(
|
||||
'错误',
|
||||
'分享失败:${e.toString().substring(0, e.toString().length > 50 ? 50 : e.toString().length)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,11 +112,13 @@ class ShareImageUtils {
|
||||
class CustomErrorWidget extends StatelessWidget {
|
||||
final String errorMessage;
|
||||
final VoidCallback onRetry;
|
||||
final bool isDark;
|
||||
|
||||
const CustomErrorWidget({
|
||||
super.key,
|
||||
required this.errorMessage,
|
||||
required this.onRetry,
|
||||
this.isDark = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -134,11 +127,18 @@ class CustomErrorWidget extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 64, color: Colors.grey[400]),
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: isDark ? Colors.grey[600] : Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
errorMessage,
|
||||
style: const TextStyle(fontSize: 16, color: Colors.grey),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -157,12 +157,20 @@ class CustomErrorWidget extends StatelessWidget {
|
||||
|
||||
/// 空状态组件
|
||||
class EmptyWidget extends StatelessWidget {
|
||||
const EmptyWidget({super.key});
|
||||
final bool isDark;
|
||||
|
||||
const EmptyWidget({super.key, this.isDark = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(
|
||||
child: Text('暂无诗词内容', style: TextStyle(fontSize: 16, color: Colors.grey)),
|
||||
return Center(
|
||||
child: Text(
|
||||
'暂无诗词内容',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -283,18 +291,15 @@ class CopyUtils {
|
||||
String content,
|
||||
String contentType, {
|
||||
VoidCallback? onSuccess,
|
||||
bool isDark = false,
|
||||
}) {
|
||||
try {
|
||||
Clipboard.setData(ClipboardData(text: content));
|
||||
PoetryStateManager.showSnackBar(context, '已复制$contentType');
|
||||
Get.snackbar('提示', '已复制$contentType');
|
||||
DebugInfoManager().showCopySuccess();
|
||||
onSuccess?.call();
|
||||
} catch (e) {
|
||||
PoetryStateManager.showSnackBar(
|
||||
context,
|
||||
'复制失败',
|
||||
backgroundColor: AppConstants.errorColor,
|
||||
);
|
||||
Get.snackbar('错误', '复制失败');
|
||||
DebugInfoManager().showCopyFailed();
|
||||
}
|
||||
}
|
||||
@@ -302,39 +307,56 @@ class CopyUtils {
|
||||
static void showCopyDialog(
|
||||
BuildContext context,
|
||||
String content,
|
||||
String contentType,
|
||||
) {
|
||||
String contentType, {
|
||||
bool isDark = false,
|
||||
}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('复制$contentType'),
|
||||
backgroundColor: isDark ? const Color(0xFF1E1E1E) : Colors.white,
|
||||
title: Text(
|
||||
'复制$contentType',
|
||||
style: TextStyle(color: isDark ? Colors.white : Colors.black87),
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'受隐私权限约束,频繁写入剪切板需告知用户',
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isDark ? Colors.grey[300] : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'预览内容:',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: Colors.grey[300]!),
|
||||
border: Border.all(
|
||||
color: isDark ? Colors.grey[700]! : Colors.grey[300]!,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
content.length > 50
|
||||
? '${content.substring(0, 50)}...'
|
||||
: content,
|
||||
style: const TextStyle(fontSize: 12, color: Colors.black87),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[300] : Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -342,12 +364,17 @@ class CopyUtils {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('返回'),
|
||||
child: Text(
|
||||
'返回',
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
copyToClipboard(context, content, contentType);
|
||||
copyToClipboard(context, content, contentType, isDark: isDark);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppConstants.primaryColor,
|
||||
@@ -364,8 +391,13 @@ class CopyUtils {
|
||||
/// 悬浮分享按钮组件
|
||||
class FloatingShareButton extends StatelessWidget {
|
||||
final VoidCallback onShare;
|
||||
final bool isDark;
|
||||
|
||||
const FloatingShareButton({super.key, required this.onShare});
|
||||
const FloatingShareButton({
|
||||
super.key,
|
||||
required this.onShare,
|
||||
this.isDark = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -400,11 +432,179 @@ class FloatingShareButton extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮上一条按钮
|
||||
class FloatingPreviousButton extends StatelessWidget {
|
||||
final VoidCallback onPrevious;
|
||||
final bool isDark;
|
||||
|
||||
const FloatingPreviousButton({
|
||||
super.key,
|
||||
required this.onPrevious,
|
||||
this.isDark = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 20),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onPrevious();
|
||||
},
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.arrow_back,
|
||||
color: isDark ? Colors.grey[300] : AppConstants.primaryColor,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮下一条按钮
|
||||
class FloatingNextButton extends StatelessWidget {
|
||||
final VoidCallback onNext;
|
||||
final bool isDark;
|
||||
|
||||
const FloatingNextButton({
|
||||
super.key,
|
||||
required this.onNext,
|
||||
this.isDark = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 20),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onNext();
|
||||
},
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.arrow_forward,
|
||||
color: isDark ? Colors.grey[300] : AppConstants.primaryColor,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮点赞按钮
|
||||
class FloatingLikeButton extends StatelessWidget {
|
||||
final bool isLiked;
|
||||
final bool isLoadingLike;
|
||||
final VoidCallback onToggleLike;
|
||||
final bool isDark;
|
||||
|
||||
const FloatingLikeButton({
|
||||
super.key,
|
||||
required this.isLiked,
|
||||
required this.isLoadingLike,
|
||||
required this.onToggleLike,
|
||||
this.isDark = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: isLiked
|
||||
? Colors.red
|
||||
: (isDark ? const Color(0xFF2A2A2A) : Colors.white),
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: (isLiked ? Colors.red : Colors.black).withAlpha(
|
||||
isDark ? 40 : 20,
|
||||
),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: isLoadingLike
|
||||
? null
|
||||
: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onToggleLike();
|
||||
},
|
||||
child: Center(
|
||||
child: isLoadingLike
|
||||
? SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
isDark ? Colors.grey[300]! : AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
isLiked ? Icons.favorite : Icons.favorite_border,
|
||||
color: isLiked
|
||||
? Colors.white
|
||||
: (isDark ? Colors.grey[300] : Colors.grey),
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 统计信息卡片组件
|
||||
class StatsCard extends StatelessWidget {
|
||||
final PoetryData poetryData;
|
||||
final bool isDark;
|
||||
|
||||
const StatsCard({super.key, required this.poetryData});
|
||||
const StatsCard({super.key, required this.poetryData, this.isDark = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -412,11 +612,11 @@ class StatsCard extends StatelessWidget {
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
color: isDark ? const Color(0xFF1E1E1E) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(5),
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 5),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
@@ -456,14 +656,20 @@ class StatsCard extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
color: isDark ? Colors.grey[200] : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(label, style: const TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user