import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:getx_scaffold/getx_scaffold.dart'; import 'controller.dart'; class MapPage extends GetView { const MapPage({super.key}); Widget _buildView() { 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, ), onWebViewCreated: (c) { controller.webViewController = c; }, onLoadStop: (c, url) { // 通知 Controller 页面加载完毕 controller.onWebViewLoadStop(); }, onConsoleMessage: (controller, consoleMessage) { // 方便在 Flutter 控制台看 JS 日志 print("JS Log: ${consoleMessage.message}"); }, ), ], ); } @override Widget build(BuildContext context) { return GetBuilder( init: MapController(), id: 'map', builder: (_) { return _buildView(); }, ); } }