我正在开发一个使用GoogleMaps的地图应用程序,但我在显示地图的页面上遇到了问题。尝试使用MapView给了我错误";项目类型'MapView<动态,动态>'无法分配给列表类型"Widget"如果有人能告诉我如何解决这个问题,我将不胜感激。谢谢
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<LocationBloc, LocationState>(
builder: (context, locationState) {
if (locationState.lastKnownLocation == null) {
return const Center(child: Text('Espere por favor...'));
}
return BlocBuilder<MapBloc, MapState>(
builder: (context, mapState) {
Map<String, Polyline> polylines = Map.from( mapState.polylines );
if ( !mapState.showMyRoute ) {
polylines.removeWhere((key, value) => key == 'myRoute');
}
return SingleChildScrollView(
child: Stack(
children: [
MapView(
initialLocation: locationState.lastKnownLocation!,
polylines: polylines.values.toSet(),
markers: mapState.markers.values.toSet(),
),
SearchBar(),
const ManualMarker(),
],
),
);
},
);
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: const [
BtnToggleUserRoute(),
BtnFollowUser(),
BtnCurrentLocation(),
],
),
);
}
}
您定义了一个名为map view的类,它采用initialLocation、折线和市场,但我相信它不会返回GoogleMaps类型的Widget。。试试这个
const LatLng _center = LatLng(32.080664, 34.9563837);
//Then use this in widget tree,
Center(
child: SizedBox(
width: 300.0,
height: 300.0,
child: GoogleMap(
initialCameraPosition: const CameraPosition(target: _center,
zoom: 11.0,
),
gestureRecognizers: //
<Factory<OneSequenceGestureRecognizer>>{
Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(),
),
},
),
),
),