feat: 增强 HomeScreen 录音交互与 ChatBloc 状态管理

- 新增录音启动延迟处理,解决权限未就绪时的竞态问题
- 实现历史分页滚动位置保持,提升加载体验
- 添加文本输入框点击键盘显示与焦点管理
- 优化 ChatBloc provider 到 MultiBlocProvider 支持
- 修复 ApiException 429 错误详情解析(支持 JSON 字符串 body)
- 改进 LocalNotificationService 精确闹钟权限请求
- 优化 UiSchemaRenderer GridView children 生成
- 支持导航 action 的 replace 参数
- 移除 Agent router 速率限制逻辑(_allow_run_request, _allow_transcribe_request)
- 补充相关单元测试与集成测试
This commit is contained in:
qzl
2026-03-18 17:03:22 +08:00
parent b34697660d
commit 8539f05a66
13 changed files with 578 additions and 143 deletions
+37 -3
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart';
abstract class ApiException implements Exception {
@@ -17,9 +19,14 @@ abstract class ApiException implements Exception {
final data = response?.data;
String detail;
if (data is Map<String, dynamic>) {
final decodedData = _normalizeErrorData(data);
if (decodedData is Map<String, dynamic>) {
detail =
(data['detail'] ?? data['message'] ?? data['error'])?.toString() ??
(decodedData['detail'] ??
decodedData['message'] ??
decodedData['error'])
?.toString() ??
'请求失败';
} else {
detail = _networkErrorMessage(error);
@@ -42,6 +49,29 @@ abstract class ApiException implements Exception {
return const ServerException('网络错误');
}
static Map<String, dynamic>? _normalizeErrorData(dynamic data) {
if (data is Map<String, dynamic>) {
return data;
}
if (data is Map) {
return data.map((key, value) => MapEntry(key.toString(), value));
}
if (data is String && data.trim().isNotEmpty) {
try {
final decoded = jsonDecode(data);
if (decoded is Map<String, dynamic>) {
return decoded;
}
if (decoded is Map) {
return decoded.map((key, value) => MapEntry(key.toString(), value));
}
} catch (_) {
return null;
}
}
return null;
}
static String _localizeError(String detail, int? statusCode) {
if (statusCode == 403) {
return '没有权限执行此操作';
@@ -50,7 +80,11 @@ abstract class ApiException implements Exception {
return '请求的资源不存在';
}
if (statusCode == 429) {
return '请求过于频繁,请稍后再试';
final normalized = detail.trim();
if (normalized.isEmpty || normalized == '请求失败') {
return '请求过于频繁,请稍后再试';
}
return detail;
}
if (statusCode != null && statusCode >= 500) {
return '服务器错误,请稍后再试';