Skip to content

[firebase_messaging] Flutter throws NoSuchMethod error when hot restarting (Please read description) #209

Closed
@ThinkDigitalSoftware

Description

@ThinkDigitalSoftware

Error thrown is NoSuchMethodError: The method 'add' was called on null. Receiver: null Tried calling: add(Instance of 'QuerySnapshot'):

I don't know why the error is happening, but I have traced down the reason. I'm assuming that my device never deregisters as an observer before it's hot restarted and it contributes to the issue. The attached video can explain the issue better than I can. Please ask for clarification as I'm unable to duplicate it since I don't understand it fully enough.
Video
In cloud_firestore-0.9.7/lib/src/firestore.dart

class Firestore {
  Firestore({FirebaseApp app}) : app = app ?? FirebaseApp.instance {
    if (_initialized) return;
    channel.setMethodCallHandler((MethodCall call) async {
      if (call.method == 'QuerySnapshot') {
        final QuerySnapshot snapshot = QuerySnapshot._(call.arguments, this);

       // THIS IS WHERE THE ERROR OCCURS👇🏾
        _queryObservers[call.arguments['handle']].add(snapshot);
      } else if (call.method == 'DocumentSnapshot') {
        final DocumentSnapshot snapshot = DocumentSnapshot._(
          call.arguments['path'],
          _asStringKeyedMap(call.arguments['data']),
          this,
        );

Variables:
call.arguments['handle'] -> 7

_queryObservers (I just realized that this list starts at a higher number after I hot restart). This must be the cause.
_queryObservers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions