firebase GetX状态管理无法更新SliverPersistentHeader上的值

uklbhaso  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(158)

我遇到了一些Getx状态管理的问题,当我在SliverPersistentHeader上 Package CustomScrollView,然后我在它上面实现列表视图,然后我在列表上做一些偶数,但是它没有更新。

class SFController extends GetxController {
  int currentIndex = 0;
  onSeletedTab(int index) {
    currentIndex = index;
    update();
  }
}

这是我的用户界面

GetBuilder(
          init: controller,
          builder: (_) {
            return CustomScrollView(slivers: [
              SliverAppBar(),
              SliverPersistentHeader(
                pinned: true,
                delegate: _HeaderSliver(controller),
              ),
            ]);
          }),

下面是_标题条:

class _HeaderSliver extends SliverPersistentHeaderDelegate {
  final SFController controller;
  _HeaderSliver(this.controller);

@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return Stack(
  children: [
    Positioned(
      bottom: 0.0,
      left: 0.0,
      right: 0.0,
      top: 0.0,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16.0),
        height: _maxHeaferExtent,
        color: Colors.white,
        child: Row(
          children: [
            Expanded(
              child: Container(
                alignment: Alignment.center,
                height: 35.0,
                color: Colors.white,
                child: ListView.separated(
                  padding: const EdgeInsets.only(
                  left: 4.0, right: 4.0, bottom:        4.0, top: 0.0),
                  scrollDirection: Axis.horizontal,
                  itemCount: 3,
                  itemBuilder: (context, index) {
                    return GestureDetector(
                      onTap: () {
                        log("Index:");
                        controller.onSeletedTab(index);
                      },
                      child: Container(
                        padding: const EdgeInsets.only(left: 10.0, right: 10.0),
                        height: 36.0,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: controller.indeTest == index ? 
                           AppColor.secondaryColor : AppColor.neutral25,
                          borderRadius: BorderRadius.circular(24.0),
                        ),
                        child: Text(
                          controller.stringTitle[index],
                          style: Theme.of(context).textTheme.bodyText1?.copyWith(
                                fontSize: 14,
                                color: controller.indeTest == index ? 
                                 AppColor.white : AppColor.neutral900,
                                fontWeight: controller.indeTest == index ? 
                              FontWeight.w600 : FontWeight.w400,
                              ),
                        ),
                      ),
                    );
                  },
                  separatorBuilder: (BuildContext context, int index) =>
                      const Padding(padding: EdgeInsets.only(left: 10.0)),
                ),
              ),
            ),
            Container(
              padding: const EdgeInsets.only(left: 0.0, right: 4.0, bottom: 8.0, 
              top: 0.0),
              alignment: Alignment.centerRight,
              height: 36.0,
              color: Colors.white,
              child: Text(
                "Select",
                style: Theme.of(context).textTheme.bodyText1?.copyWith(
                      fontSize: 12,
                      color: AppColor.secondaryColor,
                      fontWeight: FontWeight.w700,
                    ),
              ),
            )
          ],
        ),
      ),
    )
  ],
);
}

@override
double get maxExtent => _maxHeaferExtent;

@override
double get minExtent => _maxHeaferExtent;

@override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) => false;
}

我尝试在SliverPersistentHeader的更新项控制器上调用方法,但不起作用。

b1zrtrql

b1zrtrql1#

GetBuilder的init参数中,您可以尝试将SFController()替换为controller,因为通过使用控制器,您可以直接访问(查找)它。

相关问题