当在MapOptions-> Center中使用地图时,当输入lat和液化天然气时,参数类型'LatLng‘不能分配给参数类型'LatLng?’。
class MapsView extends HookConsumerWidget {
MapsView({Key? key}) : super(key: key);
final MapController _mapController=MapController();
@override
Widget build(BuildContext context, WidgetRef ref) {
return FlutterMap(
options: MapOptions(
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
),
layers: [
TileLayerOptions(
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
userAgentPackageName: 'com.example.app',
),
],
nonRotatedChildren: [
AttributionWidget.defaultWidget(
source: 'OpenStreetMap contributors',
onSourceTapped: null,
),
],
);
}
}

发布于 2022-08-13 05:41:20
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
class MapsView extends HookConsumerWidget {
MapsView({Key? key}) : super(key: key);
final MapController _mapController=MapController();
@override
Widget build(BuildContext context, WidgetRef ref) {
return FlutterMap(
options: MapOptions(
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
),
layers: [
TileLayerOptions(
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
userAgentPackageName: 'com.example.app',
),
],
nonRotatedChildren: [
AttributionWidget.defaultWidget(
source: 'OpenStreetMap contributors',
onSourceTapped: null,
),
],
);
}
}'package:latlong2/latlong.dart导入
在包中没有导出,所以您必须手动导入它才能在其中赋值。

发布于 2022-08-13 05:41:54
我认为你不需要使用latLng2
依赖关系: latlong2:^0.8.0
import 'package:latlong2/latlong.dart' as latLng;
FlutterMap(
options: MapOptions(
center: latLng.LatLng(51.509364, -0.128928),
zoom: 9.2,
),https://stackoverflow.com/questions/73341777
复制相似问题