完善细类
This commit is contained in:
@@ -8,6 +8,41 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../utils/http/poetry_api.dart';
|
||||
|
||||
class SecondaryButtonsManager {
|
||||
static const String _hideSecondaryButtonsKey = 'hide_secondary_buttons';
|
||||
|
||||
static SecondaryButtonsManager? _instance;
|
||||
bool _isHidden = false;
|
||||
final ValueNotifier<bool> _hiddenNotifier = ValueNotifier<bool>(false);
|
||||
|
||||
SecondaryButtonsManager._internal();
|
||||
|
||||
factory SecondaryButtonsManager() {
|
||||
_instance ??= SecondaryButtonsManager._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_isHidden = prefs.getBool(_hideSecondaryButtonsKey) ?? false;
|
||||
_hiddenNotifier.value = _isHidden;
|
||||
}
|
||||
|
||||
bool get isHidden => _isHidden;
|
||||
ValueNotifier<bool> get hiddenNotifier => _hiddenNotifier;
|
||||
|
||||
Future<void> setHidden(bool hidden) async {
|
||||
_isHidden = hidden;
|
||||
_hiddenNotifier.value = hidden;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_hideSecondaryButtonsKey, hidden);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_hiddenNotifier.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
class AutoRefreshManager {
|
||||
static const String _autoRefreshKey = 'auto_refresh_enabled';
|
||||
static const Duration _refreshInterval = Duration(seconds: 5);
|
||||
|
||||
@@ -60,12 +60,17 @@ class _HomePageState extends State<HomePage>
|
||||
_initDebugInfo();
|
||||
_initOfflineDataManager();
|
||||
_initAudioManager();
|
||||
_initSecondaryButtonsManager();
|
||||
// 延迟加载诗词,确保页面先显示
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadPoetry();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _initSecondaryButtonsManager() async {
|
||||
await SecondaryButtonsManager().init();
|
||||
}
|
||||
|
||||
Future<void> _initAudioManager() async {
|
||||
await AudioManager().init();
|
||||
}
|
||||
@@ -772,63 +777,71 @@ class _HomePageState extends State<HomePage>
|
||||
onRefresh: _refreshPoetry,
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: Stack(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(), // 确保可以下拉刷新
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
PoetryCard(
|
||||
poetryData: _poetryData!,
|
||||
keywordList: _keywordList,
|
||||
onTap: _loadNextPoetry,
|
||||
sectionLoadingStates: _sectionLoadingStates,
|
||||
repaintKey: _repaintKey,
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: SecondaryButtonsManager().hiddenNotifier,
|
||||
builder: (context, hideSecondaryButtons, child) {
|
||||
return Stack(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
physics:
|
||||
const AlwaysScrollableScrollPhysics(), // 确保可以下拉刷新
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
PoetryCard(
|
||||
poetryData: _poetryData!,
|
||||
keywordList: _keywordList,
|
||||
onTap: _loadNextPoetry,
|
||||
sectionLoadingStates: _sectionLoadingStates,
|
||||
repaintKey: _repaintKey,
|
||||
),
|
||||
const SizedBox(height: 160), // 为悬浮按钮留出更多空间
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 160), // 为悬浮按钮留出更多空间
|
||||
],
|
||||
),
|
||||
),
|
||||
// 调试信息气泡
|
||||
Positioned(
|
||||
bottom: 66,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(child: _buildDebugInfoBubble()),
|
||||
),
|
||||
// 悬浮上一条按钮 - 左边上方
|
||||
Positioned(
|
||||
left: 16,
|
||||
bottom: 100,
|
||||
child: FloatingPreviousButton(
|
||||
onPrevious: _loadPreviousPoetry,
|
||||
),
|
||||
),
|
||||
// 悬浮下一条按钮 - 左边下方
|
||||
Positioned(
|
||||
left: 16,
|
||||
bottom: 32,
|
||||
child: FloatingNextButton(onNext: _loadNextPoetry),
|
||||
),
|
||||
// 悬浮分享按钮 - 右边上方
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 100,
|
||||
child: FloatingShareButton(onShare: _sharePoetryImage),
|
||||
),
|
||||
// 悬浮点赞按钮 - 右边(仅在线状态显示)
|
||||
if (isOnline)
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 32,
|
||||
child: FloatingLikeButton(
|
||||
isLiked: _isLiked,
|
||||
isLoadingLike: _isLoadingLike,
|
||||
onToggleLike: _toggleLike,
|
||||
),
|
||||
),
|
||||
],
|
||||
// 调试信息气泡
|
||||
Positioned(
|
||||
bottom: 66,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(child: _buildDebugInfoBubble()),
|
||||
),
|
||||
// 悬浮上一条按钮 - 左边上方(根据设置显示/隐藏)
|
||||
if (!hideSecondaryButtons)
|
||||
Positioned(
|
||||
left: 16,
|
||||
bottom: 100,
|
||||
child: FloatingPreviousButton(
|
||||
onPrevious: _loadPreviousPoetry,
|
||||
),
|
||||
),
|
||||
// 悬浮下一条按钮 - 左边下方
|
||||
Positioned(
|
||||
left: 16,
|
||||
bottom: 32,
|
||||
child: FloatingNextButton(onNext: _loadNextPoetry),
|
||||
),
|
||||
// 悬浮分享按钮 - 右边上方(根据设置显示/隐藏)
|
||||
if (!hideSecondaryButtons)
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 100,
|
||||
child: FloatingShareButton(onShare: _sharePoetryImage),
|
||||
),
|
||||
// 悬浮点赞按钮 - 右边(仅在线状态显示)
|
||||
if (isOnline)
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 32,
|
||||
child: FloatingLikeButton(
|
||||
isLiked: _isLiked,
|
||||
isLoadingLike: _isLoadingLike,
|
||||
onToggleLike: _toggleLike,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -158,7 +158,7 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_showCopyTip) _buildCopyTip(),
|
||||
_buildCopyTip(),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -225,6 +225,10 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
}
|
||||
|
||||
Widget _buildCopyTip() {
|
||||
if (!_globalTipsEnabled || !_showCopyTip) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Positioned(
|
||||
top: 56,
|
||||
right: 24,
|
||||
@@ -243,21 +247,21 @@ class _PoetryCardState extends State<PoetryCard> {
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: Colors.white, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Icon(Icons.info_outline, color: Colors.white, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
_globalTipsEnabled ? '点击任意区域加载下一条,长按复制,下拉刷新' : '',
|
||||
'点击任意区域加载下一条,长按复制,下拉刷新',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(Icons.close, color: Colors.white, size: 14),
|
||||
SizedBox(width: 4),
|
||||
Icon(Icons.close, color: Colors.white, size: 14),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user