diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 47df53d..837edf9 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,5 +1,10 @@ -import java.util.Properties +import com.android.build.VariantOutput +import com.android.build.gradle.AbstractAppExtension +import com.android.build.gradle.api.ApkVariantOutput import java.io.FileInputStream +import java.time.LocalDate +import java.time.format.DateTimeFormatter +import java.util.Properties plugins { id("com.android.application") @@ -68,3 +73,23 @@ android { flutter { source = "../.." } + +// 自定义 APK 输出文件名:{应用英文}_{版本号}_{构建日期}_{abi}.apk +// 例:ttstd_family_care_v1.0.0_20261105_arm64-v8a.apk +// 未按 ABI 拆分时 abi 为 universal。 +val appEnglishName = "ttstd_family_care" +val buildDate = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE) + +// AGP 新 Variant API 不提供修改输出文件名的能力,只能走仍可用的旧 API(Flutter 插件自身也依赖它)。 +@Suppress("DEPRECATION") +val legacyAndroidExtension = extensions.getByName("android") as AbstractAppExtension +legacyAndroidExtension.applicationVariants.configureEach { + outputs.forEach { output -> + val apkOutput = output as ApkVariantOutput + val abi = apkOutput.getFilter(VariantOutput.FilterType.ABI) + ?.takeIf { it.isNotEmpty() } + ?: "universal" + apkOutput.outputFileName = + "${appEnglishName}_v${flutter.versionName}_${buildDate}_${abi}.apk" + } +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3de4775..695c3a7 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -42,6 +42,10 @@ android:label="ttstd_family_care" android:name=".AppApplication" android:icon="@mipmap/ic_launcher"> + + + + - 192.168.100.244 + api.ttstd.com diff --git a/android/build/reports/problems/problems-report.html b/android/build/reports/problems/problems-report.html index 1c1eecb..3dae232 100644 --- a/android/build/reports/problems/problems-report.html +++ b/android/build/reports/problems/problems-report.html @@ -225,13 +225,11 @@ template { .header { display: flex; flex-wrap: wrap; - position: fixed; top: 0; left: 0; width: 100%; - padding: 24px 24px 0 24px; + padding-top: 24px; background-color: white; - z-index: 1; } .learn-more { @@ -250,8 +248,6 @@ template { .content { font-size: 0.875rem; - padding: 240px 0 48px; - overflow-x: auto; white-space: nowrap; } @@ -650,12 +646,12 @@ code + .copy-button { diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 08ae915..272c6a3 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -83,7 +83,7 @@ NSExceptionDomains - 192.168.100.244 + api.ttstd.com NSExceptionAllowsInsecureHTTPLoads diff --git a/lib/features/connection/data/connection_providers.dart b/lib/features/connection/data/connection_providers.dart index 57cbd82..27361aa 100644 --- a/lib/features/connection/data/connection_providers.dart +++ b/lib/features/connection/data/connection_providers.dart @@ -9,7 +9,7 @@ import 'signaling_client.dart'; /// /// baseUrl 形如 http://host:port/api/,信令端点固定为 /ws/signal(后端新增)。 String get signalServerUrl { - final base = AppConstants.kBaseUrl; // e.g. http://192.168.100.244:8000/api/ + final base = AppConstants.kBaseUrl; try { final uri = Uri.parse(base); final scheme = uri.scheme == 'https' ? 'wss' : 'ws'; diff --git a/lib/features/home/presentation/home_page.dart b/lib/features/home/presentation/home_page.dart index dabb6ca..58f3ac5 100644 --- a/lib/features/home/presentation/home_page.dart +++ b/lib/features/home/presentation/home_page.dart @@ -19,6 +19,7 @@ class HomePage extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + const tabBarMargin = 20.0; final l10n = AppLocalizations.of(context); final location = GoRouterState.of(context).uri.path; final index = switch (location) { @@ -51,29 +52,32 @@ class HomePage extends ConsumerWidget { alignment: Alignment.bottomCenter, child: SafeArea( top: false, - minimum: const EdgeInsets.only(bottom: 8), - // GlassTabBar 仍读取 Flutter SDK 的 Cupertino 主题。 - // ignore: deprecated_member_use - child: CupertinoUiCompatibilityBridge( - child: GlassTabBar.bottom( - selectedIndex: index, - onTabSelected: (i) => _onTabTap(context, i), - verticalPadding: 0, - iconSize: 26, - tabs: [ - GlassTab( - icon: const Icon(CupertinoIcons.home), - label: l10n.tabHome, - ), - GlassTab( - icon: const Icon(CupertinoIcons.square_grid_2x2), - label: l10n.tabManage, - ), - GlassTab( - icon: const Icon(CupertinoIcons.person), - label: l10n.tabProfile, - ), - ], + child: Padding( + padding: const EdgeInsets.only(bottom: tabBarMargin), + // GlassTabBar 仍读取 Flutter SDK 的 Cupertino 主题。 + // ignore: deprecated_member_use + child: CupertinoUiCompatibilityBridge( + child: GlassTabBar.bottom( + selectedIndex: index, + onTabSelected: (i) => _onTabTap(context, i), + horizontalPadding: tabBarMargin, + verticalPadding: 0, + iconSize: 26, + tabs: [ + GlassTab( + icon: const Icon(CupertinoIcons.home), + label: l10n.tabHome, + ), + GlassTab( + icon: const Icon(CupertinoIcons.square_grid_2x2), + label: l10n.tabManage, + ), + GlassTab( + icon: const Icon(CupertinoIcons.person), + label: l10n.tabProfile, + ), + ], + ), ), ), ), diff --git a/lib/features/home/presentation/home_tab.dart b/lib/features/home/presentation/home_tab.dart index bca1153..d24ea3c 100644 --- a/lib/features/home/presentation/home_tab.dart +++ b/lib/features/home/presentation/home_tab.dart @@ -888,23 +888,22 @@ class _LocationCard extends ConsumerWidget { ), Stack( children: [ - // 百度地图实时位置(须明确宽高,否则地图空白)。 - // RepaintBoundary 隔离原生视图重绘,避免地图刷新污染父层布局。 RepaintBoundary( child: ClipRRect( borderRadius: BorderRadius.circular(14), child: SizedBox( width: double.infinity, height: 150, - child: LocationMapView(location: location), + child: IgnorePointer( + child: LocationMapView(location: location), + ), ), ), ), // 地址信息浮层 - // 右侧留出间隔,避免遮挡地图右侧的放大缩小按钮。 Positioned( left: 12, - right: 52, + right: 12, bottom: 10, child: Container( padding: diff --git a/lib/features/home/presentation/location_map_view.dart b/lib/features/home/presentation/location_map_view.dart index 7cf2f16..d8b6dca 100644 --- a/lib/features/home/presentation/location_map_view.dart +++ b/lib/features/home/presentation/location_map_view.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:typed_data'; import 'dart:ui' as ui; @@ -13,10 +14,10 @@ import '../../../core/utils/coord_util.dart'; import '../../device/domain/device_models.dart'; import '../data/location_controller.dart'; -/// 可复用的嵌入式百度地图视图(用于首页定位卡片等小尺寸地图)。 +/// 首页定位卡片的百度地图预览。 /// /// 根据传入的 [location](WGS84 坐标)将地图中心与标记定位到设备位置; -/// 无有效坐标时保持默认中心(北京)不添加标记。尺寸由父级约束决定。 +/// 地图加载完成后用快照替换原生视图。尺寸由父级约束决定。 class LocationMapView extends ConsumerStatefulWidget { const LocationMapView({super.key, required this.location}); @@ -27,28 +28,25 @@ class LocationMapView extends ConsumerStatefulWidget { } class _LocationMapViewState extends ConsumerState - with WidgetsBindingObserver { + with WidgetsBindingObserver, AutomaticKeepAliveClientMixin { BMFMapController? _mapController; - bool _markerAdded = false; bool _mapReady = false; + Uint8List? _snapshot; + + @override + bool get wantKeepAlive => true; /// 平台视图重建标记:app 从后台恢复后自增,用于强制重建 /// [BMFMapWidget](AndroidView / UiKitView),修复原生地图残留在上层的问题。 int _platformViewGeneration = 0; - /// 首次创建时计算并缓存的初始地图中心,之后固定复用。 - /// - /// ⚠️ 关键性能点:`BMFMapWidget` 的 `mapOptions` 一旦变化会触发原生地图重建。 - /// 若每次 build 都新建 `BMFMapOptions`(对象 `==` 未重写,恒为不相等), - /// 父级卡片下拉刷新导致的 rebuild 就会反复重建原生地图,造成卡顿。 - /// 因此这里只在首次 build 创建一次,中心坐标的更新统一走 - /// [_syncLocation](`setCenterCoordinate`),不再改 mapOptions。 - late final BMFCoordinate _initialCenter; + /// 同一次预览复用选项,避免父级重建时重新创建原生视图。 + late BMFMapOptions _mapOptions; @override void initState() { super.initState(); - _initialCenter = _computeCenter(widget.location); + _mapOptions = _previewOptions(); // 监听 app 生命周期,app 从后台恢复时重建原生地图视图(见 didChangeAppLifecycleState)。 WidgetsBinding.instance.addObserver(this); } @@ -67,7 +65,7 @@ class _LocationMapViewState extends ConsumerState // 切换到桌面(paused)再返回时,百度地图原生 Surface 可能残留在其它 // Flutter 页面之上不消失。恢复前台时通过递增 generation 重建平台视图, // 让原生地图重新挂载到正确层级(每次重建成本可控,仅发生于前后台切换)。 - if (state == AppLifecycleState.resumed) { + if (state == AppLifecycleState.resumed && _snapshot == null) { _recreatePlatformView(); } } @@ -77,16 +75,20 @@ class _LocationMapViewState extends ConsumerState // 复位控制器/标记/就绪状态,等待新视图的 onMapCreated 重新初始化。 _mapController = null; _mapReady = false; - _markerAdded = false; - setState(() => _platformViewGeneration++); + setState(() { + _snapshot = null; + _mapOptions = _previewOptions(); + _platformViewGeneration++; + }); } @override void didUpdateWidget(covariant LocationMapView oldWidget) { super.didUpdateWidget(oldWidget); - // 定位数据变化时刷新标记位置(仅当地图已就绪且数据确实变化)。 - if (oldWidget.location != widget.location) { - _syncLocation(widget.location); + if (_toWgsCoordinate(oldWidget.location) != + _toWgsCoordinate(widget.location) || + oldWidget.location?.sn != widget.location?.sn) { + _recreatePlatformView(); } } @@ -95,14 +97,14 @@ class _LocationMapViewState extends ConsumerState debugPrint('[LocationMapView] onMapCreated, mapController 已就绪'); // 按官方「显示定位」文档:地图加载完成后再执行图层/覆盖物操作, // 否则 addMarker / showUserLocation 等在地图未就绪时调用会不生效。 - controller.setMapDidLoadCallback(callback: () { - if (_mapReady) return; // 幂等保护,避免重复注册导致重复原生调用。 + controller.setMapDidLoadCallback(callback: () async { + if (_mapController != controller || _mapReady) return; _mapReady = true; debugPrint('[LocationMapView] mapDidLoad, 执行图层与标记初始化'); // 1. 初始化定位图层 + 补偿蓝色定位点。 _enableUserLocationLayer(); // 2. 补偿添加设备位置 Marker(地图加载完成后 addMarker 才可靠)。 - _syncLocation(widget.location); + await _capturePreview(controller, widget.location); }); } @@ -149,38 +151,62 @@ class _LocationMapViewState extends ConsumerState controller.updateLocationData(userLocation); } - void _syncLocation(DeviceLocation? location) { - final controller = _mapController; - if (controller == null) return; + Future _capturePreview( + BMFMapController controller, + DeviceLocation? location, + ) async { final coord = _toWgsCoordinate(location); - if (coord == null) return; - - final bd = wgs84ToBd09(coord.lat, coord.lon); - // 关闭动画:避免滚动/下拉刷新期间触发原生地图的动画平移重绘,降低卡顿。 - controller.setCenterCoordinate(bd, false); - if (!_markerAdded) { - // Marker 标题展示设备 SN(缺失时兜底为"设备位置")。 - final sn = location!.sn; - final title = (sn != null && sn.isNotEmpty) ? sn : '设备位置'; - _addDeviceMarker(controller, bd, title); + try { + final rendered = Completer(); + controller.setMapDidFinishedRenderCallback(callback: (success) { + if (success && !rendered.isCompleted) rendered.complete(); + }); + if (coord != null) { + final sn = location!.sn; + final icon = await deviceMarkerIconData( + sn != null && sn.isNotEmpty ? sn : '设备位置', + ); + if (_mapController != controller) return; + if (icon != null) { + await controller.addMarker( + BMFMarker.iconData( + position: wgs84ToBd09(coord.lat, coord.lon), + iconData: icon, + identifier: 'device_location', + ), + ); + } + } + // 地图加载回调早于瓦片和覆盖物完成绘制。等待 SDK 渲染完成再截图。 + await rendered.future.timeout( + const Duration(seconds: 2), + onTimeout: () {}, + ); + if (_mapController != controller) return; + final snapshot = await controller.takeSnapshot().timeout( + const Duration(seconds: 5), + ); + if (_mapController != controller || snapshot == null || snapshot.isEmpty) { + return; + } + // 用普通 Flutter 图片参与列表滚动,释放持续合成的原生地图视图。 + setState(() { + _mapController = null; + _snapshot = snapshot; + }); + } catch (error) { + debugPrint('[LocationMapView] 生成地图预览失败: $error'); } } - Future _addDeviceMarker( - BMFMapController controller, - BMFCoordinate position, - String title, - ) async { - final icon = await deviceMarkerIconData(title); - if (icon == null || _markerAdded) return; // 并发保护,避免重复添加。 - final marker = BMFMarker.iconData( - position: position, - iconData: icon, - identifier: 'device_location', - ); - await controller.addMarker(marker); - _markerAdded = true; - } + BMFMapOptions _previewOptions() => BMFMapOptions( + center: _computeCenter(widget.location), + zoomLevel: 16, + showMapScaleBar: false, + showZoomControl: false, + scrollEnabled: false, + zoomEnabled: false, + ); BMFCoordinate _computeCenter(DeviceLocation? location) { final coord = _toWgsCoordinate(location); @@ -204,6 +230,11 @@ class _LocationMapViewState extends ConsumerState @override Widget build(BuildContext context) { + super.build(context); + final snapshot = _snapshot; + if (snapshot != null) { + return SizedBox.expand(child: Image.memory(snapshot, fit: BoxFit.cover)); + } // 监听本机定位结果:成功后把蓝色定位点更新到地图。 // ⚠️ Riverpod 要求 ref.listen 只能在 build 期间调用,故放在此处。 // 使用 ref.listen 而非 ref.watch:仅建立监听、**不使 build 依赖该状态**, @@ -229,11 +260,7 @@ class _LocationMapViewState extends ConsumerState // 修复地图 Surface 残留在其它页面之上的问题。 key: ValueKey('home_map_$_platformViewGeneration'), onBMFMapCreated: _onMapCreated, - mapOptions: BMFMapOptions( - center: _initialCenter, // 复用首次缓存中心,避免 rebuild 触发地图重建。 - zoomLevel: 16, - showMapScaleBar: false, - ), + mapOptions: _mapOptions, ), ); }