主要变更: 1. 新增桌面端托盘图标支持深色/浅色主题切换 2. 重构应用锁、动画配置、小组件导航服务职责 3. 修复Riverpod初始化断言、防重复点击、工作台模式残留选中态问题 4. 优化诗词服务、阅读进度、搜索结果空状态体验 5. 完善macOS打包配置与错误静默处理逻辑 6. 新增快速卡片多语言适配与动画退出队列管理
58 lines
1.9 KiB
Dart
58 lines
1.9 KiB
Dart
/// ============================================================
|
|
/// 闲言APP — 动画配置服务
|
|
/// 创建时间: 2026-06-22
|
|
/// 更新时间: 2026-06-22
|
|
/// 作用: 管理 flutter_animate 全局动画配置(时长、曲线),仅在设置变化时更新
|
|
/// 上次更新: 从 app.dart 中提取动画配置职责,实现单一职责分离
|
|
/// ============================================================
|
|
|
|
import 'package:flutter/animation.dart';
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
|
|
|
import '../../features/settings/providers/theme_settings_provider.dart';
|
|
|
|
/// 动画配置服务
|
|
///
|
|
/// 负责管理 flutter_animate 的全局默认配置:
|
|
/// - 动画时长:根据开关和强度级别计算
|
|
/// - 动画曲线:根据强度级别选择
|
|
///
|
|
/// 使用去重机制避免每次 build 重复设置全局配置。
|
|
class AnimationConfigService {
|
|
/// 上次设置的动画时长(去重用)
|
|
Duration? _lastDuration;
|
|
|
|
/// 上次设置的动画曲线(去重用)
|
|
Curve? _lastCurve;
|
|
|
|
/// 更新全局动画配置
|
|
///
|
|
/// 仅在配置变化时更新 [Animate] 的全局默认值,避免每次 build 重复设置。
|
|
/// [enabled] 动画是否启用
|
|
/// [intensity] 动画强度选项
|
|
void updateSettings({
|
|
required bool enabled,
|
|
required AnimationIntensityOption intensity,
|
|
}) {
|
|
final targetDuration = enabled
|
|
? Duration(
|
|
milliseconds: (300 * intensity.durationMultiplier).round(),
|
|
)
|
|
: Duration.zero;
|
|
final targetCurve = intensity.curve;
|
|
|
|
if (_lastDuration != targetDuration || _lastCurve != targetCurve) {
|
|
_lastDuration = targetDuration;
|
|
_lastCurve = targetCurve;
|
|
Animate.defaultDuration = targetDuration;
|
|
Animate.defaultCurve = targetCurve;
|
|
}
|
|
}
|
|
|
|
/// 重置状态(用于测试)
|
|
void reset() {
|
|
_lastDuration = null;
|
|
_lastCurve = null;
|
|
}
|
|
}
|