Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash when move() is called before FlutterMap has been built #827

Merged
merged 1 commit into from Mar 16, 2021

Conversation

gr4yscale
Copy link
Contributor

@gr4yscale gr4yscale commented Feb 21, 2021

If size has never been computed before move() is called on a MapController instance, there is a crash:

E/flutter (20522): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '/' was called on null.
E/flutter (20522): Receiver: null
E/flutter (20522): Tried calling: /(2.0)
E/flutter (20522): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (20522): #1      MapState.getPixelBounds (package:flutter_map/src/map/map.dart:464:25)
package:flutter_map/…/map/map.dart:464
E/flutter (16529): #2      MapState.move
package:flutter_map/…/map/map.dart:307
E/flutter (16529): #3      MapControllerImpl.move
package:flutter_map/…/map/map.dart:41
E/flutter (16529): #4      MapAltState.initState.<anonymous closure>

MapController has a ready state, but it can be ready and the map not built yet.

@gr4yscale gr4yscale changed the title Prevent crash when move() is called before FlutterMap has been built Prevent crash when move() is called before FlutterMap has been built Feb 22, 2021
@gr4yscale gr4yscale changed the title Prevent crash when move() is called before FlutterMap has been built Prevent crash when move() is called before FlutterMap has been built Feb 22, 2021
@@ -133,7 +133,7 @@ class MapState {
// Extended size of the map where rotation is calculated
CustomPoint _size;

CustomPoint get size => _size;
CustomPoint get size => _size ?? CustomPoint(0.0, 0.0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also initialize the _size field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnpryan That would have made more sense!

@johnpryan johnpryan merged commit 159c06f into fleaflet:master Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants