chore: 汇总批量提交的功能优化与bug修复
本次提交包含多项迭代优化和问题修复: 1. 新增缩略图图片组件、数字格式化工具类,补充多语言翻译类型与本地化支持 2. 优化底部导航栏主题色统一使用动态accent色值 3. 修复多处图表动画、路由跳转、API请求相关问题 4. 简化服务器公告文案,调整默认分屏状态为关闭 5. 新增安卓/iOS桌面快捷方式配置 6. 重构多处状态管理类使用SafeNotifierInit统一异常保护 7. 替换硬编码蓝色为主题色,更新版本号获取方式为动态读取 8. 优化缓存预加载逻辑,移除无用代码 9. 调整默认设置项,优化用户体验细节
This commit is contained in:
85
lib/core/utils/ui/rtl_utils.dart
Normal file
85
lib/core/utils/ui/rtl_utils.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — RTL布局工具
|
||||
/// 创建时间: 2026-05-31
|
||||
/// 更新时间: 2026-05-31
|
||||
/// 作用: 提供RTL感知的EdgeInsets/Alignment工具方法,方便逐步迁移
|
||||
/// 上次更新: 初始创建,提供方向感知的padding/margin工具
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// RTL布局工具类
|
||||
/// 提供方向感知的EdgeInsets和Alignment工具方法
|
||||
///
|
||||
/// 使用方式:
|
||||
/// ```dart
|
||||
/// // 替代 EdgeInsets.only(left: 16)
|
||||
/// padding: RtlPadding.only(start: 16, context),
|
||||
///
|
||||
/// // 替代 EdgeInsets.only(left: 16, right: 8)
|
||||
/// padding: RtlPadding.only(start: 16, end: 8, context),
|
||||
/// ```
|
||||
class RtlPadding {
|
||||
/// 方向感知的EdgeInsets.only
|
||||
/// [start] 在LTR中为left,RTL中为right
|
||||
/// [end] 在LTR中为right,RTL中为left
|
||||
static EdgeInsets only({
|
||||
double start = 0,
|
||||
double end = 0,
|
||||
double top = 0,
|
||||
double bottom = 0,
|
||||
required BuildContext context,
|
||||
}) {
|
||||
final isRtl = Directionality.of(context) == TextDirection.rtl;
|
||||
return EdgeInsets.only(
|
||||
left: isRtl ? end : start,
|
||||
right: isRtl ? start : end,
|
||||
top: top,
|
||||
bottom: bottom,
|
||||
);
|
||||
}
|
||||
|
||||
/// 方向感知的EdgeInsets.symmetric
|
||||
/// [horizontalStart] 对应start方向,[horizontalEnd] 对应end方向
|
||||
static EdgeInsets symmetric({
|
||||
double horizontalStart = 0,
|
||||
double horizontalEnd = 0,
|
||||
double vertical = 0,
|
||||
required BuildContext context,
|
||||
}) {
|
||||
final isRtl = Directionality.of(context) == TextDirection.rtl;
|
||||
return EdgeInsets.only(
|
||||
left: isRtl ? horizontalEnd : horizontalStart,
|
||||
right: isRtl ? horizontalStart : horizontalEnd,
|
||||
top: vertical,
|
||||
bottom: vertical,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// RTL感知的Alignment工具
|
||||
class RtlAlignment {
|
||||
/// start对齐:LTR中为left,RTL中为right
|
||||
static AlignmentDirectional get start => AlignmentDirectional.centerStart;
|
||||
|
||||
/// end对齐:LTR中为right,RTL中为left
|
||||
static AlignmentDirectional get end => AlignmentDirectional.centerEnd;
|
||||
|
||||
/// topStart对齐
|
||||
static AlignmentDirectional get topStart => AlignmentDirectional.topStart;
|
||||
|
||||
/// topEnd对齐
|
||||
static AlignmentDirectional get topEnd => AlignmentDirectional.topEnd;
|
||||
|
||||
/// bottomStart对齐
|
||||
static AlignmentDirectional get bottomStart =>
|
||||
AlignmentDirectional.bottomStart;
|
||||
|
||||
/// bottomEnd对齐
|
||||
static AlignmentDirectional get bottomEnd => AlignmentDirectional.bottomEnd;
|
||||
}
|
||||
|
||||
/// 判断当前上下文是否为RTL
|
||||
bool isContextRtl(BuildContext context) {
|
||||
return Directionality.of(context) == TextDirection.rtl;
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — Sheet动画同步通知器
|
||||
/// 创建时间: 2026-04-30
|
||||
/// 更新时间: 2026-05-25
|
||||
/// 更新时间: 2026-05-30
|
||||
/// 作用: 全局Sheet动画进度同步,让底层页面响应Sheet弹出/拖拽
|
||||
/// 上次更新: 添加帧率节流30fps+值缓存避免重复notify+ValueNotifier替代ChangeNotifier
|
||||
/// 上次更新: 从全局单例改为Riverpod Provider,随页面生命周期自动管理
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:xianyan/core/utils/performance_optimizer.dart';
|
||||
|
||||
/// Sheet动画进度通知器
|
||||
/// 管理多个Sheet层的动画进度,聚合后通知UI更新
|
||||
/// 配合 AnimatedBuilder 使用,实现Sheet弹出时底层页面的缩放/圆角动画
|
||||
final class SheetAnimationNotifier extends ChangeNotifier {
|
||||
SheetAnimationNotifier._();
|
||||
static final SheetAnimationNotifier instance = SheetAnimationNotifier._();
|
||||
|
||||
final Map<Object, double> _layers = {};
|
||||
|
||||
double _cachedProgress = 0.0;
|
||||
@@ -21,8 +22,10 @@ final class SheetAnimationNotifier extends ChangeNotifier {
|
||||
FrameRateThrottler get _throttle =>
|
||||
_throttler ??= FrameRateThrottler(AnimationFpsCategory.decorative);
|
||||
|
||||
/// 当前聚合动画进度 (0.0 ~ 2.0)
|
||||
double get progress => _cachedProgress;
|
||||
|
||||
/// 计算所有层的聚合进度
|
||||
double _computeProgress() {
|
||||
if (_layers.isEmpty) return 0.0;
|
||||
var total = 0.0;
|
||||
@@ -32,6 +35,7 @@ final class SheetAnimationNotifier extends ChangeNotifier {
|
||||
return total.clamp(0.0, 2.0);
|
||||
}
|
||||
|
||||
/// 更新指定层的进度值
|
||||
void updateLayer(Object key, double value) {
|
||||
final clamped = value.clamp(0.0, 1.0);
|
||||
if (_layers.containsKey(key) && (_layers[key]! - clamped).abs() < 0.001) {
|
||||
@@ -46,16 +50,33 @@ final class SheetAnimationNotifier extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 移除指定层
|
||||
void removeLayer(Object key) {
|
||||
if (_layers.remove(key) != null) {
|
||||
_cachedProgress = _computeProgress();
|
||||
notifyListeners();
|
||||
if (hasListeners) notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 重置所有层
|
||||
void reset() {
|
||||
_layers.clear();
|
||||
_cachedProgress = 0.0;
|
||||
notifyListeners();
|
||||
if (hasListeners) notifyListeners();
|
||||
}
|
||||
|
||||
/// 通过 ProviderScope 获取实例的兼容方法
|
||||
/// 用于非 ConsumerWidget/ConsumerStatefulWidget 场景
|
||||
static SheetAnimationNotifier of(BuildContext context) {
|
||||
return ProviderScope.containerOf(context).read(sheetAnimationProvider);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sheet动画进度 Riverpod provider
|
||||
/// 使用 Provider + ref.onDispose 管理生命周期
|
||||
/// 页面销毁时自动 dispose 通知器,释放监听资源
|
||||
final sheetAnimationProvider = Provider<SheetAnimationNotifier>((ref) {
|
||||
final notifier = SheetAnimationNotifier();
|
||||
ref.onDispose(notifier.dispose);
|
||||
return notifier;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user