提交 07d6f75c authored 作者: 史晓晨's avatar 史晓晨

feat:调试兼容web导航

上级 9de934db
import 'dart:html';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'navigation_page.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: TextButton(
onPressed: () {
if (kIsWeb) {
window.open(
"https:////uri.amap.com/navigation?from=116.478346,39.997361&to=116.3246,39.966577",
'_blank');
} else {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => const NavigationPage()));
}
},
child: const Text("开始导航"),
),
),
);
}
}
import 'package:clx_map_navigation_example/map_config.dart';
import 'package:flutter/material.dart';
import 'package:clx_map_navigation/amap_navigation_widget.dart';
import 'home_page.dart';
void main() {
runApp(const MyApp());
......@@ -8,35 +8,19 @@ void main() {
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const AMapNavigationWidget(
apiKey: AMapConfig.aMapApiKeys,
// startPoint: { "latitude": 39.993135, "longitude": 116.474175 },
// endPoint: { "latitude": 39.908791, "longitude": 116.321257 },
startPoint: { "latitude": 37.820494, "longitude": 112.586248 },
endPoint: { "latitude": 39.911328, "longitude": 116.152583 },
onMapClosed: AMapConfig.onMapClosed,
),
),
);
Widget build(BuildContext _) {
return const MaterialApp(home: HomePage());
}
}
import 'package:clx_map_navigation/amap_navigation_widget.dart';
import 'package:flutter/material.dart';
import 'map_config.dart';
class NavigationPage extends StatelessWidget {
const NavigationPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const AMapNavigationWidget(
apiKey: AMapConfig.aMapApiKeys,
// startPoint: { "latitude": 39.993135, "longitude": 116.474175 },
// endPoint: { "latitude": 39.908791, "longitude": 116.321257 },
startPoint: { "latitude": 37.820494, "longitude": 112.586248 },
endPoint: { "latitude": 39.911328, "longitude": 116.152583 },
onMapClosed: AMapConfig.onMapClosed,
),
);
}
}
......@@ -5,6 +5,7 @@ packages:
dependency: "direct main"
description:
name: amap_flutter_base
sha256: "9ef2439b8de7100cdd1b4357701b8ca8c059c0f2d9d0257b81750bbf0c6f53bb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.0"
......@@ -12,27 +13,31 @@ packages:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.9.0"
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.1"
version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
......@@ -47,20 +52,23 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.16.0"
version: "1.18.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
version: "1.0.8"
fake_async:
dependency: transitive
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
......@@ -73,56 +81,92 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
version: "2.0.3"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.flutter-io.cn"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
version: "2.1.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.12"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.5"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0"
version: "1.11.0"
path:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.2"
version: "1.9.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.3"
version: "2.1.8"
sky_engine:
dependency: transitive
description: flutter
......@@ -132,41 +176,47 @@ packages:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.0"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
version: "2.1.2"
stream_transform:
dependency: transitive
description:
name: stream_transform
sha256: ad47125e588cfd37a9a7f86c7d6356dde8dfe89d071d293f80ca9e9273a33871
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.1"
......@@ -174,16 +224,26 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.12"
version: "0.6.1"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.flutter-io.cn"
source: hosted
version: "13.0.0"
sdks:
dart: ">=2.17.6 <3.0.0"
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=2.5.0"
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="Demonstrates how to use the test_web_plugin plugin.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="test_web_plugin_example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>test_web_plugin_example</title>
<link rel="manifest" href="manifest.json">
<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
<script src="https://webapi.amap.com/loader.js"></script>
</head>
<body>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});
}
});
});
</script>
</body>
</html>
{
"name": "test_web_plugin_example",
"short_name": "test_web_plugin_example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "Demonstrates how to use the test_web_plugin plugin.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}
import 'dart:async';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:clx_map_navigation/core/amap_navigation_util.dart';
import 'package:clx_map_navigation/core/map_event.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:flutter/services.dart';
import 'core/map_navigation_controller.dart';
import 'core/map_navigation_method_channel.dart';
import 'core/map_navigation_platform_interface.dart';
final MethodChannelMapNavigation _methodChannel = MapNavigationPlatform.instance as MethodChannelMapNavigation;
final MethodChannelMapNavigation _methodChannel =
MapNavigationPlatform.instance as MethodChannelMapNavigation;
typedef MapClosedCallback = void Function();
typedef NavCreatedCallback = void Function(MapNavigationController controller);
class AMapNavigationWidget extends StatefulWidget {
/// 高德开放平台的key
final AMapApiKey? apiKey;
/// 起点
final Map? startPoint;
/// 终点
final Map? endPoint;
/// 需要应用到地图上的手势集合
final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers;
/// 导航地图底部退出的回调
final MapClosedCallback? onMapClosed;
......@@ -46,10 +52,10 @@ class AMapNavigationWidget extends StatefulWidget {
}
class _MapNavigationState extends State<AMapNavigationWidget> {
//消息订阅对象
late StreamSubscription _streamSubscription;
final Completer<MapNavigationController> _controller = Completer<MapNavigationController>();
final Completer<MapNavigationController> _controller =
Completer<MapNavigationController>();
@override
void initState() {
......@@ -59,7 +65,9 @@ class _MapNavigationState extends State<AMapNavigationWidget> {
}
_setupChannelsConfig() {
_methodChannel.channel().setMethodCallHandler((call) => _handleMethodCall(call));
_methodChannel
.channel()
.setMethodCallHandler((call) => _handleMethodCall(call));
}
// 监听
......@@ -67,7 +75,9 @@ class _MapNavigationState extends State<AMapNavigationWidget> {
debugPrint("---_connectStreams---");
if (widget.onMapClosed != null) {
debugPrint("------ _connectStreams listen ----- ");
_streamSubscription = _methodChannel.onMapClosed().listen((MapClosedEvent e) => widget.onMapClosed!());
_streamSubscription = _methodChannel
.onMapClosed()
.listen((MapClosedEvent e) => widget.onMapClosed!());
}
}
......@@ -85,7 +95,7 @@ class _MapNavigationState extends State<AMapNavigationWidget> {
@override
Widget build(BuildContext context) {
AMapNavigationUtil.init(context);
final Map<String, dynamic> creationParams = <String, dynamic> {
final Map<String, dynamic> creationParams = <String, dynamic>{
'apiKey': widget.apiKey?.toMap(),
'startPoint': widget.startPoint,
'endPoint': widget.endPoint,
......@@ -117,5 +127,4 @@ class _MapNavigationState extends State<AMapNavigationWidget> {
//取消监听
_streamSubscription.cancel();
}
}
import 'dart:io';
import 'package:flutter/foundation.dart';
/// 平台信息
class PlatformUtils {
static bool _isWeb() {
return kIsWeb == true;
}
static bool _isAndroid() {
return _isWeb() ? false : Platform.isAndroid;
}
static bool _isIOS() {
return _isWeb() ? false : Platform.isIOS;
}
static bool get isWeb => _isWeb();
static bool get isAndroid => _isAndroid();
static bool get isIOS => _isIOS();
}
......@@ -10,6 +10,8 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
plugin_platform_interface: ^2.0.2
amap_flutter_base: ^3.0.0
stream_transform: ^2.0.0
......
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart';
void main() {
MethodChannelClxMapNavigation platform = MethodChannelClxMapNavigation();
const MethodChannel channel = MethodChannel('clx_map_navigation');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});
tearDown(() {
channel.setMockMethodCallHandler(null);
});
test('getPlatformVersion', () async {
expect(await platform.getPlatformVersion(), '42');
});
}
// import 'package:flutter/services.dart';
// import 'package:flutter_test/flutter_test.dart';
// import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart';
//
// void main() {
// MethodChannelClxMapNavigation platform = MethodChannelClxMapNavigation();
// const MethodChannel channel = MethodChannel('clx_map_navigation');
//
// TestWidgetsFlutterBinding.ensureInitialized();
//
// setUp(() {
// channel.setMockMethodCallHandler((MethodCall methodCall) async {
// return '42';
// });
// });
//
// tearDown(() {
// channel.setMockMethodCallHandler(null);
// });
//
// test('getPlatformVersion', () async {
// expect(await platform.getPlatformVersion(), '42');
// });
// }
import 'package:flutter_test/flutter_test.dart';
// import 'package:flutter_test/flutter_test.dart';
// import 'package:clx_map_navigation/core/clx_map_navigation.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_platform_interface.dart';
import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
// import 'package:clx_map_navigation/core/clx_map_navigation_platform_interface.dart';
// import 'package:clx_map_navigation/core/clx_map_navigation_method_channel.dart';
// import 'package:plugin_platform_interface/plugin_platform_interface.dart';
// class MockClxMapNavigationPlatform with MockPlatformInterfaceMixin implements ClxMapNavigationPlatform {
//
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论