声音功能
This commit is contained in:
@@ -5,8 +5,11 @@
|
||||
|
||||
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/flutter_compatibility_fix.dart';
|
||||
import '../../../utils/audio_manager.dart';
|
||||
import 'home_components.dart';
|
||||
|
||||
/// 诗词卡片组件 - 优化版本,防止拉伸和处理文本溢出
|
||||
@@ -31,6 +34,13 @@ class PoetryCard extends StatefulWidget {
|
||||
class _PoetryCardState extends State<PoetryCard> {
|
||||
bool _showCopyTip = true;
|
||||
bool _showRecommendation = false;
|
||||
bool _globalTipsEnabled = true; // 添加全局Tips开关状态
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadGlobalTipsSettings(); // 加载全局Tips设置
|
||||
}
|
||||
|
||||
String _getTimeOfDayGreeting() {
|
||||
final hour = DateTime.now().hour;
|
||||
@@ -74,10 +84,34 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载全局Tips设置
|
||||
Future<void> _loadGlobalTipsSettings() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_globalTipsEnabled = prefs.getBool('global_tips_enabled') ?? true;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果加载失败,默认开启
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_globalTipsEnabled = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
onTap: () async {
|
||||
// 播放点击音效
|
||||
await AudioManager().playClickSound();
|
||||
// 调用原始的onTap回调
|
||||
widget.onTap?.call();
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
@@ -87,7 +121,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
color: Colors.black.withAlpha(10),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@@ -143,7 +177,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppConstants.primaryColor.withValues(alpha: 0.8),
|
||||
AppConstants.primaryColor.withAlpha(204),
|
||||
AppConstants.primaryColor,
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
@@ -197,7 +231,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.primaryColor.withValues(alpha: 0.3),
|
||||
color: AppConstants.primaryColor.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@@ -208,8 +242,8 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: Colors.white, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
'点击任意区域加载下一条,长按复制,下拉刷新',
|
||||
Text(
|
||||
_globalTipsEnabled ? '点击任意区域加载下一条,长按复制,下拉刷新' : '',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
@@ -293,20 +327,20 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppConstants.primaryColor.withValues(alpha: 0.1),
|
||||
AppConstants.primaryColor.withValues(alpha: 0.05),
|
||||
AppConstants.primaryColor.withAlpha(26),
|
||||
AppConstants.primaryColor.withAlpha(13),
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppConstants.primaryColor.withValues(alpha: 0.2),
|
||||
color: AppConstants.primaryColor.withAlpha(51),
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.primaryColor.withValues(alpha: 0.1),
|
||||
color: AppConstants.primaryColor.withAlpha(26),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@@ -437,7 +471,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.secondaryColor
|
||||
.withValues(alpha: 0.1),
|
||||
.withAlpha(26),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
@@ -468,8 +502,8 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.primaryColor.withValues(
|
||||
alpha: 0.1,
|
||||
color: AppConstants.primaryColor.withAlpha(
|
||||
26,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -604,11 +638,9 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
constraints: const BoxConstraints(maxHeight: 150),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.infoColor.withValues(alpha: 0.05),
|
||||
color: AppConstants.infoColor.withAlpha(13),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppConstants.infoColor.withValues(alpha: 0.2),
|
||||
),
|
||||
border: Border.all(color: AppConstants.infoColor.withAlpha(51)),
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
@@ -671,7 +703,7 @@ class FloatingPreviousButton extends StatelessWidget {
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.secondaryColor.withValues(alpha: 0.3),
|
||||
color: AppConstants.secondaryColor.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
@@ -711,7 +743,7 @@ class FloatingNextButton extends StatelessWidget {
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppConstants.primaryColor.withValues(alpha: 0.3),
|
||||
color: AppConstants.primaryColor.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
@@ -759,7 +791,7 @@ class FloatingLikeButton extends StatelessWidget {
|
||||
BoxShadow(
|
||||
color:
|
||||
(isLiked ? AppConstants.errorColor : AppConstants.primaryColor)
|
||||
.withValues(alpha: 0.3),
|
||||
.withAlpha(76),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
@@ -813,7 +845,7 @@ class StatsCard extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
color: Colors.black.withAlpha(5),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user