2 years ago

#25326

test-img

Apostolos

Not a constant expression onMapCreated

new to flutter and dart here. I've been experimenting with dart/flutter and google maps. I have tried to follow the example described here to use google maps widget. My code is the following:

class _ParkingMapState extends State<ParkingMap> {
  Completer<GoogleMapController> _controller = Completer();
  static const _initialCameraPosition = CameraPosition(
      target: LatLng(40.10548077666605, 22.501827754541637),
      zoom: 11.5
  );

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: GoogleMap(
        initialCameraPosition: _initialCameraPosition,
        onMapCreated: (ctrl)  {
          _controller.complete(ctrl);
        },
        mapType: MapType.hybrid,
        myLocationButtonEnabled: false,
        zoomControlsEnabled: false,

      )
    );
  }
}

but it gives me the following error:

lib/map.dart:29:11: Error: Not a constant expression.
          _controller.complete(ctrl);
          ^^^^^^^^^^^
lib/map.dart:29:32: Error: Not a constant expression.
          _controller.complete(ctrl);
                               ^^^^
lib/map.dart:29:23: Error: Method invocation is not a constant expression.
          _controller.complete(ctrl);
                      ^^^^^^^^
lib/map.dart:28:23: Error: Not a constant expression.
        onMapCreated: (ctrl)  {
                      ^^^^^^

I cannot understand what I am doing wrong. Any ideas/help would be usefull!

flutter

dart

google-maps-flutter

0 Answers

Your Answer

Accepted video resources