0

I am working on a map application, which uses GoogleMaps, but I am having problems on the page that should display the map. Trying to use the MapView gives me the error "Item type 'MapView<dynamic, dynamic>' cannot be assigned to list type 'Widget'." I appreciate if someone can tell me how to fix this. Thank you

@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(),
        ],
      ),
    );
  }
}
Eve
  • 37
  • 5

1 Answers1

1

You defined a class named map view that takes initialLocation, polylines and markets but I believe its not returning a Widget of type GoogleMaps.. Try this

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(),
                        ),
                      },
                    ),
                  ),
                ),

Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30