Reputation: 519
When i try to assign set of markers to markers argument in GoogleMap it gives me this error...
The argument type 'Set?' can't be assigned to the parameter type 'Set'.
Code Sample
body: GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(
widget.initialLocation!.latitude!,
widget.initialLocation!.longitude!,
),
zoom: 16,
),
onTap: widget.isSelecting! ? _selectLocation : null,
markers: _pickedLocation == null
? null
: {
Marker(
markerId: MarkerId('m1'),
position: _pickedLocation!,
),
},
),
Upvotes: 1
Views: 2236
Reputation: 1
Try to set the marker value this way
markers: _pickedLocation == null
? <Marker>[].toSet()
: [
Marker(
markerId: MarkerId('m1'),
position: _pickedLocation!,
),
].toSet(),
Upvotes: 0
Reputation: 380
You can return an empty set which will satisfy the non-null requirement of the markers: property
markers: (_pickedLocation == null && !widget.isSelecting)
? {}
: [
Marker(
markerId: MarkerId('m1'),
position: _pickedLocation ??
LatLng(
widget.initialLocation.latitude!,
widget.initialLocation.longitude!,
),
),
].toSet(),
Upvotes: 0
Reputation: 51
markers: (_pickedLocation == null && !widget.isSelecting)
? <Marker>[].toSet()
: [
Marker(
markerId: MarkerId('m1'),
position: _pickedLocation ??
LatLng(
widget.initialLocation.latitude!,
widget.initialLocation.longitude!,
),
),
].toSet(),
Upvotes: 3