Flutter Dart-在将RX命令结果发送到RxLoader之前对其进行处理

Flutter Dart-在将RX命令结果发送到RxLoader之前对其进行处理,flutter,dart,reactive-programming,rxdart,Flutter,Dart,Reactive Programming,Rxdart,我正在编写一个flatter应用程序,我决定使用RxDart将我的数据和事件传递给经理、服务和用户界面。 基本上,我有一个从web服务获取数据并返回数据的服务。假设它返回一个名为ExploreEntity的模型的列表 class ExploreMockService extends ExploreServiceStruct { final String response = /** a sample json **/; @override Future<List<Expl

我正在编写一个flatter应用程序,我决定使用
RxDart
将我的数据和事件传递给经理、服务和用户界面。 基本上,我有一个从web服务获取数据并返回数据的服务。假设它返回一个名为
ExploreEntity
的模型的
列表

class ExploreMockService extends ExploreServiceStruct {
  final String response = /** a sample json **/;
  @override
  Future<List<ExploreEntity>> loadExploreData(PaginationInput input) async {
    await Future.delayed(new Duration(seconds: 2));
    return List<ExploreEntity>.from(jsonDecode(response));
  }
}
最后,我通过
RxLoader
获得结果,并将其传递给
GridView
,前提是数据获取成功

class ExplorePageState extends State<ExplorePage>{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Explore"),
        ),
        body: Column(children: <Widget>[
          Expanded(
            child: RxLoader<List<ExploreEntity>>(
                commandResults:
                sl.get<ExploreManager>().loadExploreDataCommand.results,
                dataBuilder: (context, data) => ExploreGridView(data),
                placeHolderBuilder: (context) => Center(
                  child: Center(
                    child: CircularProgressIndicator(),
                  ),
                ),
                errorBuilder: (context, error) => Center(
                  child: Text("Error"),
                )),
          )
        ]));
  }
}
类ExplorePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“探索”),
),
正文:列(子项:[
扩大(
儿童:RxLoader(
结果:
sl.get().loadExploreDataCommand.results,
dataBuilder:(上下文,数据)=>ExploreGridView(数据),
占位符生成器:(上下文)=>中心(
儿童:中心(
子对象:CircularProgressIndicator(),
),
),
errorBuilder:(上下文,错误)=>中心(
子项:文本(“错误”),
)),
)
]));
}
}
它的工作原理很有魅力,但当我想从web服务加载下一页的数据并将其附加到列表中时,我找不到一个解决方案来存储上一页的内容并将新页的内容附加到其中,因为数据是通过
RxCommand
RxLoader
自动传递的


loadExploreData
向经理发送响应时,我需要首先将结果附加到列表中,然后将该列表作为结果发送到
RxLoader
。有什么建议吗?

嗯,如果使用Rx就可以做到这一点,那么这是一个好问题。我要做的是在manager中保留一个已接收项目的列表。因此,当触发该命令以获取下一页时,该命令将首先将新数据添加到列表中,然后将整个列表推送到UI中。 我很好奇是否还有其他解决办法

我在一个粗略的代码示例中描述了我的方法

class ExploreManagerImplementation extends ExploreManager {
  List<ExploreEntity>> receivedData = <ExploreEntity>[];

  @override
  RxCommand<void, List<ExploreEntity>> loadExploreDataCommand;

  ExploreManagerImplementation() {
    loadExploreDataCommand = RxCommand.createAsync<PaginationInput, List<ExploreEntity>>((input) 
      async {
         var newData = await sl //Forget about this part
         .get<ExploreServiceStruct>() //and this part if you couldn't understand it
            .loadExploreData(input);
     receivedData.addAll(newData);
     return receivedData;
     };
  }


}
类ExploreManager实现扩展了ExploreManager{
列表>接收数据=[];
@凌驾
RxCommand loadExploreDataCommand;
ExploreManagerImplementation(){
loadExploreDataCommand=RxCommand.createAsync((输入)
异步的{
var newData=wait sl//忘记这部分
.get()//如果您不理解它,请使用此部分
.loadExploreData(输入);
receivedData.addAll(新数据);
返回接收数据;
};
}
}

谢谢你,先生……我在想这个问题,但我无法实现……你能给我提供一些代码吗?同样,我不得不放弃RxLoader?谢谢你,先生,你的回答帮助了我,并且在我需要的时候起了作用……我注意到了一个与问题无关的问题,但我还是要问你,看看你是否知道出了什么问题……我知道了从
RxLoader
中删除了
Placeholder Builder
,因为我不会在每次我想加载新数据到列表并显示
CircularProgressIndicator
时都隐藏列表。但不管怎样,它还是会一直显示,即使我用
Text
小部件替换它,但每次我都会看到
CircularProgressIndicator
n
loadExploreDataCommand
。也许这是
RxLoader
的一个bug?你能在rx\u命令库中提出一个问题吗?请在那里添加源代码。
class ExploreManagerImplementation extends ExploreManager {
  List<ExploreEntity>> receivedData = <ExploreEntity>[];

  @override
  RxCommand<void, List<ExploreEntity>> loadExploreDataCommand;

  ExploreManagerImplementation() {
    loadExploreDataCommand = RxCommand.createAsync<PaginationInput, List<ExploreEntity>>((input) 
      async {
         var newData = await sl //Forget about this part
         .get<ExploreServiceStruct>() //and this part if you couldn't understand it
            .loadExploreData(input);
     receivedData.addAll(newData);
     return receivedData;
     };
  }


}