- 引入 DarkMode 工具类,提供系统栏、颜色、色调的暗色适配能力 - AppColors 调色板改为 CupertinoDynamicColor.withBrightness 自适应 - app.dart 增加 AnnotatedRegion 与 Material Theme 包裹以联动暗色系统栏 - 移除 system_ui_util 中硬编码的浅色图标配置,改由主题驱动 - CardBox、AppDivider、SectionTitle 等公共组件适配深色卡片与分割线 - settings_ui、change_mobile、change_password、login_devices、wechat_binding 等页面全面接入 DarkMode 颜色 - dio_client 新增 allowStale 响应缓存机制,网络异常时回退本地缓存 - token_storage 增加 currentAccountId(JWT 解析)及按用户隔离的设备偏好存取 - ApiException 改为通过私有构造持有真实 AppError 实例,appError getter 返回结构化错误 - 闹钟模块迁移至 FutureProvider.autoDispose.family,消除手动 loading 状态管理 - 闹钟编辑页 CupertinoTimerPicker 替换为 CupertinoDatePicker(24h 格式),标签输入改为 TextEditingController
91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
import 'package:cupertino_ui/cupertino_ui.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:ttstd_family_care/core/widgets/app_page_scaffold.dart';
|
|
|
|
import '../../../core/storage/token_storage.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
|
|
/// 启动页。
|
|
///
|
|
/// 仅负责首屏展示与路由决策(登录态判断),不含业务请求。
|
|
class SplashPage extends ConsumerStatefulWidget {
|
|
const SplashPage({super.key});
|
|
|
|
@override
|
|
ConsumerState<SplashPage> createState() => _SplashPageState();
|
|
}
|
|
|
|
class _SplashPageState extends ConsumerState<SplashPage> {
|
|
bool _navigated = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// 首帧绘制后做一次性的路由决策。
|
|
// 不使用 Future.delayed 做跳转:App 进后台再回前台时计时器可能被挂起,
|
|
// 导致恢复后跳转不可靠、画面卡在第一屏。改用首帧回调 + 幂等保护。
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _decideRoute());
|
|
}
|
|
|
|
void _decideRoute() {
|
|
if (_navigated || !mounted) return;
|
|
_navigated = true;
|
|
try {
|
|
final target = TokenStorage.isLoggedIn ? '/home' : '/login';
|
|
context.go(target);
|
|
_repaintAfterNavigation();
|
|
} catch (_) {
|
|
// 极端情况下的路由异常不应卡死首屏,重试一次。
|
|
if (mounted) {
|
|
_navigated = false;
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _decideRoute());
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 规避 Impeller(OpenGLES) 冷启动首帧的字形图集纹理错位:
|
|
/// 首屏可能整块图标/文字残缺,且未变化的图层不会再绘制,画面会一直残缺,
|
|
/// 直到触发一次重排/重绘(如切页、旋转)才恢复。首个页面绘制完成后主动把
|
|
/// 整棵渲染树标记为待重绘,强制重新录制并重新光栅化一次。
|
|
static void _repaintAfterNavigation() {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
for (final view in WidgetsBinding.instance.renderViews) {
|
|
_markNeedsPaint(view);
|
|
}
|
|
});
|
|
}
|
|
|
|
static void _markNeedsPaint(RenderObject object) {
|
|
object.markNeedsPaint();
|
|
object.visitChildren(_markNeedsPaint);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
return AppPageScaffold(
|
|
backgroundColor: CupertinoColors.systemBackground,
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(
|
|
CupertinoIcons.heart_fill,
|
|
size: 64,
|
|
color: CupertinoColors.activeBlue,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
l10n.appTitle,
|
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
|
|
),
|
|
SizedBox(height: 8),
|
|
CupertinoActivityIndicator(),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|