poitch / dart-matomo

A Dart Matomo Client
MIT License
20 stars 39 forks source link

CastError when initializing #15

Closed SlayerOrnstein closed 3 years ago

SlayerOrnstein commented 3 years ago

Matomo seems to be throwing and error when initializing, started to happen when updating to 0.1.1.

_CastError: type '_InternalLinkedHashMap<String, String?>' is not a subtype of type 'Map<String, String>?' in type cast
  File "matomo.dart", line 384, in _MatomoDispatcher.send
  File "matomo.dart", line 261, in MatomoTracker._dequeue
  File "matomo.dart", line 183, in MatomoTracker.initialize.<fn>
  File "zone.dart", line 1362, in _rootRunUnary
  File "zone.dart", line 1265, in _CustomZone.runUnary
  File "zone.dart", line 1170, in _CustomZone.runUnaryGuarded
  File "zone.dart", line 1207, in _CustomZone.bindUnaryCallbackGuarded.<fn>
  File "zone.dart", line 1370, in _rootRunUnary
  File "zone.dart", line 1265, in _CustomZone.runUnary
  File "zone.dart", line 1191, in _CustomZone.bindUnaryCallback.<fn>
  File "timer_impl.dart", line 395, in _Timer._runTimers
  File "timer_impl.dart", line 426, in _Timer._handleMessage
  File "isolate_patch.dart", line 184, in _RawReceivePortImpl._handleMessage
poitch commented 3 years ago

This seems to be in the send method. We dequeue messages in the initialize method which ends up sending messages.

In particular, the crash seems to be when we cast the headers:

headers as Map<String, String>?

This is strange but might be due to a newer version of dart that I've been using. (I've been stuck to pre-nullsafety for my main project because other libraries haven't moved yet)

Could you send me the version of dart you are using?

I'll look into this crash over the weekend.

SlayerOrnstein commented 3 years ago

Yeah, sorry I didn't include it from the start.

Flutter 2.0.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision adc687823a (2 weeks ago) • 2021-04-16 09:40:20 -0700
Engine • revision b09f014e96
Tools • Dart 2.12.3
Dix206 commented 3 years ago

I had the same problem. I've fixed it and opened a PR: https://github.com/poitch/dart-matomo/pull/16

SlayerOrnstein commented 3 years ago

All seems good now thank you @poitch and @Dix206