接入高清场站地图
This commit is contained in:
82
lib/features/home/presentation/pages/dj_page.dart
Normal file
82
lib/features/home/presentation/pages/dj_page.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class DjPage extends StatefulWidget {
|
||||
const DjPage({super.key});
|
||||
|
||||
@override
|
||||
State<DjPage> createState() => _DjPageState();
|
||||
}
|
||||
|
||||
class _DjPageState extends State<DjPage> {
|
||||
late final WebViewController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final url = "https://pvs.satabot.com/?platform=flutter&t=${DateTime.now().millisecondsSinceEpoch}";
|
||||
|
||||
controller = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
// 监听 H5 消息
|
||||
..addJavaScriptChannel(
|
||||
'MapChannel',
|
||||
onMessageReceived: (JavaScriptMessage message) {
|
||||
_handleJsMessage(message.message);
|
||||
},
|
||||
)
|
||||
// 加载网页
|
||||
..loadRequest(Uri.parse(url));
|
||||
}
|
||||
|
||||
/// 处理 H5 返回的数据
|
||||
void _handleJsMessage(String msg) {
|
||||
debugPrint("H5消息: $msg");
|
||||
|
||||
try {
|
||||
final data = jsonDecode(msg);
|
||||
|
||||
final action = data["action"];
|
||||
final page = data["page"];
|
||||
|
||||
if (action == "navigate") {
|
||||
if (page == "gaode") {
|
||||
_openGaode();
|
||||
}
|
||||
|
||||
if (page == "StatusFragment") {
|
||||
context.go(RoutePaths.routePlan);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("解析H5消息失败: $e");
|
||||
}
|
||||
}
|
||||
|
||||
/// 打开高德地图页面
|
||||
void _openGaode() {
|
||||
context.go(RoutePaths.routePlan);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () {
|
||||
context.go(RoutePaths.home);
|
||||
},
|
||||
),
|
||||
title: const Text("路径规划", style: TextStyle(color: Colors.white)),
|
||||
backgroundColor: const Color(0xFF1677FF),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: WebViewWidget(controller: controller),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -961,9 +961,6 @@ class _RunningStatusPageState extends State<RunningStatusPage> {
|
||||
),
|
||||
// 新增:AppBar底部阴影优化
|
||||
shadowColor: Colors.black12,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(12), bottomRight: Radius.circular(12)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user