Flutter:谷歌地图.如何通过这两种标记类型



我正在创建两种标记类型。一个来自Bloc,通过一个消费者,另一个来自我的主课。如何设置标记:同时接受Profmap.markers和set.of(marks.values(?下面的谷歌地图代码:

body: Stack(children: <Widget>[
SizedBox(
width: MediaQuery.of(context)
.size
.width, // or use fixed size like 200
height: MediaQuery.of(context).size.height,
child:
Consumer<ProviderMaps>(builder: (context, Provmap, widget) {
return GoogleMap(
myLocationEnabled: true,
compassEnabled: true,
mapToolbarEnabled: true,
zoomControlsEnabled: true,
zoomGesturesEnabled: true,
onCameraMove: _onCameraMove,
onLongPress: _addMarkerLongPressed,
myLocationButtonEnabled: false,
mapType: maptype,
onTap: Provmap.addMarker,

//                    markers: Provmap.markers,  ///cant pass both... 
markers: Set<Marker>.of(markers.values),

circles: Set<Circle>.of(circles.values),
polylines: Provmap.polyline,
polygons: Provmap.polygon,
initialCameraPosition:
CameraPosition(target: LatLng(lat, lng), zoom: 10.0),
onMapCreated: (GoogleMapController controller) {
mapController = controller;
_controller.complete(controller);
isMapCreated = true;
changeMapMode();
changeMapType();
setState(() {});
Provmap.onCreated;
});
})),

如果markers.values不是Set,则使用toSet()markers.values.toSet()进行设置。并在Set中使用union()

就像markers.values.toSet().union(Provmap.markers)

并且Provmap.markers也应该是Set。因为union()采用Set类型作为It的参数。

最新更新