flutter_movie icon indicating copy to clipboard operation
flutter_movie copied to clipboard

参考你的代码,使用rxdart遇到问题,想请教一下.

Open lifetin opened this issue 6 years ago • 3 comments

参考你的代码,使用rxdart遇到问题,想请教一下. 我现在的页面是这样的结构 main->index->indexFrame->indexFrameMain这样四层组合的一个首页 main是StatelessWidget其它全是StatefulWidget 我在main中使用

BlocProvider( child: Index(), blocs: [ IndexBloC(), ] 然后我在index中请求数据,然后通过IndexBloC中的add添加进ReplaySubject中 index中可以正常调用.也添加了数据进去.

IndexBloC 写法是这样 class IndexBloC extends BlocBase { final ReplaySubject<IndexModel> _subject = ReplaySubject<IndexModel>(maxSize: 1); Stream get stream => _subject.stream; @override void dispose() { _subject.close(); } void add(IndexModel model) { _subject.sink.add(model); } } 但是在在indexFrameMain中获取IndexBloC一直是空,不知道这是什么原因? 为了这个问题,调式了几个小时还没有搞定,望高手给讲解一下? 11

lifetin avatar Mar 31 '19 18:03 lifetin

然后我试了indexFrame中调用也是出现这样的问题. 我的BlocProvider文件是直接用你的. 参考了你的BlocProvider创建,全是在main中定义的. 把home全包住.你的教程中说这样可以所有页面都可访问.不知道我这是什么原因? 55

lifetin avatar Mar 31 '19 18:03 lifetin

不好意思,这个邮箱没有怎么用了,你说的包住是什么写法,可以对代码段进行截图,能否找到bloc或者相关属性都是基于build context的。

发自我的 iPad

在 2019年4月1日,02:11,超人不会飞 [email protected] 写道:

然后我试了indexFrame中调用也是出现这样的问题. 我的BlocProvider文件是直接用你的. 参考了你的BlocProvider创建,全是在main中定义的. 把home全包住.你的教程中说这样可以所有页面都可访问.不知道我这是什么原因?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

mm2qq avatar Apr 09 '19 17:04 mm2qq

对于示例main.dart中BlocProvider保证的是HomePage这个widget及其子widget下能够根据context访问到对应的bloc,你要注意BlocProvider是否嵌套的同一个widget树

mm2qq avatar Apr 10 '19 05:04 mm2qq