|
|
@ -1,7 +1,9 @@ |
|
|
|
|
|
import 'dart:async'; |
|
|
import 'dart:convert'; |
|
|
import 'dart:convert'; |
|
|
import 'dart:math'; |
|
|
import 'dart:math'; |
|
|
import 'dart:math' as math; |
|
|
import 'dart:math' as math; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:amap_flutter/amap_flutter.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:http/http.dart' as http; |
|
|
import 'package:http/http.dart' as http; |
|
|
|
|
|
|
|
|
@ -20,12 +22,41 @@ class _ChatNavigationCardState extends State<ChatNavigationCard> { |
|
|
LatLng startPoint = LatLng(116.397428, 39.90923); // 起点坐标 |
|
|
LatLng startPoint = LatLng(116.397428, 39.90923); // 起点坐标 |
|
|
LatLng endPoint = LatLng(116.397026, 39.903303); // 终点坐标 |
|
|
LatLng endPoint = LatLng(116.397026, 39.903303); // 终点坐标 |
|
|
|
|
|
|
|
|
late Future _mapUrl; |
|
|
final _amapFlutter = AmapFlutter(); |
|
|
|
|
|
StreamSubscription? _locationStream; |
|
|
|
|
|
|
|
|
|
|
|
String _mapUrl = ''; |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
void initState() { |
|
|
void initState() { |
|
|
super.initState(); |
|
|
super.initState(); |
|
|
_mapUrl = _getMapUrl(); |
|
|
_getLocation(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
void dispose() { |
|
|
|
|
|
_amapFlutter.dispose(); |
|
|
|
|
|
_locationStream?.cancel(); |
|
|
|
|
|
super.dispose(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _getLocation() async { |
|
|
|
|
|
List endPointList = widget.data?['navigationcard']['location'].split(','); |
|
|
|
|
|
endPoint = LatLng( |
|
|
|
|
|
double.parse(endPointList[0]), |
|
|
|
|
|
double.parse(endPointList[1]), |
|
|
|
|
|
); |
|
|
|
|
|
await _amapFlutter.initLocation(); |
|
|
|
|
|
_locationStream = _amapFlutter.locationStream().listen((data) async { |
|
|
|
|
|
startPoint = LatLng( |
|
|
|
|
|
data['longitude'], |
|
|
|
|
|
data['latitude'], |
|
|
|
|
|
); |
|
|
|
|
|
_mapUrl = await _getMapUrl(); |
|
|
|
|
|
_amapFlutter.stopLocation(); |
|
|
|
|
|
setState(() {}); |
|
|
|
|
|
}); |
|
|
|
|
|
_amapFlutter.startLocation(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<String> _getMapUrl() async { |
|
|
Future<String> _getMapUrl() async { |
|
|
@ -159,15 +190,9 @@ class _ChatNavigationCardState extends State<ChatNavigationCard> { |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
return Column( |
|
|
return Column( |
|
|
children: [ |
|
|
children: [ |
|
|
FutureBuilder( |
|
|
_mapUrl.isNotEmpty |
|
|
future: _mapUrl, |
|
|
? Image.network(_mapUrl) |
|
|
builder: (BuildContext context, AsyncSnapshot snapshot) { |
|
|
: const CircularProgressIndicator(), |
|
|
if (snapshot.hasData) { |
|
|
|
|
|
return Image.network(snapshot.data); |
|
|
|
|
|
} |
|
|
|
|
|
return const CircularProgressIndicator(); |
|
|
|
|
|
}, |
|
|
|
|
|
), |
|
|
|
|
|
], |
|
|
], |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|