hemanthrajv / flutter_compass

MIT License
101 stars 170 forks source link

NoSuchMethodError: The method 'cast' was called on null. #56

Closed steinmetz closed 3 years ago

steinmetz commented 3 years ago

I am getting many logs on Sentry for this:

image

NoSuchMethodError: NoSuchMethodError: The method 'cast' was called on null. Receiver: null Tried calling: cast() File "object_patch.dart", line 54, in Object.noSuchMethod File "flutter_compass.dart", line 56, in FlutterCompass.events. File "stream_pipe.dart", line 213, in _MapStream._handleData File "stream_pipe.dart", line 153, in _ForwardingStreamSubscription._handleData File "zone.dart", line 1370, in _rootRunUnary File "zone.dart", line 1265, in _CustomZone.runUnary File "zone.dart", line 1170, in _CustomZone.runUnaryGuarded File "stream_impl.dart", line 341, in _BufferingStreamSubscription._sendData File "stream_impl.dart", line 591, in _DelayedData.perform File "stream_impl.dart", line 706, in _StreamImplEvents.handleNext File "stream_impl.dart", line 663, in _PendingEvents.schedule. File "zone.dart", line 1346, in _rootRun File "zone.dart", line 1258, in _CustomZone.run File "zone.dart", line 1162, in _CustomZone.runGuarded File "zone.dart", line 1202, in _CustomZone.bindCallbackGuarded. File "zone.dart", line 1354, in _rootRun File "zone.dart", line 1258, in _CustomZone.run File "zone.dart", line 1162, in _CustomZone.runGuarded File "zone.dart", line 1202, in _CustomZone.bindCallbackGuarded. File "schedule_microtask.dart", line 40, in _microtaskLoop File "schedule_microtask.dart", line 49, in _startMicrotaskLoop

What do you think if there is a check here if data is not null?

.map((dynamic data) => CompassEvent.fromList(data.cast<double>()))

thanhhuan1990 commented 3 years ago

Same for me on many devices.

EdgarJan commented 3 years ago

Such error is happening on devices without magnetometer sensor, it dosen't crash app. You can catch this error in StreamBuilder.

Do-Repo commented 3 years ago

this happens on my Huawei y6 II however it has a built in compass app, idk how that's supposed to work if this error means there's no magnetometer sensor

In my case this error is coming from somewhere else I/flutter (20562): NoSuchMethodError: The method 'cast' was called on null. I/flutter (20562): Receiver: null I/flutter (20562): Tried calling: cast() because my device has a magnetometer

hemanthrajv commented 3 years ago

Closed by #61