SaltechSystems / couchbase_lite

Flutter plugin for the Community edition of Couchbase Lite. Couchbase Lite is an embedded lightweight, document-oriented (NoSQL), syncable database engine.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

null-safety migrated app crash on document change (listener)

matsunanaro opened this issue · comments

Describe the bug
We've migrated our app to null-safety using the latest tag v3.0.0-nullsafety.1
However, the app crashes whenever there is a document change (in the hosted couchbase bucket).

To Reproduce
Steps to reproduce the behavior:

  1. Migrated the couchbase_lite_example app to null-safety
  2. Log in using foo/bar
  3. In the couchbase server, manually change a document in the 'sample-beer' bucket
  4. The migrated app will crash with the following exception:

I/flutter ( 3367): ReplicatorActivityLevel.busy E/flutter ( 3367): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type 'List<Object?>' is not a subtype of type 'List<Object>' in type cast E/flutter ( 3367): #0 Database.addDocumentChangeListener.<anonymous closure> package:couchbase_lite/src/database.dart:223 E

Additional context
The crash was due to a downcast in 'couchbase_lite/src/database.dart:223'.
I believe the downcast should be List<dynamic> instead.

`ListenerToken addDocumentChangeListener(String withId,
Function(DocumentChange) callback) {
var token = ListenerToken();

tokens[token] = _stream
    .where((data) =>
(data['database'] == name && data['type'] == 'DatabaseChange') &&
    (data['documentIDs'] as List<Object>).contains(withId))
                                          ^^^^^^^^^^^^^
  ///  Failed to cast as List<Object>. Should it be cast as List<dynamic> instead?
    .listen((data) {
  callback(DocumentChange(this, withId));
});

// Caveat:  Do not call addChangeListener more than once.
if (tokens.length == 1) {
  _methodChannel.invokeMethod(
      'addChangeListener', <String, dynamic>{'database': name});
}

`

I've already created a PR for this one.