Flutter_map: The method 'move' was called on null.

Created on 20 Jun 2019  ยท  14Comments  ยท  Source: fleaflet/flutter_map

Here is the stacktrace :

โ•โ•โ•ก EXCEPTION CAUGHT BY WIDGETS LIBRARY โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
The following NoSuchMethodError was thrown building StreamBuilder<LatLng>(dirty, state:
_StreamBuilderBaseState<LatLng, AsyncSnapshot<LatLng>>#d59a1):
The method 'move' was called on null.
Receiver: null
Tried calling: move(Instance of 'LatLng', 18.0, hasGesture: false, isUserGesture: false)
When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
#1      MapControllerImpl.move (package:flutter_map/src/map/map.dart:28:12)
#2      SelfUpdatingMap.build.<anonymous closure> (package:car_park/util/self_updating_map.dart:58:22)
#3      StreamBuilder.build (package:flutter/src/widgets/async.dart:425:74)
#4      _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:125:48)
#5      StatefulElement.build (package:flutter/src/widgets/framework.dart:3825:27)
#6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3739:15)
#7      Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5)
#8      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2278:33)
#9      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
#10     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
#11     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
#12     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
#13     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
#17     _invoke (dart:ui/hooks.dart:219:10)
#18     _drawFrame (dart:ui/hooks.dart:178:3)
(elided 3 frames from package dart:async)
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

In fact, I get this error when I call move(...) on a MapController which is not affected to a map.

All 14 comments

Same here with latest flutter and flutter_map 0.5.4

Okay, the usage of MapController is not well documented but the class has a getter ready which returns whether or not the state can be used. So before using any MapController method, the ready boolean should be checked @kaynz.

I leave this issue opened just for the authors to know that a little clarification may be needed.

@Skyost have you got this working successfully because I am having the same issue except that center and zoom also are null so I can't even reach map.move

any help getting this working would be appreciated

@MitchellQ

You have to wait until controller.ready returns _true_ before using the methods. You may want to listen to controller.onReady to know when you can use the methods like move, center, etc...

I'm not having much luck @Skyost can you please help

 mapController.onReady.then((result) {
      setState(() {
        animatedMapMove(
          LatLng(tracks[trackNum].activities[0].location.x,
              tracks[trackNum].activities[0].location.y),
          18.0,
        );
      });
    });

I changed my code to use onReady but it just skips over and never goes back, Im quite new to flutter and developing in general so I'm probably missing something simple but any help is appreciated

@MitchellQ Try something like that :

mapController.onReady.then((result) {
  mapController.move(LatLng(tracks[trackNum].activities[0].location.x, tracks[trackNum].activities[0].location.y), 18.0);
});

@Skyost I got it working, I was able to get it working and didn't need to use onReady. It seems my problem was due to using bottom navigation and how i displayed the map namely I have a List of widgets that the map is part of and the animate method doesn't like that for some reason so I used a ternary to display the map on the tab instead of adding it to the List of Widgets I spent so many hours on this, thanks for your help

I face a similar issue with this snapshot of code:

  @override
  Widget build(BuildContext context) {
    var center = getCenter(widget.issues);
    if (_mapCtrl.ready) {
      _mapCtrl.move(center, 12.0);
    }

and the stacktrace is:

I/flutter (23365): โ•โ•โ•ก EXCEPTION CAUGHT BY WIDGETS LIBRARY โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
I/flutter (23365): The following NoSuchMethodError was thrown building LeafletMap(dirty, state:
I/flutter (23365): _LeafletMapState#2fe39):
I/flutter (23365): The method 'toDouble' was called on null.
I/flutter (23365): Receiver: null
I/flutter (23365): Tried calling: toDouble()
I/flutter (23365): 
I/flutter (23365): When the exception was thrown, this was the stack:
I/flutter (23365): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
I/flutter (23365): #1      pow (dart:math-patch/math_patch.dart:83:44)
I/flutter (23365): #2      Crs.scale (package:flutter_map/src/geo/crs/crs.dart:38:18)
I/flutter (23365): #3      MapState.getZoomScale (package:flutter_map/src/map/map.dart:237:16)
I/flutter (23365): #4      MapState.getPixelBounds (package:flutter_map/src/map/map.dart:261:17)
I/flutter (23365): #5      MapState.getLastPixelBounds (package:flutter_map/src/map/map.dart:165:12)
I/flutter (23365): #6      MapState._calculateBounds (package:flutter_map/src/map/map.dart:169:18)
I/flutter (23365): #7      MapState.getBounds (package:flutter_map/src/map/map.dart:157:12)
I/flutter (23365): #8      MapState.bounds (package:flutter_map/src/map/map.dart:86:30)
I/flutter (23365): #9      MapState.move (package:flutter_map/src/map/map.dart:103:56)
I/flutter (23365): #10     MapControllerImpl.move (package:flutter_map/src/map/map.dart:28:12)

any help is appreciate on what I could possibly do wrong.
Dependency is flutter_map: ^0.5.5

@Skyost is correct, the mapController can't be used until it's ready

It is still not working. Please help me I tried everything from above.

As other said, we need to check onReady
floatingActionButton: FloatingActionButton( onPressed: () { _mapController.onReady.then((result) { _mapController.move(LatLng(51.5, -0.09), 13.0); }); }, )

At first, I was facing issues because _mapController was initialized at build() method, so as soon as I was doing setState(), old _mapController.onReady was getting discarded. Make sure _mapController is declared at class level. Now everything works fine.

if (lat != null && long != null) {
mapController.onReady.then((result) {
mapController.move(LatLng(lat, long), _inZoom);
This is part of my code.
I hope it works for u guys! it works for me
I put in a function where move the cam if the location (lat,long) is already to work

My map controller is never ready. Any idea why ?

Not without seeing any code no. It may be that you're drawing the widget before the map controller is ready as mentioned earlier.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnpryan picture johnpryan  ยท  4Comments

EdHubbell picture EdHubbell  ยท  4Comments

GENL picture GENL  ยท  6Comments

garrrettt picture garrrettt  ยท  3Comments

jasonleung101 picture jasonleung101  ยท  3Comments