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

NoSuchMethodError in flutter testing on dispose #56

Open
ChemoCosmo opened this issue Apr 27, 2020 · 1 comment
Open

NoSuchMethodError in flutter testing on dispose #56

ChemoCosmo opened this issue Apr 27, 2020 · 1 comment

Comments

@ChemoCosmo
Copy link

ChemoCosmo commented Apr 27, 2020

When I use the location plugin in my app, all tests fail with an NoSuchMethodError / Null Pointer Error.

The following NoSuchMethodError was thrown while finalizing the widget tree:
The method 'cancel' was called on null.
Receiver: null
Tried calling: cancel()

When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      _MapsPluginLayerState.dispose (package:user_location/src/user_location_layer.dart:55:42)
#2      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4435:12)
#3      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1748:13)
[...]

Apparently the _onLocationChangedStreamSubscription listener is never initialized but waiting in the user_location_layer.dart::101 indefinitely for the location permission request.

When disposed in line user_location_layer.dart:55:42 the cancel operation is called, without checking if the subscription ever succeeded.

To Reproduce
Steps to reproduce the behavior:

  1. Implement location plugin in flutter project widget with flutter_map
  2. Write test that starts the widget
  3. Run "flutter test"

Expected behavior
No error, even without location permissions response.

Environment:

  • OS: Ubuntu 18.04
  • user_location Version: 0.1.2
  • flutter_map Version: 0.8.2
  • Flutter Version: 1.12.13
  • Dart Version: 2.7.0

Additional context
The tests are not about testing the plugins functionality or integration. The error appears already from instantiating the widget, without further interaction with the plugin.

@ChemoCosmo
Copy link
Author

A workaround is adding the user plugin to the map only when user location permission has been granted.
Still, would be nice if the plugin could work without throwing erros even with missing user location permission.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant