Skip to content
This repository was archived by the owner on Jul 11, 2021. It is now read-only.
This repository was archived by the owner on Jul 11, 2021. It is now read-only.

[ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: NoSuchMethodError: The getter 'zoom' was called on null. #85

@Drkstr

Description

@Drkstr

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. (package:user_location/src/user_location_layer.dart:255:9)
E/flutter (12323): #4 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (12323): #5 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (12323): #6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (12323): #7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (12323): #8 _DelayedData.perform (dart:async/stream_impl.dart:611:14)
E/flutter (12323): #9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:730:11)
E/flutter (12323): #10 _PendingEvents.schedule. (dart:async/stream_impl.dart:687:7)
E/flutter (12323): #11 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (12323): #12 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (12323): #13 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (12323): #14 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)
E/flutter (12323): #15 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (12323): #16 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (12323): #17 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (12323): #18 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)
E/flutter (12323): #19 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (12323): #20 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions