深色模式、首页设置页面和功能优化

This commit is contained in:
Developer
2026-04-02 07:06:55 +08:00
parent f0a62ed68b
commit 954d173329
88 changed files with 12157 additions and 7578 deletions

View File

@@ -4,6 +4,7 @@ import '../config/app_config.dart';
import '../routes/app_routes.dart';
import 'screen_adapter.dart';
import 'force_guide_checker.dart';
import 'audio_manager.dart';
class AppInitializer {
static const bool _isDebugMode =
@@ -29,6 +30,9 @@ class AppInitializer {
_setupScreenAdapter();
// 初始化音频管理器
await AudioManager().init();
final initialRoute = await _getInitialRoute(prefs);
return InitializationResult(

View File

@@ -4,12 +4,13 @@ import 'package:shared_preferences/shared_preferences.dart';
/// 时间: 2026-03-30
/// 功能: 音频管理类
/// 介绍: 管理应用中的音效播放,包括点击音效、点赞音效等
/// 最新变化: 使用最简单的音频播放方式
/// 最新变化: 重写声音播放逻辑确保声音正常播放不依赖GlobalAudioScope
class AudioManager {
static AudioManager? _instance;
bool _isInitialized = false;
bool _isMuted = false;
AudioPlayer? _player;
AudioManager._internal();
@@ -23,9 +24,13 @@ class AudioManager {
try {
await _loadSoundSetting();
// 不依赖GlobalAudioScope的初始化直接创建AudioPlayer
_player = AudioPlayer();
_isInitialized = true;
print('AudioManager初始化成功');
} catch (e) {
// 初始化失败
print('AudioManager初始化失败: $e');
_isInitialized = true;
}
}
@@ -33,10 +38,12 @@ class AudioManager {
Future<void> _loadSoundSetting() async {
try {
final prefs = await SharedPreferences.getInstance();
bool soundEnabled = prefs.getBool('sound_enabled') ?? false;
bool soundEnabled = prefs.getBool('sound_enabled') ?? true;
_isMuted = !soundEnabled;
print('声音设置: soundEnabled=$soundEnabled, _isMuted=$_isMuted');
} catch (e) {
// 加载设置失败
print('加载声音设置失败: $e');
_isMuted = false;
}
}
@@ -57,27 +64,43 @@ class AudioManager {
/// 播放音频
void _playSound(String assetPath) {
if (_isMuted) return;
if (_isMuted) {
print('声音已静音,不播放: $assetPath');
return;
}
print('播放声音: $assetPath');
_playSoundAsync(assetPath);
}
/// 异步播放音频
void _playSoundAsync(String assetPath) async {
Future<void> _playSoundAsync(String assetPath) async {
try {
final player = AudioPlayer();
await player.play(AssetSource(assetPath));
// 确保player已初始化
if (_player == null) {
_player = AudioPlayer();
}
player.onPlayerComplete.listen((_) {
player.dispose();
});
// 播放音频
await _player!.play(AssetSource(assetPath));
print('声音播放成功: $assetPath');
} catch (e) {
// 播放失败
print('声音播放失败: $assetPath, 错误: $e');
// 如果播放失败尝试重新创建player
try {
_player?.dispose();
_player = AudioPlayer();
await _player!.play(AssetSource(assetPath));
print('声音重播成功: $assetPath');
} catch (retryError) {
print('声音重播失败: $assetPath, 错误: $retryError');
}
}
}
/// 设置静音状态
void setMuted(bool muted) {
_isMuted = muted;
print('设置静音状态: $_isMuted');
}
/// 获取静音状态