You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成supabase_flutter 2.1.0执行flutter run时报错求助

解决web_socket_channel与web包版本冲突导致的EventStreamProviders未定义错误

问题场景

执行flutter pub get supabase_flutter导入包后,运行flutter run时出现以下编译错误:

../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.2/lib/src/web_helpers.dart:10:32: Error: The getter 'EventStreamProviders' isn't defined for the class 'WebSocket'.
 - 'WebSocket' is from 'package:web/src/dom/websockets.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/websockets.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'EventStreamProviders'.
  Stream<Event> get onOpenX => EventStreamProviders.openEvent.forTarget(this);
                               ^^^^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.2/lib/src/web_helpers.dart:12:7: Error: The getter 'EventStreamProviders' isn't defined for the class 'WebSocket'.
 - 'WebSocket' is from 'package:web/src/dom/websockets.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/websockets.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'EventStreamProviders'.
      EventStreamProviders.messageEvent.forTarget(this);
      ^^^^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.2/lib/src/web_helpers.dart:14:7: Error: The getter 'EventStreamProviders' isn't defined for the class 'WebSocket'.
 - 'WebSocket' is from 'package:web/src/dom/websockets.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/websockets.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'EventStreamProviders'.
      EventStreamProviders.closeEvent.forTarget(this);
      ^^^^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/web_socket_channel-2.4.2/lib/src/web_helpers.dart:16:7: Error: The getter 'EventStreamProviders' isn't defined for the class 'WebSocket'.
 - 'WebSocket' is from 'package:web/src/dom/websockets.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/web-0.3.0/lib/src/dom/websockets.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'EventStreamProviders'.
      EventStreamProviders.errorEventSourceEvent.forTarget(this);
      ^^^^^^^^^^^^^^^^^^^^

问题原因

web包0.3.0版本进行了API重大重构,移除了EventStreamProviders类,但当前依赖的web_socket_channel-2.4.2仍在调用这个已被移除的API,两者版本不兼容导致编译失败。supabase_flutter间接依赖web_socket_channel,因此触发了该问题。

解决方案

任选以下一种方法即可解决:

  • 升级web_socket_channel到兼容版本
    执行命令升级到支持web0.3.0的版本(2.4.3及以上):

    flutter pub upgrade web_socket_channel
    

    之后重新执行flutter pub get。

  • 锁定web包到旧兼容版本
    在项目的pubspec.yaml文件中添加web包的版本约束:

    dependencies:
      # 其他依赖...
      web: ^0.2.2+1
    

    执行flutter pub get拉取指定版本。

  • 清理缓存重新获取依赖
    如果上述方法不生效,清理pub缓存后重新获取:

    flutter pub cache clean
    flutter pub get
    

内容的提问来源于stack exchange,提问作者Tommy Johnson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 00:10:23