Comments (25)
在模拟器只要重新运行就会加一次回调
from fluttertencentimplugin.
你好,请确定 addListener 只运行了一次,或 及时 removeListener
from fluttertencentimplugin.
请检查是否移除监听成功
from fluttertencentimplugin.
我发现只要重新flutter run就不会了。但之后每次R运行就会加一次回调。确定在页面dispose时都有移除监听了。
from fluttertencentimplugin.
因为Flutter热加载机制在部分情况下会重新运行 initState 方法,且不会运行 dispose 方法,所以请注意热加载时的问题!
from fluttertencentimplugin.
好的,谢谢!
from fluttertencentimplugin.
顺便问下getMessages能做分页么
from fluttertencentimplugin.
getMessage 目前支持分页,只需要传 lastMessage
参数即可
from fluttertencentimplugin.
我想移除监听是不是有问题,就算我在initState里先remove再addlisten,回调还是一次次增加
from fluttertencentimplugin.
removeListener 以及 addListener 需要接收一个方法引用,当你对象不相同时,就没法移除其它对象的引用。请确保 removeListener 传入的方法和addListener传入的方法相同。
from fluttertencentimplugin.
所以在引用不相同的情况下,先remove始终会无效,这是Dart机制。
from fluttertencentimplugin.
TencentImPlugin.removeListener(_messageListener);
TencentImPlugin.addListener(_messageListener);
是同一个的。
from fluttertencentimplugin.
同一个的判定条件还有对象,也就是类的对象
from fluttertencentimplugin.
假设你在对象A中添加,是没有办法在对象B中移除,即使他们的方法是相同的。因为他们在内存中的“址”是不相同的。
from fluttertencentimplugin.
@OverRide
void initState() {
super.initState();
TencentImPlugin.removeListener(_messageListener);
TencentImPlugin.addListener(_messageListener);
}
_messageListener(ListenerTypeEnum type, params) {}
就这样呀,在同一个文件里。同一个类里
from fluttertencentimplugin.
同一个文件,同一个类,不代表“对象”相同,对象是类的实例化,类只是抽象的表述。
from fluttertencentimplugin.
你可通过Debug模式排查,在 initState 中和dispose 中进行打断点排查,确保调用 addListener 和 removeListener 是正确的.
from fluttertencentimplugin.
我觉得监听跟移除监听写法应该没错的。在同一个文件同一个页面里。
from fluttertencentimplugin.
你没遇到过吗?shift+R重新进入聊天界面,监听回调多执行了一次
from fluttertencentimplugin.
必须要关闭重新flutter run才回到一次
from fluttertencentimplugin.
因为Flutter热加载机制在部分情况下会重新运行 initState 方法,且不会运行 dispose 方法,所以请注意热加载时的问题!
请检查是否多次调用 addListener 或 removeListener 不及时
from fluttertencentimplugin.
我觉得监听跟移除监听写法应该没错的。在同一个文件同一个页面里。
据上面所说,同一个类、同一文件,创建两个对象后,他们内部的方法引用是不相同的。
如果你需要验证 先remove再add,请将回调方法更改为 static.
from fluttertencentimplugin.
看来是热重载时dispose没执行导致监听没被移除掉,这样在模拟器无解了?官方好像没提供解决方法
from fluttertencentimplugin.
from fluttertencentimplugin.
嗯,只是开发时有点麻烦。谢谢
from fluttertencentimplugin.
Related Issues (20)
- android release包闪退 HOT 8
- 请问下新版的群简介怎么拿到,之前的版本会话列表中可以取到群简介 HOT 1
- 大佬能不能顺便也支持一下web HOT 2
- android createGroup 返回的groupID有非法字符 " HOT 2
- ios setGroupInfo必须指定全部字段,否则其他字段会被清空(android没这个问题) HOT 4
- 似乎是跟flutter_sound插件的依赖版本起冲突,请问该如何解决? HOT 4
- ios编译报错 HOT 1
- 请问直接关闭App的时候有办法让IM执行退出登录操作吗? HOT 1
- 如何更新本地的IM用户的信息呢? HOT 5
- Swift里的JsonUtil无法解析特殊字符 HOT 6
- flutter2.5.3 ios运行模拟器报错 HOT 16
- 可以支持下 insertC2CMessageToLocalStorage 这个方法嘛? HOT 2
- 发送失败后,调用resendMessage接口,并不能改变消息的发送状态status(依旧为MessageStatusEnum.SendFail) HOT 1
- ios 调用sendMessage 时 真机闪退 HOT 11
- 消息发送是否支持CloudCustomData HOT 9
- 麻烦添加一下x64支持 HOT 1
- 安卓机在进行会话监听时闪退 HOT 23
- `TencentImPlugin.setSelfInfo` 不生效或失败, 导致该用户聊天时获取到的`faceUrl`为null 或 不更新是旧头像, 但是试了腾讯官方的demo, 没有该问题 HOT 6
- DeviceToken
- 通过ref引入编译失败 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluttertencentimplugin.