feat(android): 支持沉浸式状态栏、地图定位与自定义签名
- 配置 edge-to-edge 沉浸式状态栏与刘海屏适配 - 新增百度地图权限、AK 配置及定位权限说明 - 接入 MethodChannel 实现返回键退后台热启动优化 - 配置自定义签名并更新构建逻辑 - 完善 token 刷新与鉴权失效统一处理 - 新增地图页与截图页路由 - 修复返回键拦截导致的 PopScope 失效问题
This commit is contained in:
1 parent
41d815336a
commit
06cdc77172
51 files changed
+3988
-634
No files matched your search
@@ -1,137 +1,321 @@
|
||||
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/app/constants/app_constants.dart';
|
||||
import 'package:ttstd_family_care/core/widgets/feature_ui.dart';
|
||||
import 'package:ttstd_family_care/features/device/data/device_providers.dart';
|
||||
import 'package:ttstd_family_care/features/device/domain/device_models.dart';
|
||||
import 'package:ttstd_family_care/l10n/app_localizations.dart';
|
||||
|
||||
import '../../../core/widgets/feature_ui.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
/// 应用页(管理 → 应用)。
|
||||
///
|
||||
/// 对应移动端设计稿:搜索栏 + 常用九宫格 + 系统工具/影音娱乐分类列表。
|
||||
class AppsPage extends StatelessWidget {
|
||||
/// 应用列表页(对接 client「已安装应用」接口)。
|
||||
class AppsPage extends ConsumerWidget {
|
||||
const AppsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(l10n.appsTitle),
|
||||
leading: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
child: const Icon(CupertinoIcons.back),
|
||||
onPressed: () => context.go('/messages'),
|
||||
final sn = ref.watch(selectedDeviceSnProvider);
|
||||
final appsAsync = sn == null
|
||||
? const AsyncValue<List<DeviceApkInfo>>.data(const [])
|
||||
: ref.watch(deviceApksProvider(sn));
|
||||
|
||||
return PopScope(
|
||||
// 拦截系统返回键:优先出栈;若无法出栈则跳回「管理」页,避免直接退到桌面。
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (didPop) return;
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/messages');
|
||||
}
|
||||
},
|
||||
child: CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(l10n.appsTitle),
|
||||
leading: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
child: const Icon(CupertinoIcons.back),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
),
|
||||
trailing: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
child: const Text('管理'),
|
||||
onPressed: () {},
|
||||
child: SafeArea(
|
||||
child: appsAsync.when(
|
||||
loading: () => const Center(child: CupertinoActivityIndicator()),
|
||||
error: (e, _) => Center(
|
||||
child: Text('${l10n.appsLoadFailed}:$e',
|
||||
style: const TextStyle(color: AppColors.sub)),
|
||||
),
|
||||
data: (apps) {
|
||||
if (apps.isEmpty) {
|
||||
return Center(
|
||||
child: Text(l10n.appsEmpty,
|
||||
style: const TextStyle(color: AppColors.sub)),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
final app = apps[index];
|
||||
return _appCell(context, ref, l10n, sn, app);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
children: [
|
||||
// 搜索栏
|
||||
Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 10, 16, 4),
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [BoxShadow(color: Color(0x14141E3C), blurRadius: 8, offset: Offset(0, 2))],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _appCell(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
AppLocalizations l10n,
|
||||
String? sn,
|
||||
DeviceApkInfo app,
|
||||
) =>
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Color(0x08000000),
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, 4),
|
||||
),
|
||||
child: const Row(
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 14),
|
||||
Icon(CupertinoIcons.search, size: 16, color: AppColors.sub),
|
||||
SizedBox(width: 8),
|
||||
Text('搜索应用', style: TextStyle(fontSize: 14, color: AppColors.sub)),
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: _appIcon(app.iconUrl),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(app.appName ?? app.packageName,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.ink)),
|
||||
const SizedBox(height: 4),
|
||||
Text('${app.packageName}${app.versionName != null ? ' · v${app.versionName}' : ''}',
|
||||
style:
|
||||
const TextStyle(fontSize: 12, color: AppColors.sub),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (app.systemApp)
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.sub.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Text('系统',
|
||||
style: TextStyle(fontSize: 11, color: AppColors.sub)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionTitle(l10n.appsCommon),
|
||||
CardBox(
|
||||
child: Column(
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: IconTile(emoji: '🖼️', color: AppColors.blue, label: l10n.menuAlbum)),
|
||||
Expanded(child: IconTile(emoji: '⏰', color: AppColors.orange, label: l10n.menuAlarm)),
|
||||
Expanded(child: IconTile(emoji: '👥', color: AppColors.green, label: l10n.menuContacts)),
|
||||
Expanded(child: IconTile(emoji: '📁', color: AppColors.purple, label: l10n.menuFiles)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: IconTile(emoji: '📷', color: AppColors.red, label: l10n.appsCamera)),
|
||||
Expanded(child: IconTile(emoji: '📅', color: AppColors.teal, label: '日历')),
|
||||
Expanded(child: IconTile(emoji: '📝', color: const Color(0xFF22C55E), label: '备忘录')),
|
||||
Expanded(child: IconTile(emoji: '➕', color: AppColors.gray, label: l10n.appsAdd)),
|
||||
],
|
||||
_actionButton(context, ref, l10n, sn, app, 'launch',
|
||||
l10n.appOpLaunch),
|
||||
const SizedBox(width: 8),
|
||||
_actionButton(context, ref, l10n, sn, app, 'stop',
|
||||
l10n.appOpStop),
|
||||
const SizedBox(width: 8),
|
||||
_actionButton(context, ref, l10n, sn, app, 'clear_data',
|
||||
l10n.appOpClearData),
|
||||
const SizedBox(width: 8),
|
||||
_actionButton(
|
||||
context,
|
||||
ref,
|
||||
l10n,
|
||||
sn,
|
||||
app,
|
||||
'uninstall',
|
||||
l10n.appOpUninstall,
|
||||
destructive: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
/// 应用操作按钮:点击后执行对应操作;卸载/清除数据等危险操作先弹确认框。
|
||||
Widget _actionButton(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
AppLocalizations l10n,
|
||||
String? sn,
|
||||
DeviceApkInfo app,
|
||||
String op,
|
||||
String label, {
|
||||
bool destructive = false,
|
||||
}) {
|
||||
final Color color = destructive ? AppColors.red : AppColors.blue;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (op == 'uninstall') {
|
||||
_confirmAppOp(context, ref, l10n, sn, app, 'uninstall',
|
||||
l10n.appOpUninstallConfirm);
|
||||
} else if (op == 'clear_data') {
|
||||
_confirmAppOp(context, ref, l10n, sn, app, 'clear_data',
|
||||
l10n.appOpClearDataConfirm);
|
||||
} else {
|
||||
_runAppOp(context, ref, l10n, sn, app.packageName, op);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
height: 34,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
SectionTitle(l10n.appsSystem),
|
||||
CardBox(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_appRow('⚙️', const Color(0xFF64748B), '设置', '系统 · 已安装'),
|
||||
const AppDivider(),
|
||||
_appRow('🌐', AppColors.teal, '浏览器', '系统 · 已安装'),
|
||||
const AppDivider(),
|
||||
_appRow('🗺️', const Color(0xFF22C55E), '地图', '系统 · 已安装'),
|
||||
],
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
SectionTitle(l10n.appsEntertain),
|
||||
CardBox(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_appRow('🎵', AppColors.red, '音乐', 'v8.2 · 已安装'),
|
||||
const AppDivider(),
|
||||
_appRow('🎬', AppColors.orange, '视频', 'v5.1 · 已安装'),
|
||||
const AppDivider(),
|
||||
_appRow('📚', AppColors.purple, '阅读', 'v3.4 · 已安装'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 危险应用操作(卸载/清除数据)确认弹窗。
|
||||
Future<void> _confirmAppOp(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
AppLocalizations l10n,
|
||||
String? sn,
|
||||
DeviceApkInfo app,
|
||||
String op,
|
||||
String message,
|
||||
) async {
|
||||
final confirmed = await showCupertinoDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => CupertinoAlertDialog(
|
||||
title: Text(l10n.appOpConfirmTitle),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text(l10n.cancel),
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
isDestructiveAction: true,
|
||||
child: Text(l10n.confirm),
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !context.mounted) return;
|
||||
await _runAppOp(context, ref, l10n, sn, app.packageName, op);
|
||||
}
|
||||
|
||||
/// 下发应用操作指令并弹出结果提示。
|
||||
Future<void> _runAppOp(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
AppLocalizations l10n,
|
||||
String? sn,
|
||||
String packageName,
|
||||
String op,
|
||||
) async {
|
||||
if (sn == null || sn.isEmpty) {
|
||||
_showAppOpResult(context, l10n, l10n.opCmdFailed);
|
||||
return;
|
||||
}
|
||||
final error =
|
||||
await ref.read(deviceRepositoryProvider).sendAppOp(sn, op, packageName);
|
||||
if (!context.mounted) return;
|
||||
if (error == null) {
|
||||
// 卸载成功后应用已不在列表,刷新应用列表。
|
||||
if (op == 'uninstall') {
|
||||
ref.invalidate(deviceApksProvider(sn));
|
||||
}
|
||||
_showAppOpResult(context, l10n, l10n.appOpSent);
|
||||
} else {
|
||||
_showAppOpResult(context, l10n, error);
|
||||
}
|
||||
}
|
||||
|
||||
/// 应用操作结果提示弹窗。
|
||||
void _showAppOpResult(
|
||||
BuildContext context, AppLocalizations l10n, String message) {
|
||||
showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => CupertinoAlertDialog(
|
||||
title: Text(l10n.alertTitle),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text(l10n.confirm),
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _appRow(String emoji, Color color, String name, String sub) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(13)),
|
||||
child: Center(child: Text(emoji, style: const TextStyle(fontSize: 19))),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, style: const TextStyle(fontSize: 14.5, fontWeight: FontWeight.w600, color: AppColors.ink)),
|
||||
Text(sub, style: const TextStyle(fontSize: 12, color: AppColors.sub)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE8F8EE),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: const Text('打开', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: AppColors.green)),
|
||||
),
|
||||
],
|
||||
),
|
||||
/// 应用图标:后台返回的是相对路径(如 /static/app_icon/xxx.png),
|
||||
/// 需要拼接接口 Host 才能作为网络图片加载;无图标或加载失败时回退到占位图标。
|
||||
Widget _appIcon(String? iconUrl) {
|
||||
final resolved = _resolveIconUrl(iconUrl);
|
||||
if (resolved == null) {
|
||||
return const Center(
|
||||
child: Icon(CupertinoIcons.app_fill, color: AppColors.blue, size: 22),
|
||||
);
|
||||
}
|
||||
return Image.network(
|
||||
resolved,
|
||||
width: 44,
|
||||
height: 44,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Center(
|
||||
child: Icon(CupertinoIcons.app_fill, color: AppColors.blue, size: 22),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 将相对或绝对图标地址解析为完整可访问的 URL。
|
||||
String? _resolveIconUrl(String? iconUrl) {
|
||||
if (iconUrl == null || iconUrl.isEmpty) return null;
|
||||
if (iconUrl.startsWith('http://') || iconUrl.startsWith('https://')) {
|
||||
return iconUrl;
|
||||
}
|
||||
// 去除 /api 前缀,保留协议与 Host。
|
||||
final base = AppConstants.kBaseUrl.replaceFirst(RegExp(r'/api/?$'), '');
|
||||
return '$base$iconUrl';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user