Atreides
Atreides

Reputation: 1

Flutter_map widget returns a black screen when called?

What I'm Trying to Do

I basically want to include an uber-similar user location tracking map in flutter, and I'm using flutter_map for the same.

The Problem

The widget returns a black screen in my app. I've added all necessary parameters and bound conditions, the problem doesn't resolve.

The Code in Question

class MapPage extends StatefulWidget {
const MapPage({super.key});

@override
State<MapPage> createState() => _MapPageState();
}

class _MapPageState extends State<MapPage> {
@override
Widget build(BuildContext context) {
  return FlutterMap(
  mapController: MapController(),
  options: MapOptions(
    center: LatLng(0.0, 0.0),
    zoom: 10,
    maxZoom: 13,
    bounds: LatLngBounds(
      LatLng(51.74920, -0.56741),
      LatLng(51.25709, 0.34018),
    ),
    rotation: 180.0,
  ),
  children: [],
);
}
}

Upvotes: 0

Views: 513

Answers (1)

MANISH DAYMA
MANISH DAYMA

Reputation: 1240

because you are showing a map even if it's not loaded check if the map is loaded if loaded then show the map widget.

here is an example,

return Container(
  height: size.height,
  width: size.width,
  child: Stack(
    children: <Widget>[
      GoogleMap(
        initialCameraPosition: CameraPosition(
          target: LatLng(37.4220, -122.0841),
          zoom: 15,
        ),
        onMapCreated: (GoogleMapController controller) =>
            setState(() => _mapLoading = false),
      ),
      (_mapLoading)
          ? Container(
              height: size.height,
              width: size.width,
              color: Colors.grey[100],
              child: Center(
                child: CircularProgressIndicator(),
              ),
            )
          : Container(),
    ],
  ),
);

Upvotes: -1

Related Questions