Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下拉刷新时列表子项高度增加或减少导致不回弹 #618

Closed
denymz opened this issue Sep 19, 2022 · 4 comments
Closed

下拉刷新时列表子项高度增加或减少导致不回弹 #618

denymz opened this issue Sep 19, 2022 · 4 comments

Comments

@denymz
Copy link

denymz commented Sep 19, 2022

使用callRefresh进行刷新,刷新完成后子项数量不减少/增加,但是高度会减少/增加时,会导致Header收不回去;手动上滑可以将之归位,如果不手动上滑,下一次callRefresh调用时不会触发onRefresh,但是会将Header归位。

代码结构:

EasyRefreshController _refreshController = EasyRefreshController(
      controlFinishLoad: true,
      controlFinishRefresh: true,
);

EasyRefresh(
              controller: _refreshController,
              header: const CupertinoHeader(
                position: IndicatorPosition.locator,
                safeArea: false,
              ),
              onRefresh: () async {
                Model resp;
                try {
                  resp = await getLayout();
                  if (!mounted) {
                    return IndicatorResult.none;
                  }
                  setState(() {
                    boxList = resp.data;
                    _count = boxList?.length ?? 0;
                  });
                } finally {
                  _refreshController.finishRefresh();
                }
                return IndicatorResult.success;
              },
              child: CustomScrollView(
                slivers: [
                  const HeaderLocator.sliver(),
                  SliverPadding(
                    padding: const EdgeInsets.symmetric(vertical: 4),
                    sliver: SliverList(
                      delegate: SliverChildBuilderDelegate(
                        (_, index) {
                          if (_count == 0) {
                              return EmptyWidget();
                          }
                          return _buildBoxWidget(boxList![index]);
                        },
                        childCount: _count > 0 ? _count : 1,
                      ),
                    ),
                  ),
                ],
              ),

_buildBoxWidget 方法如下:
通过 AnimatedCrossFade 进行组件切换,切换时高度会发生变化。

  Widget _buildBoxWidget(BoxModel e) {
    switch (e.type) {
      case "commonBox":
        return Consumer2<SettingsCache, UsageStatCache>(
            builder: (ctx, settings, usageStat, _) {
          if (!settings.currSettings.enable) return Container();
          var showBox = usageStat.getList.isNotEmpty
              ? CrossFadeState.showSecond
              : CrossFadeState.showFirst;
          return AnimatedCrossFade(
              firstChild: Container(),
              secondChild: CommonBoxWidget(title: e.title),
              crossFadeState: showBox,
              duration: const Duration(milliseconds: 200));
        });
      default:
        return Container();
    }
  }
@hukejia
Copy link

hukejia commented Oct 9, 2022

解决了吗,和你碰到一样的问题

@denymz
Copy link
Author

denymz commented Oct 20, 2022

解决了吗,和你碰到一样的问题

谈不上解决,使用了默认的Header就不会出现此问题

@hukejia
Copy link

hukejia commented Oct 20, 2022

先更新列表,延迟200毫秒再finishRefresh 也能正常,不过这办法好鸡肋

@xuelongqy
Copy link
Owner

3.2.2+2已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants