Skip to content

Flutter web throws TypeError: Instance of 'JSArray<dynamic>': type 'List<dynamic>' is not a subtype of type 'List<Binding>' on hot restart. #1307

@dhiaCodes

Description

@dhiaCodes

In web/JS interop, .where().toList() chains infer List instead of preserving generic types, which fails on hot restart:

_bindings[typeLower] = _bindings[typeLower]!
    .where((bind) => ...)
    .toList();  // --> throws Exception

To Reproduce

  • Set up a RealtimeChannel with event listeners using a method like onPostgresChanges()
  • Run Flutter web
  • Hot restart the app
  • Observe the TypeError: Instance of 'JSArray<dynamic>': type 'List<dynamic>' is not a subtype of type 'List<Binding>'

Expected Behavior and Root Cause

The off() method in the RealtimeChannel class should successfully remove the matching event binding from the _bindings map without any type errors.

Suggested Fix

Add explicit type casting: (this method is inside RealtimeChannel class)

  @internal
  RealtimeChannel off(String type, Map<String, String> filter) {
    final typeLower = type.toLowerCase();

    _bindings[typeLower] = _bindings[typeLower]!
        .where((bind) {
          return !(bind.type.toLowerCase() == typeLower &&
              RealtimeChannel._isEqual(bind.filter, filter));
        })
        .toList()
        .cast<Binding>();  // --> this cast seems to fix the issue for me !
    return this; 
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions