[ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: NoSuchMethodError: The getter 'zoom' was called on null.
Describe the bug I have a button to toggle the user's location on and off. I get the following error when I try to toggle on the users' location. Everything works fine till I toggle the users' location
[ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: NoSuchMethodError: The getter 'zoom' was called on null.
This is the stack trace
Receiver: null
E/flutter (12323): Tried calling: zoom
E/flutter (12323): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (12323): #1 MapControllerImpl.zoom (package:flutter_map/src/map/map.dart:50:29)
E/flutter (12323): #2 _MapsPluginLayerState.forceMapUpdate (package:user_location/src/user_location_layer.dart:363:45)
E/flutter (12323): #3 _MapsPluginLayerState._handleCompassDirection.
To Reproduce Here is my flutter_map widget
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:smart_paddock/utils/string_utils.dart';
import 'package:smart_paddock/utils/style_utils.dart';
import 'package:user_location/user_location.dart';
Widget map(List<Marker> markers, List<LatLng> boundary, bool userLocationEnabled,
LatLng userLocation, BuildContext context) {
MapOptions mapOptions;
MapController mapController = MapController();
// if we have user location enables, create and instance of the user location. <- added to layers in towards the end of this file
// or if we only have a single tag selected, center the map on the tag
// else, bound the map to the property boundary
UserLocationOptions userLocationOptions;
if(userLocationEnabled){
userLocationOptions = UserLocationOptions(
context: context,
mapController: mapController,
markers: markers,
showMoveToCurrentLocationFloatingActionButton: false
);
mapOptions = MapOptions(
plugins: [
UserLocationPlugin(),
],
center: markers.first.point,
zoom: 17
);
}else if(markers.length == 1){
mapOptions = MapOptions(
center: markers.first.point,
zoom: 17
);
}
else{
mapOptions = MapOptions(
bounds: LatLngBounds.fromPoints(boundary),
boundsOptions: FitBoundsOptions(
padding: EdgeInsets.only(top: 128)
)
);
}
List<LayerOptions> layers = [];
// add the map tiles
layers.add(TileLayerOptions(
urlTemplate: "https://api.mapbox.com/styles/v1/$MAPBOX_STYLE/tiles/{z}/{x}/{y}?access_token=$MAIN_TOKEN",
additionalOptions: {
'accessToken': MAIN_TOKEN,
'id': 'mapbox/satellite-v9'
},
));
// add the boundary
layers.add(PolygonLayerOptions(
polygons: [
Polygon(
points: boundary,
color: Colors.transparent,
borderColor: DARK_ORANGE,
borderStrokeWidth: 2,
)
]
),);
// add the tag markers
layers.add(MarkerLayerOptions(
markers: markers,
),);
// if the user location in enables, add the user location via the UserLocationPlugin
if(userLocationEnabled){
layers.add(userLocationOptions);
}
return new FlutterMap(
options: mapOptions,
layers: layers,
mapController: mapController,
);
}
Expected behaviour Expected to see the users location on the map. And the map moving to keep the user in the centre of the screen.
Additional context Testing on Android version 10
flutter_map: 0.10.1+1
user_location:
git:
url: https://github.com/igaurab/user_location_plugin.git