Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter SliverList和Getx StateMixin支持_Flutter_Flutter Sliver_Flutter Getx - Fatal编程技术网

Flutter SliverList和Getx StateMixin支持

Flutter SliverList和Getx StateMixin支持,flutter,flutter-sliver,flutter-getx,Flutter,Flutter Sliver,Flutter Getx,我正在努力使GetxController与SliverList一起工作。特别是,我的控制器使用StateMixinfrom返回视图状态 类行程ByCreatorPageController扩展GetxController 与StateMixin{ 行程ByCreatorPageController(此.\u交互者); 最终行程由中介人与互动人共同完成; void getCreatorPage(字符串创建者标签,字符串语言){ _互动者 .GetInvesturesByCreatorSlug(cr

我正在努力使
GetxController
SliverList
一起工作。特别是,我的控制器使用
StateMixin
from返回视图状态

类行程ByCreatorPageController扩展GetxController
与StateMixin{
行程ByCreatorPageController(此.\u交互者);
最终行程由中介人与互动人共同完成;
void getCreatorPage(字符串创建者标签,字符串语言){
_互动者
.GetInvesturesByCreatorSlug(creatorSlug,语言)
.then((值)=>change(值,状态:RxStatus.success())
.onError((错误,堆栈跟踪)=>
更改(null,状态:RxStatus.error(error.toString()));
}
}
在视图方面,我使用
obx
扩展来观察控制器状态,并使用
SliverList
来显示数据。不幸的是,
SliverList
delegate
SliverChildBuilderDelegate
需要在其构造函数中提供list
childCount
,但是子计数是从控制器异步来的,我在Getx文档中找不到以反应方式返回子计数的方法。有什么方法可以使
SliverList
Getx
一起工作吗

Widget\u获取行程列表(){
返回银表(
代表:SliverChildBuilderDelegate(
(上下文,索引)=>\u controller.obx((数据){
如果(索引==0){
返回CreatorInfo小部件(
创建者:data.first,
imageWidget:CreatorImageWidget(
imageUrl:data.first.avatars.first,
),
);
}else if(索引==1){
返回主行程窗口小部件(
创建者:data.first,行程:data.second[index-1]);
}否则{
返回第二行程小部件(
创建者:data.first,行程:data.second[index-1]);
}
}),
childCount:5//此处使用来自控制器的动态子计数);
}

您可以在
滑动列表上方向上移动
控制器.obx

Widget _getItinerariesList() {
return _controller.obx((data) {
  return SliverList(
        delegate: SliverChildBuilderDelegate(
        (context, index){
              if (index == 0) {
                return CreatorInfoWidget(
                  creator: data.first,
                  imageWidget: CreatorImageWidget(
                    imageUrl: data.first.avatars.first,
                  ),
                );
              } else if (index == 1) {
                return MainItineraryWidget(
                    creator: data.first, itinerary: data.second[index - 1]);
              } else {
                return SecondaryItineraryWidget(
                    creator: data.first, itinerary: data.second[index - 1]);
              }
            }),
        childCount: data.yourCountVariable // use a dynamic child count here, coming from the controller));
   }
}