- 将资料编辑页重构为可交互表单,支持昵称、签名编辑与头像更换 - 新增 DioClient 本地缓存读取与写入方法,支持离线读取策略快照 - 设备策略切换后自动使本地缓存失效,避免数据不一致 - Home Tab 切换时选中态跟随可见页面,滑动过程中实时更新底栏高亮 - 系统设置页引入 loading 遮罩层,防止切换开关时重复操作 - 个人资料页接入 profileController 展示真实用户信息与加载状态 - 适配深色模式,修正 home_tab 中头像与文字颜色硬编码问题
1122 lines
41 KiB
Dart
1122 lines
41 KiB
Dart
import 'package:ttstd_family_care/core/network/cached_network_image.dart';
|
||
import 'package:cupertino_ui/cupertino_ui.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
import 'package:go_router/go_router.dart';
|
||
import 'package:material_ui/material_ui.dart';
|
||
import 'package:ttstd_family_care/app/theme/dark_mode.dart';
|
||
import 'package:ttstd_family_care/core/widgets/app_page_scaffold.dart';
|
||
|
||
import '../../../core/platform/platform_capabilities.dart';
|
||
import '../../../core/utils/time_format.dart';
|
||
import '../../../core/widgets/feature_ui.dart';
|
||
import '../../../features/device/data/device_providers.dart';
|
||
import '../../../features/device/domain/device_models.dart';
|
||
import '../../../features/device/presentation/device_switcher.dart';
|
||
import '../../../l10n/app_localizations.dart';
|
||
import 'location_map_view.dart';
|
||
|
||
/// 首页 Tab 内容(特性模块:home / presentation)。
|
||
///
|
||
/// 对应移动端设计稿的「平板信息页」:实时位置地图、最近截图、
|
||
/// 今日使用时长、设备操作(重启/关机/截屏/刷新/定位)与常用功能网格。
|
||
///
|
||
/// 性能优化说明:
|
||
/// - 首页包含百度地图(原生平台视图)与网络图片等高重绘成本内容。
|
||
/// - 为提升下拉/滚动流畅度,将数据驱动的卡片(定位卡片、截图卡片)拆分为
|
||
/// 独立的 `ConsumerWidget`,各自 `watch` 自己的 Provider,实现**局部刷新**,
|
||
/// 避免任意一个异步数据变化时重建整页(尤其避免重建地图原生视图)。
|
||
/// - 地图使用 `RepaintBoundary` 隔离重绘;静态卡片尽量 `const` 化。
|
||
class HomeTab extends ConsumerWidget {
|
||
const HomeTab({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
final l10n = AppLocalizations.of(context);
|
||
// 仅在此 watch 设备 SN;设备切换时才重建整页结构,其余异步数据由各卡片自行 watch。
|
||
final sn = ref.watch(selectedDeviceSnProvider);
|
||
// 设备列表加载完成且为空 → 展示「未绑定设备」引导界面。
|
||
final devicesAsync = ref.watch(myDevicesProvider);
|
||
final noDevice = devicesAsync.hasValue && (devicesAsync.value?.isEmpty ?? true);
|
||
|
||
return AppPageScaffold(
|
||
navigationBar: CupertinoNavigationBar(
|
||
middle: Text(l10n.appTitle,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(
|
||
fontSize: 20, fontWeight: FontWeight.w700, color: DarkMode.color(context, AppColors.ink))),
|
||
trailing: const DeviceSwitcherButton(),
|
||
),
|
||
child: SafeArea(
|
||
child: noDevice
|
||
? _noDeviceView(context, l10n)
|
||
: CustomScrollView(
|
||
physics: const AlwaysScrollableScrollPhysics(
|
||
parent: BouncingScrollPhysics(),
|
||
),
|
||
slivers: [
|
||
CupertinoSliverRefreshControl(
|
||
onRefresh: () async {
|
||
// 下拉刷新:重新拉取设备列表、当前设备最新定位与最近截图列表。
|
||
await Future.wait([
|
||
ref.refresh(myDevicesProvider.future),
|
||
if (sn != null) ref.refresh(deviceLocationProvider(sn).future),
|
||
if (sn != null) ref.refresh(recentScreenshotsProvider(sn).future),
|
||
]);
|
||
},
|
||
),
|
||
SliverPadding(
|
||
padding: const EdgeInsets.only(bottom: 96),
|
||
sliver: SliverList(
|
||
// 用 builder 按需懒构建,避免一次性持有所有卡片 Element;
|
||
// 配合下方各卡片自身的局部刷新,减少无效重建。
|
||
delegate: SliverChildBuilderDelegate(
|
||
(context, index) {
|
||
// 定位卡片、截图卡片为独立 ConsumerWidget,各自 watch 自己的
|
||
// Provider,实现局部刷新(数据变化时不重建其余静态卡片)。
|
||
final child = switch (index) {
|
||
0 => const _LocationCard(),
|
||
1 => const _ScreenshotsCard(),
|
||
2 => _usageCard(context, l10n),
|
||
3 => _deviceOpsCard(context, l10n, ref, sn),
|
||
4 => SectionTitle(l10n.homeCommon),
|
||
5 => _commonCard(context, ref, l10n, sn),
|
||
_ => const SizedBox.shrink(),
|
||
};
|
||
// 给每个 child 加上稳定 key,配合 findChildIndexCallback 实现
|
||
// 滚动时 Element 复用,避免滚动离屏/回屏时重建高成本子树。
|
||
return KeyedSubtree(
|
||
key: ValueKey<int>(index),
|
||
child: child,
|
||
);
|
||
},
|
||
childCount: 6,
|
||
findChildIndexCallback: (key) {
|
||
final v = key is ValueKey<int> ? key.value : null;
|
||
return (v != null && v < 6) ? v : null;
|
||
},
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 未绑定任何设备时的引导界面:提示文案 + 「去绑定」按钮。
|
||
Widget _noDeviceView(BuildContext context, AppLocalizations l10n) {
|
||
return Center(
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 40),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Container(
|
||
width: 72,
|
||
height: 72,
|
||
decoration: BoxDecoration(
|
||
color: DarkMode.color(context, AppColors.surface),
|
||
borderRadius: BorderRadius.circular(22),
|
||
),
|
||
child: const Center(
|
||
child: Text('📱', style: TextStyle(fontSize: 34))),
|
||
),
|
||
const SizedBox(height: 16),
|
||
Text(
|
||
l10n.homeNoDevice,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
fontSize: 15,
|
||
fontWeight: FontWeight.w600,
|
||
color: DarkMode.color(context, AppColors.ink),
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
l10n.homeNoDeviceTip,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.sub)),
|
||
),
|
||
const SizedBox(height: 20),
|
||
// 「去绑定」按钮:跳转设备管理页,用户可在其中进入绑定/扫码。
|
||
GestureDetector(
|
||
onTap: () => context.push('/device/manage'),
|
||
child: Container(
|
||
padding:
|
||
const EdgeInsets.symmetric(horizontal: 32, vertical: 10),
|
||
decoration: BoxDecoration(
|
||
color: AppColors.green,
|
||
borderRadius: BorderRadius.circular(22),
|
||
),
|
||
child: Text(
|
||
l10n.homeBindDevice,
|
||
style: const TextStyle(
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.w700,
|
||
color: CupertinoColors.white,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _cardHeader(BuildContext context,
|
||
String emoji,
|
||
Color color,
|
||
String title, {
|
||
String? trailing,
|
||
VoidCallback? onTrailingTap,
|
||
}) =>
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: 12),
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
width: 22,
|
||
height: 22,
|
||
decoration: BoxDecoration(
|
||
color: color,
|
||
borderRadius: BorderRadius.circular(7),
|
||
),
|
||
child: Center(child: Text(emoji, style: const TextStyle(fontSize: 13))),
|
||
),
|
||
const SizedBox(width: 7),
|
||
Text(title,
|
||
style: TextStyle(
|
||
fontSize: 15, fontWeight: FontWeight.w700, color: DarkMode.color(context, AppColors.ink))),
|
||
const Spacer(),
|
||
if (trailing != null)
|
||
GestureDetector(
|
||
onTap: onTrailingTap,
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||
child: Text(trailing,
|
||
style: const TextStyle(
|
||
fontSize: 12,
|
||
fontWeight: FontWeight.w600,
|
||
color: AppColors.green)),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
|
||
Widget _usageCard(BuildContext context, AppLocalizations l10n) => CardBox(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
_cardHeader(context, '⏱️', AppColors.orange, l10n.homeUsage, trailing: l10n.homeUsageTrend),
|
||
Row(
|
||
children: [
|
||
// 环形进度(约 60%)
|
||
SizedBox(
|
||
width: 86,
|
||
height: 86,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Container(
|
||
width: 86,
|
||
height: 86,
|
||
decoration: BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
gradient: SweepGradient(
|
||
stops: const [0, 0.6, 0.6, 1],
|
||
colors: [
|
||
AppColors.green,
|
||
AppColors.green,
|
||
DarkMode.color(context, AppColors.track),
|
||
DarkMode.color(context, AppColors.track),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
Container(
|
||
width: 64,
|
||
height: 64,
|
||
decoration: BoxDecoration(
|
||
color: DarkMode.color(context, AppColors.card),
|
||
shape: BoxShape.circle,
|
||
),
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Text('3.4h',
|
||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: DarkMode.color(context, AppColors.ink))),
|
||
Text(l10n.homeUsageToday,
|
||
style: TextStyle(fontSize: 10, color: DarkMode.color(context, AppColors.sub))),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
const SizedBox(width: 16),
|
||
Expanded(
|
||
child: Column(
|
||
children: [
|
||
_usageBar(context, '阅读', 0.55, AppColors.green),
|
||
_usageBar(context, '视频', 0.30, AppColors.blue),
|
||
_usageBar(context, '办公', 0.15, AppColors.orange),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
|
||
Widget _usageBar(BuildContext context, String name, double v, Color color) => Padding(
|
||
padding: const EdgeInsets.only(bottom: 8),
|
||
child: Row(
|
||
children: [
|
||
SizedBox(
|
||
width: 42,
|
||
child: Text(
|
||
name,
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: DarkMode.tone(
|
||
context,
|
||
const Color(0xFF4B5563),
|
||
DarkMode.color(context, AppColors.ink),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: Container(
|
||
height: 7,
|
||
decoration: BoxDecoration(
|
||
color: DarkMode.color(context, AppColors.track),
|
||
borderRadius: BorderRadius.circular(4),
|
||
),
|
||
child: FractionallySizedBox(
|
||
alignment: Alignment.centerLeft,
|
||
widthFactor: v,
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
color: color,
|
||
borderRadius: BorderRadius.circular(4),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
|
||
Widget _deviceOpsCard(
|
||
BuildContext context,
|
||
AppLocalizations l10n,
|
||
WidgetRef ref,
|
||
String? sn,
|
||
) =>
|
||
CardBox(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
_cardHeader(context, '⚡', AppColors.purple, l10n.homeDeviceOps),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🔄',
|
||
color: AppColors.blue,
|
||
label: l10n.opRestart,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _confirmDeviceOp(
|
||
context, l10n, ref, sn, 'reboot', l10n.opRestartConfirm),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🔌',
|
||
color: AppColors.red,
|
||
label: l10n.opShutdown,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _confirmDeviceOp(
|
||
context, l10n, ref, sn, 'shutdown', l10n.opShutdownConfirm),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '📸',
|
||
color: AppColors.green,
|
||
label: l10n.opScreenshot,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'screenshot',
|
||
refreshScreenshots: true),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🔃',
|
||
color: AppColors.orange,
|
||
label: l10n.opRefresh,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'refresh'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '📍',
|
||
color: AppColors.purple,
|
||
label: l10n.opLocate,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'locate',
|
||
refreshLocation: true),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
|
||
/// 危险操作(重启/关机)确认弹窗,确认后下发指令。
|
||
Future<void> _confirmDeviceOp(
|
||
BuildContext context,
|
||
AppLocalizations l10n,
|
||
WidgetRef ref,
|
||
String? sn,
|
||
String op,
|
||
String message,
|
||
) async {
|
||
final confirmed = await showCupertinoDialog<bool>(
|
||
context: context,
|
||
builder: (dialogContext) => CupertinoAlertDialog(
|
||
title: Text(l10n.opConfirmTitle),
|
||
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 _runDeviceOp(context, ref, l10n, sn, op);
|
||
}
|
||
|
||
/// 远程拍照:弹窗选择摄像头(后置/前置),确认后下发拍照指令。
|
||
///
|
||
/// 后端 [DeviceService.takePhoto] 通过 `camera` 参数区分摄像头
|
||
/// (`0` 后置,`1` 前置),随指令一并下发给设备端。
|
||
Future<void> _pickCameraAndTakePhoto(
|
||
BuildContext context,
|
||
WidgetRef ref,
|
||
AppLocalizations l10n,
|
||
String? sn,
|
||
) async {
|
||
if (sn == null || sn.isEmpty) {
|
||
_showOpResult(context, l10n, l10n.opCmdFailed);
|
||
return;
|
||
}
|
||
final int? camera = await showCupertinoDialog<int>(
|
||
context: context,
|
||
builder: (dialogContext) => CupertinoAlertDialog(
|
||
title: Text(l10n.cfTakePhotoTitle),
|
||
actions: [
|
||
CupertinoDialogAction(
|
||
onPressed: () => Navigator.of(dialogContext).pop(0),
|
||
child: Text(l10n.cfCamRear),
|
||
),
|
||
CupertinoDialogAction(
|
||
onPressed: () => Navigator.of(dialogContext).pop(1),
|
||
child: Text(l10n.cfCamFront),
|
||
),
|
||
CupertinoDialogAction(
|
||
isDestructiveAction: true,
|
||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||
child: Text(l10n.cancel),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
if (camera == null) return;
|
||
if (!context.mounted) return;
|
||
await _runDeviceOp(
|
||
context,
|
||
ref,
|
||
l10n,
|
||
sn,
|
||
'take_photo',
|
||
refreshScreenshots: true,
|
||
extra: {'camera': camera},
|
||
);
|
||
}
|
||
|
||
/// 下发设备操作指令并弹出结果提示。
|
||
Future<void> _runDeviceOp(
|
||
BuildContext context,
|
||
WidgetRef ref,
|
||
AppLocalizations l10n,
|
||
String? sn,
|
||
String op, {
|
||
bool refreshScreenshots = false,
|
||
bool refreshLocation = false,
|
||
Map<String, dynamic>? extra,
|
||
}) async {
|
||
if (sn == null || sn.isEmpty) {
|
||
_showOpResult(context, l10n, l10n.opCmdFailed);
|
||
return;
|
||
}
|
||
final error = await ref.read(deviceRepositoryProvider).sendDeviceOp(sn, op, extra: extra);
|
||
if (!context.mounted) return;
|
||
if (error == null) {
|
||
if (refreshScreenshots) ref.invalidate(recentScreenshotsProvider(sn));
|
||
if (refreshLocation) ref.invalidate(deviceLocationProvider(sn));
|
||
// 截屏操作成功后,额外提示锁屏状态下截图可能为黑色。
|
||
_showOpResult(
|
||
context,
|
||
l10n,
|
||
l10n.opCmdSent,
|
||
subtitle: refreshScreenshots ? l10n.opScreenshotHint : null,
|
||
);
|
||
} else {
|
||
_showOpResult(context, l10n, error);
|
||
}
|
||
}
|
||
|
||
/// 操作结果提示弹窗。
|
||
///
|
||
/// [subtitle] 为可选的补充说明(如截屏操作的成功提示)。
|
||
void _showOpResult(
|
||
BuildContext context,
|
||
AppLocalizations l10n,
|
||
String message, {
|
||
String? subtitle,
|
||
}) {
|
||
showCupertinoDialog(
|
||
context: context,
|
||
builder: (dialogContext) => CupertinoAlertDialog(
|
||
title: Text(l10n.alertTitle),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Text(message, textAlign: TextAlign.center),
|
||
if (subtitle != null) ...[
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
subtitle,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: DarkMode.color(context, AppColors.sub),
|
||
),
|
||
),
|
||
],
|
||
],
|
||
),
|
||
actions: [
|
||
CupertinoDialogAction(
|
||
child: Text(l10n.confirm),
|
||
onPressed: () => Navigator.pop(dialogContext),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 「更多」弹窗:以图标网格列出未在常用区直接展示的远程推送操作,
|
||
/// 确保后端 ClientDeviceOpsController 暴露的其余推送接口(如恢复出厂、开发者模式)
|
||
/// 在家属端 UI 也有入口,实现「每个推送接口都对接」。
|
||
Future<void> _showMoreOpsSheet(
|
||
BuildContext context,
|
||
WidgetRef ref,
|
||
AppLocalizations l10n,
|
||
String? sn,
|
||
) async {
|
||
final items = <_MoreOpItem>[
|
||
_MoreOpItem(emoji: '♻️', color: AppColors.orange, label: l10n.cfRestore, op: 'restore'),
|
||
_MoreOpItem(emoji: '🛠️', color: AppColors.blue, label: l10n.cfDeveloper, op: 'developer'),
|
||
];
|
||
if (sn == null || sn.isEmpty) {
|
||
_showOpResult(context, l10n, l10n.opCmdFailed);
|
||
return;
|
||
}
|
||
final String? op = await showCupertinoModalPopup<String>(
|
||
context: context,
|
||
builder: (ctx) => SafeArea(
|
||
child: Container(
|
||
width: double.infinity,
|
||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||
decoration: BoxDecoration(
|
||
color: Theme.of(ctx).scaffoldBackgroundColor,
|
||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||
),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Text(
|
||
l10n.cfMoreOpsTitle,
|
||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||
),
|
||
const SizedBox(height: 16),
|
||
GridView.count(
|
||
crossAxisCount: 3,
|
||
shrinkWrap: true,
|
||
physics: const NeverScrollableScrollPhysics(),
|
||
childAspectRatio: 0.95,
|
||
mainAxisSpacing: 10,
|
||
crossAxisSpacing: 10,
|
||
children: [
|
||
for (final item in items)
|
||
IconTile(
|
||
emoji: item.emoji,
|
||
color: item.color,
|
||
label: item.label,
|
||
size: 54,
|
||
iconSize: 24,
|
||
onTap: () => Navigator.of(ctx).pop(item.op),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 12),
|
||
CupertinoButton(
|
||
onPressed: () => Navigator.of(ctx).pop(),
|
||
child: Text(l10n.cancel),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
if (op == null || !context.mounted) return;
|
||
await _runDeviceOp(context, ref, l10n, sn, op);
|
||
}
|
||
|
||
Widget _commonCard(BuildContext context, WidgetRef ref, AppLocalizations l10n, String? sn) => CardBox(
|
||
child: Column(
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '📁',
|
||
color: AppColors.blue,
|
||
label: l10n.cfFileTransfer,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'file_transfer'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '📷',
|
||
color: AppColors.green,
|
||
label: l10n.cfRemoteCam,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _pickCameraAndTakePhoto(context, ref, l10n, sn),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '💬',
|
||
color: AppColors.orange,
|
||
label: l10n.cfMsgSync,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'msg_sync'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🧹',
|
||
color: AppColors.purple,
|
||
label: l10n.cfClean,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'clean'),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 14),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '📺',
|
||
color: AppColors.red,
|
||
label: l10n.cfMirror,
|
||
size: 50,
|
||
iconSize: 20,
|
||
// 远程控制:静默触发设备端启动屏幕采集(HTTP mirror 命令,不弹窗),
|
||
// 直接进入 WebRTC 远程控制页建立实时画面与控制。
|
||
onTap: () async {
|
||
if (sn != null && sn.isNotEmpty) {
|
||
// 静默下发 mirror,触发设备端启动屏幕采集;失败也不阻断进入控制页
|
||
await ref
|
||
.read(deviceRepositoryProvider)
|
||
.sendDeviceOp(sn, 'mirror');
|
||
}
|
||
if (context.mounted) {
|
||
context.push('/connection');
|
||
}
|
||
},
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🔔',
|
||
color: AppColors.teal,
|
||
label: l10n.cfLost,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'locate',
|
||
refreshLocation: true),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🔐',
|
||
color: AppColors.blue,
|
||
label: l10n.cfScreenLock,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'screen_lock'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🔒',
|
||
color: const Color(0xFF22C55E),
|
||
label: l10n.cfAppLock,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'refresh'),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 14),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '♻️',
|
||
color: AppColors.orange,
|
||
label: l10n.cfRestore,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'restore'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🛠️',
|
||
color: AppColors.blue,
|
||
label: l10n.cfDeveloper,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _runDeviceOp(context, ref, l10n, sn, 'developer'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '⚙️',
|
||
color: AppColors.gray,
|
||
label: l10n.cfSystemSettings,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => context.push('/settings'),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '🖼️',
|
||
color: AppColors.teal,
|
||
label: l10n.cfWallpaper,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => context.push('/wallpaper'),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 14),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: IconTile(
|
||
emoji: '⋯',
|
||
color: AppColors.gray,
|
||
label: l10n.cfMore,
|
||
size: 50,
|
||
iconSize: 20,
|
||
onTap: () => _showMoreOpsSheet(context, ref, l10n, sn),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
class _MoreOpItem {
|
||
const _MoreOpItem({
|
||
required this.emoji,
|
||
required this.color,
|
||
required this.label,
|
||
required this.op,
|
||
});
|
||
|
||
final String emoji;
|
||
final Color color;
|
||
final String label;
|
||
final String op;
|
||
}
|
||
|
||
/// 实时位置卡片(独立 ConsumerWidget)。
|
||
///
|
||
/// 自己 `watch` 定位 Provider,定位数据变化时**仅重建本卡片**,避免连带
|
||
/// 重建整页其它卡片(尤其百度地图原生视图与静态卡片),是首页流畅度的关键。
|
||
class _LocationCard extends ConsumerWidget {
|
||
const _LocationCard();
|
||
|
||
void _openMap(BuildContext context) {
|
||
if (!PlatformCapabilities.baiduMap) {
|
||
PlatformCapabilities.showUnsupported(context);
|
||
return;
|
||
}
|
||
context.push('/map');
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
final l10n = AppLocalizations.of(context);
|
||
final sn = ref.watch(selectedDeviceSnProvider);
|
||
final locationAsync = sn == null
|
||
? const AsyncValue<DeviceLocation?>.data(null)
|
||
: ref.watch(deviceLocationProvider(sn));
|
||
final location = locationAsync.valueOrNull;
|
||
final locating = locationAsync.isLoading;
|
||
final hasAddress = location?.displayAddress.isNotEmpty == true;
|
||
|
||
return GestureDetector(
|
||
onTap: () => _openMap(context),
|
||
child: CardBox(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
// 标题栏:实时位置 + 定位状态,右上角查看详情入口
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: 12),
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
width: 22,
|
||
height: 22,
|
||
decoration: BoxDecoration(
|
||
color: AppColors.green,
|
||
borderRadius: BorderRadius.circular(7),
|
||
),
|
||
child: Center(
|
||
child: Text('📍', style: const TextStyle(fontSize: 13))),
|
||
),
|
||
const SizedBox(width: 7),
|
||
Text(l10n.homeLocation,
|
||
style: TextStyle(
|
||
fontSize: 15,
|
||
fontWeight: FontWeight.w700,
|
||
color: DarkMode.color(context, AppColors.ink))),
|
||
const SizedBox(width: 8),
|
||
// 定位状态:放在"实时位置"标题后面
|
||
Container(
|
||
padding:
|
||
const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||
decoration: BoxDecoration(
|
||
color: locating
|
||
? DarkMode.color(context, AppColors.surface)
|
||
: AppColors.green.withValues(alpha: 0.12),
|
||
borderRadius: BorderRadius.circular(20),
|
||
),
|
||
child: Text(
|
||
locating
|
||
? l10n.homeLocating
|
||
: (hasAddress ? l10n.homeLocated : l10n.homeNoLocation),
|
||
style: TextStyle(
|
||
fontSize: 11,
|
||
fontWeight: FontWeight.w600,
|
||
color: locating
|
||
? DarkMode.color(context, AppColors.sub)
|
||
: (hasAddress ? AppColors.green : DarkMode.color(context, AppColors.sub)),
|
||
),
|
||
),
|
||
),
|
||
const Spacer(),
|
||
// 右上角查看详情
|
||
GestureDetector(
|
||
onTap: () => _openMap(context),
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Text(l10n.homeViewDetail,
|
||
style: const TextStyle(
|
||
fontSize: 12,
|
||
fontWeight: FontWeight.w600,
|
||
color: AppColors.blue)),
|
||
const SizedBox(width: 2),
|
||
const Icon(CupertinoIcons.chevron_right,
|
||
size: 14, color: AppColors.blue),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Stack(
|
||
children: [
|
||
RepaintBoundary(
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(14),
|
||
child: SizedBox(
|
||
width: double.infinity,
|
||
height: 150,
|
||
child: IgnorePointer(
|
||
child: PlatformCapabilities.baiduMap
|
||
? LocationMapView(location: location)
|
||
: const _MapUnavailablePlaceholder(),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
// 地址信息浮层
|
||
Positioned(
|
||
left: 12,
|
||
right: 12,
|
||
bottom: 10,
|
||
child: Container(
|
||
padding:
|
||
const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||
decoration: BoxDecoration(
|
||
color: DarkMode.color(
|
||
context,
|
||
AppColors.card,
|
||
).withValues(alpha: 0.92),
|
||
borderRadius: BorderRadius.circular(10),
|
||
),
|
||
child: Text(
|
||
locating
|
||
? '📍 ${l10n.homeLocating}…'
|
||
: (hasAddress
|
||
? '📍 ${location!.displayAddress}'
|
||
: '📍 ${l10n.homeAddress}'),
|
||
style: TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.ink)),
|
||
maxLines: 2,
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 地图不可用时的占位内容(桌面端百度地图插件无实现)。
|
||
class _MapUnavailablePlaceholder extends StatelessWidget {
|
||
const _MapUnavailablePlaceholder();
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final l10n = AppLocalizations.of(context);
|
||
return ColoredBox(
|
||
color: DarkMode.color(context, AppColors.surface),
|
||
child: Center(
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: Text(
|
||
l10n.featureUnsupported,
|
||
textAlign: TextAlign.center,
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: DarkMode.color(context, AppColors.sub),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 最近截图卡片(独立 ConsumerWidget)。
|
||
///
|
||
/// 自己 `watch` 截图 Provider,截图数据变化时仅重建本卡片,避免连带重建
|
||
/// 整页其它卡片。水平缩略图列表用 `RepaintBoundary` 隔离重绘。
|
||
class _ScreenshotsCard extends ConsumerWidget {
|
||
const _ScreenshotsCard();
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
final l10n = AppLocalizations.of(context);
|
||
final sn = ref.watch(selectedDeviceSnProvider);
|
||
final screenshots = sn == null
|
||
? const AsyncValue<List<ScreenshotVO>>.data([])
|
||
: ref.watch(recentScreenshotsProvider(sn));
|
||
|
||
return CardBox(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
// 标题栏:最近截图 + 查看全部入口
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: 12),
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
width: 22,
|
||
height: 22,
|
||
decoration: BoxDecoration(
|
||
color: AppColors.blue,
|
||
borderRadius: BorderRadius.circular(7),
|
||
),
|
||
child: Center(
|
||
child: Text('🖼️', style: const TextStyle(fontSize: 13))),
|
||
),
|
||
const SizedBox(width: 7),
|
||
Text(l10n.homeScreenshots,
|
||
style: TextStyle(
|
||
fontSize: 15,
|
||
fontWeight: FontWeight.w700,
|
||
color: DarkMode.color(context, AppColors.ink))),
|
||
const Spacer(),
|
||
if (screenshots.valueOrNull?.isNotEmpty ?? false)
|
||
GestureDetector(
|
||
onTap: () => context.push('/screenshots', extra: 0),
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||
child: Text(l10n.homeViewAll,
|
||
style: const TextStyle(
|
||
fontSize: 12,
|
||
fontWeight: FontWeight.w600,
|
||
color: AppColors.green)),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 120,
|
||
child: screenshots.when(
|
||
loading: () =>
|
||
const Center(child: CupertinoActivityIndicator(radius: 12)),
|
||
error: (e, _) => Center(
|
||
child: Text('加载失败',
|
||
style: TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.sub))),
|
||
),
|
||
data: (list) {
|
||
if (list.isEmpty) {
|
||
return Center(
|
||
child: Text(l10n.homeNoScreenshot,
|
||
style:
|
||
TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.sub))),
|
||
);
|
||
}
|
||
// 卡片内容宽 = 屏幕宽 - 外间距(16×2) - 内边距(16×2)。
|
||
// 一排恰好 3 张:减去 2 个间距(10×2) 后均分。
|
||
const gap = 10.0;
|
||
const cardInsets = 16.0 * 2 + 16.0 * 2;
|
||
final itemWidth =
|
||
(MediaQuery.sizeOf(context).width - cardInsets - gap * 2) / 3;
|
||
return RepaintBoundary(
|
||
child: ListView.separated(
|
||
scrollDirection: Axis.horizontal,
|
||
itemCount: list.length,
|
||
separatorBuilder: (_, _) => const SizedBox(width: gap),
|
||
itemBuilder: (_, i) {
|
||
final item = list[i];
|
||
// 统一把原始时间戳格式化为友好显示。
|
||
final time = formatTimeString(item.uploadTime);
|
||
return GestureDetector(
|
||
onTap: () => context.push('/screenshots', extra: i),
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(12),
|
||
child: SizedBox(
|
||
width: itemWidth,
|
||
child: Stack(
|
||
fit: StackFit.expand,
|
||
children: [
|
||
Image(
|
||
image: cachedNetworkImage(item.url ?? ''),
|
||
fit: BoxFit.cover,
|
||
loadingBuilder: (ctx, child, progress) =>
|
||
progress == null
|
||
? child
|
||
: const Center(
|
||
child: CupertinoActivityIndicator(
|
||
radius: 10)),
|
||
errorBuilder: (ctx, err, _) => Container(
|
||
color: DarkMode.tone(context, const Color(0xFFEEF2F7), const Color(0xFF343C49)),
|
||
child: Center(
|
||
child: Icon(CupertinoIcons.photo,
|
||
size: 22, color: DarkMode.color(context, AppColors.sub)),
|
||
),
|
||
),
|
||
),
|
||
Positioned(
|
||
left: 0,
|
||
right: 0,
|
||
bottom: 0,
|
||
child: Container(
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: 6, vertical: 2),
|
||
decoration: BoxDecoration(
|
||
color: CupertinoColors.black
|
||
.withValues(alpha: 0.45),
|
||
borderRadius: const BorderRadius.only(
|
||
bottomLeft: Radius.circular(12),
|
||
bottomRight: Radius.circular(12),
|
||
),
|
||
),
|
||
child: Text(time,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: const TextStyle(
|
||
fontSize: 10,
|
||
color: CupertinoColors.white)),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
);
|
||
},
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|