Files
ttstd_family_care/lib/app/router/app_router.dart
T
tongtong 5f84a64c3e feat(platform): 添加桌面端平台能力降级适配
- 新增 PlatformCapabilities 平台能力判断类,统一检测移动端原生插件可用性
- 地图、定位、扫码、相册、拨号、通话录制等入口在桌面端降级为提示
- 系统 UI 配置与 moveTaskToBack 在桌面端跳过,避免插件异常
- 设备信息工具新增 Windows 平台支持,返回 computerName
- 百度地图 SDK 初始化增加平台判断,桌面端不再调用
- 新增个人资料编辑页面及路由,从「我的」页头部入口跳转
- 国际化添加 featureUnsupported 提示文案
2026-11-07 17:06:32 +08:00

238 lines
8.8 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../core/storage/token_storage.dart';
import '../../features/auth/presentation/login_page.dart';
import '../../features/auth/presentation/register_page.dart';
import '../../features/auth/presentation/forgot_password_page.dart';
import '../../features/auth/presentation/legal_document_page.dart';
import '../../features/auth/presentation/splash_page.dart';
import '../../features/home/presentation/home_page.dart';
import '../../features/home/presentation/home_tab_pager.dart';
import '../../features/home/presentation/home_tab.dart';
import '../../features/home/presentation/map_page.dart';
import '../../features/home/presentation/screenshot_page.dart';
import '../../features/home/presentation/system_settings_page.dart';
import '../../features/home/presentation/wallpaper_page.dart';
import '../../features/messages/presentation/messages_tab.dart';
import '../../features/profile/presentation/profile_tab.dart';
import '../../features/profile/presentation/profile_edit_page.dart';
import '../../features/album/presentation/album_page.dart';
import '../../features/alarm/presentation/alarm_page.dart';
import '../../features/alarm/presentation/alarm_edit_page.dart';
import '../../features/alarm/domain/alarm_models.dart';
import '../../features/contacts/presentation/contacts_page.dart';
import '../../features/contacts/presentation/contact_edit_page.dart';
import '../../features/contacts/domain/contact_models.dart';
import '../../features/apps/presentation/apps_page.dart';
import '../../features/account/presentation/change_mobile_page.dart';
import '../../features/account/presentation/change_password_page.dart';
import '../../features/account/presentation/login_devices_page.dart';
import '../../features/account/presentation/security_page.dart';
import '../../features/account/presentation/wechat_binding_page.dart';
import '../../features/device/data/device_providers.dart';
import '../../features/device/domain/device_models.dart';
import '../../features/device/presentation/device_bind_page.dart';
import '../../features/device/presentation/device_manage_page.dart';
import '../../features/device/presentation/device_scan_page.dart';
import '../../features/connection/presentation/remote_control_page.dart';
/// 应用路由定义(GoRouter)。
///
/// - /splash 启动页,依据登录态决定首跳
/// - /login /register 认证流程
/// - /home Shell 路由,承载底部 Tab(首页 / 管理 / 我的)
/// - /album /alarm /contacts /apps 管理页横版菜单进入的子页面(无底部 Tab)
/// - /device/manage /device/bind /device/scan 设备管理、绑定与扫码
/// - /security/* 账号与安全(登录设备 / 修改密码 / 更换手机 / 微信绑定)
GoRouter buildAppRouter() {
return GoRouter(
initialLocation: '/splash',
refreshListenable: TokenStorage.sessionChanges,
redirect: (context, state) {
const publicPaths = {
'/splash',
'/login',
'/register',
'/forgot-password',
'/legal',
};
final path = state.uri.path;
if (!TokenStorage.isLoggedIn && !publicPaths.contains(path)) {
return '/login';
}
if (TokenStorage.isLoggedIn && {'/login', '/register'}.contains(path)) {
return '/home';
}
return null;
},
routes: [
GoRoute(path: '/splash', builder: (context, state) => const SplashPage()),
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
GoRoute(
path: '/register',
builder: (context, state) => const RegisterPage(),
),
GoRoute(
path: '/forgot-password',
builder: (context, state) => const ForgotPasswordPage(),
),
GoRoute(
path: '/legal',
builder: (context, state) => LegalDocumentPage.fromExtra(state.extra),
),
GoRoute(path: '/album', builder: (context, state) => const AlbumPage()),
GoRoute(path: '/alarm', builder: (context, state) => const AlarmPage()),
GoRoute(
path: '/alarm/edit',
builder: (context, state) => AlarmEditPage(
alarm: state.extra is AlarmModel ? state.extra as AlarmModel : null,
),
),
GoRoute(
path: '/contacts',
builder: (context, state) => const ContactsPage(),
),
GoRoute(
path: '/contacts/edit',
builder: (context, state) => ContactEditPage(
contact: state.extra is Contact ? state.extra as Contact : null,
),
),
GoRoute(path: '/apps', builder: (context, state) => const AppsPage()),
GoRoute(
path: '/device/manage',
builder: (context, state) => const DeviceManagePage(),
),
GoRoute(
path: '/device/bind',
builder: (context, state) => DeviceBindPage(
initialSn: state.extra is String ? state.extra as String : null,
),
),
GoRoute(
path: '/device/scan',
builder: (context, state) => const DeviceScanPage(),
),
GoRoute(path: '/profile/edit', builder: (context, state) => const ProfileEditPage()),
GoRoute(
path: '/security',
builder: (context, state) => const SecurityPage(),
),
GoRoute(
path: '/security/login-devices',
builder: (context, state) => const LoginDevicesPage(),
),
GoRoute(
path: '/security/password',
builder: (context, state) => const ChangePasswordPage(),
),
GoRoute(
path: '/security/mobile',
builder: (context, state) => ChangeMobilePage(
currentMobile: state.extra is String ? state.extra as String : null,
),
),
GoRoute(
path: '/security/wechat',
builder: (context, state) => const WechatBindingPage(),
),
GoRoute(path: '/map', builder: (context, state) => _MapRoute()),
GoRoute(
path: '/screenshots',
builder: (context, state) => _ScreenshotsRoute(
initialIndex: (state.extra is int) ? state.extra as int : 0,
),
),
GoRoute(
path: '/connection',
builder: (context, state) => _RemoteControlRoute(),
),
GoRoute(
path: '/settings',
builder: (context, state) => const SystemSettingsPage(),
),
GoRoute(
path: '/wallpaper',
builder: (context, state) => const WallpaperPage(),
),
StatefulShellRoute(
builder: (context, state, shell) => HomePage(navigationShell: shell),
navigatorContainerBuilder: (context, shell, children) =>
HomeTabPager(navigationShell: shell, children: children),
branches: [
StatefulShellBranch(
preload: true,
routes: [
GoRoute(
path: '/home',
builder: (context, state) => const HomeTab(),
),
],
),
StatefulShellBranch(
preload: true,
routes: [
GoRoute(
path: '/messages',
builder: (context, state) => const MessagesTab(),
),
],
),
StatefulShellBranch(
preload: true,
routes: [
GoRoute(
path: '/profile',
builder: (context, state) => const ProfileTab(),
),
],
),
],
),
],
);
}
/// /map 路由包装:从全局选中的设备 SN 读取后渲染地图。
class _MapRoute extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final sn = ref.watch(selectedDeviceSnProvider) ?? '';
return MapPage(sn: sn);
}
}
/// /screenshots 路由包装:从全局选中的设备 SN 读取最近截图列表,
/// 定位到传入的初始索引后渲染截图查看页。
class _ScreenshotsRoute extends ConsumerWidget {
const _ScreenshotsRoute({required this.initialIndex});
final int initialIndex;
@override
Widget build(BuildContext context, WidgetRef ref) {
final sn = ref.watch(selectedDeviceSnProvider);
final screenshotsAsync = sn == null
? const AsyncValue<List<ScreenshotVO>>.data([])
: ref.watch(recentScreenshotsProvider(sn));
final list = screenshotsAsync.valueOrNull ?? const <ScreenshotVO>[];
// 越界保护:初始索引落在列表内,否则回退到 0。
final index = (list.isNotEmpty && initialIndex < list.length)
? initialIndex
: 0;
return ScreenshotPage(screenshots: list, sn: sn ?? '', initialIndex: index);
}
}
/// /connection 路由包装:从全局选中的设备 SN 读取后渲染远程控制页。
class _RemoteControlRoute extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final sn = ref.watch(selectedDeviceSnProvider) ?? '';
return RemoteControlPage(sn: sn);
}
}