8d890c0424
- 新增 lib/core/network/:ApiClient(dio 封装,错误信封→类型化异常,base URL 经 --dart-define=PATBOND_API_BASE_URL 注入)、AuthInterceptor(Bearer + 设备标识)、TokenRefresher(单飞刷新,401/40101 重放一次,仅 40102/再 401 清会话) - 新增 lib/features/auth/:SessionManager(token 只进 flutter_secure_storage)、AuthRepository(login/register/refresh/logout/me,注册带 Idempotency-Key)、Splash(500ms 最短停留/5s 超时/错误态重试+改用账号登录)、登录页与注册页(照 12 号组装稿,错误三层映射,预留区不渲染) - App 根组件改为认证状态机驱动(Splash↔登录↔主壳 300ms fade);个人中心退出登录接入真实 logout - 顺带修复:FIX-1 促销卡渐变改 [primaryStrong, primary]、FIX-2 补 helperStyle: muted、README dart format 命令补 --output=none - 新增依赖:dio ^5.11.1、flutter_secure_storage ^11.0.0、uuid ^4.6.0 - 门禁:dart format(0 changed)/ flutter analyze(No issues)/ flutter test(30 passed,其中新增 23:TokenRefresher 5 + AuthRepository 10 + 登录页 4 + 注册页 4) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
21 lines
638 B
Dart
21 lines
638 B
Dart
/// 服务端统一响应信封 `{code, message, data}` 的解析结果。
|
|
class ApiEnvelope {
|
|
const ApiEnvelope({required this.code, required this.message, this.data});
|
|
|
|
final int code;
|
|
final String message;
|
|
final Object? data;
|
|
|
|
/// 从响应体解析信封;结构不符(非 JSON 对象 / 无 int code)返回 null。
|
|
static ApiEnvelope? tryParse(Object? body) {
|
|
if (body is! Map) return null;
|
|
final code = body['code'];
|
|
if (code is! int) return null;
|
|
return ApiEnvelope(
|
|
code: code,
|
|
message: body['message'] is String ? body['message'] as String : '',
|
|
data: body['data'],
|
|
);
|
|
}
|
|
}
|