如何在 Flutter 中为 StreamBuilder 的重建添加条件?
How to add condition to StreamBuilder's rebuild in Flutter?
我正在使用 StreamBuilder
动态刷新 UI。
StreamBuilder<State>( //
stream: stateStream,
builder: (BuildContext context, AsyncSnapshot<BlocState> snapshot) =>
// do anything
);
当stateStream
中有新数据时,UI会自动刷新
但是,有时新数据和旧数据的值可能相同。这个时候就不用刷新了
如何控制StreamBuilder
这次不刷新?
您正在使用任何类型的状态管理吗?即集团?
如果您不想刷新小部件...您应该在 Bloc 中添加逻辑,而不是在 StreamBuilder 中。基本上如果数据相同,则不向Sink发送任何数据。
我建议使用 bloc_library. One of its advantages is that it does not send data to UI if it has not changed. I have recently written blog post,其中我已解决此功能。
如 所示,distinct
解决了我的问题
我正在使用 StreamBuilder
动态刷新 UI。
StreamBuilder<State>( //
stream: stateStream,
builder: (BuildContext context, AsyncSnapshot<BlocState> snapshot) =>
// do anything
);
当stateStream
中有新数据时,UI会自动刷新
但是,有时新数据和旧数据的值可能相同。这个时候就不用刷新了
如何控制StreamBuilder
这次不刷新?
您正在使用任何类型的状态管理吗?即集团?
如果您不想刷新小部件...您应该在 Bloc 中添加逻辑,而不是在 StreamBuilder 中。基本上如果数据相同,则不向Sink发送任何数据。
我建议使用 bloc_library. One of its advantages is that it does not send data to UI if it has not changed. I have recently written blog post,其中我已解决此功能。
如 distinct
解决了我的问题