调整地图样式

This commit is contained in:
2025-11-27 15:25:58 +08:00
parent aa30d13b91
commit da4149ec60
3 changed files with 384 additions and 263 deletions

View File

@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
@@ -10,23 +11,21 @@ class MapPage extends GetView<MapController> {
return Stack(
children: [
InAppWebView(
// 确保 pubspec.yaml 中声明了 assets/html/map.html
initialFile: 'assets/html/map.html',
initialSettings: InAppWebViewSettings(
isInspectable: true,
geolocationEnabled: true,
// 允许 JS 弹窗 (Alert) 用于调试
javaScriptCanOpenWindowsAutomatically: true,
// 既然完全依赖 Flutter 定位,建议把 WebView 的定位彻底关掉,防止 JS 意外触发
geolocationEnabled: false,
javaScriptEnabled: true,
// Android 混合开发推荐配置
useHybridComposition: true, // 提升地图渲染性能(重要)
allowFileAccessFromFileURLs: true, // 允许本地 html 访问本地资源
allowUniversalAccessFromFileURLs: true,
),
onWebViewCreated: (c) {
controller.webViewController = c;
},
onLoadStop: (c, url) {
// 通知 Controller 页面加载完毕
controller.onWebViewLoadStop();
},
// 当 WebView 创建完成后,将 controller 实例传递给我们的 MapController
onWebViewCreated: controller.onWebViewCreated,
onConsoleMessage: (controller, consoleMessage) {
// 方便在 Flutter 控制台 JS 日志
// 方便在 Flutter 控制台查看来自 JS 日志
print("JS Log: ${consoleMessage.message}");
},
),