Reputation: 338
I don't understand why I'm catching an error in _mapController:
final MapController _mapController = MapController();
@override
void initState() {
super.initState();
_mapController.move(widget.latLng, _mapController.zoom);
}
Upvotes: 0
Views: 542
Reputation: 1
I think the problem arises because you start using the mapcontroller before the build function starts which has the necessary configuration for the map. Try to put this line
_mapController.move(widget.latLng, _mapController.zoom);
inside a method for example (_moveMap) and call it inside the build function when pressing a button.
like this:
child: ElevatedButton(
child:Icon(Icons.location_on_outlined,
color: Colors.blue,) ,
onPressed:_moveMap ,
)),
Upvotes: 0
Reputation: 14865
Try below code
MapController? _mapController;
//or try this-> MapController _mapController;
@override
void initState() {
super.initState();
_mapController.move(widget.latLng, _mapController.zoom);
}
Upvotes: 0
Reputation: 1556
I don't know but try like this ? :
late MapController _mapController;
@override
void initState() {
_mapController = MapController();
_mapController.move(widget.latLng, _mapController.zoom);
super.initState();
}
Upvotes: 1