flutter 如何在PagedGridView中将加载图标水平居中对齐?

yhived7q  于 2023-05-01  发布在  Flutter
关注(0)|答案(2)|浏览(174)

我试图在PagedGridView中使用无限滚动一次加载有限数量的数据来显示新闻项目。一切都工作正常,但我在获取额外数据时陷入了管理加载指示器对齐的困境。加载图标是对齐的权利,而我希望它是在屏幕的中心水平。

PagedGridView(
                    pagingController: _pagingController,
                    scrollController: _scrollController,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        childAspectRatio: 5.2 / 8.0,
                        crossAxisCount: 2,
                        crossAxisSpacing: 1.5,
                        mainAxisSpacing: 3.0,
                        mainAxisExtent: 225),
                    builderDelegate: PagedChildBuilderDelegate<Post>(
                        itemBuilder: (context, item, index) {
                            return AllNewsCard(
                                allNews:
                                newsHeadlineController.getAllNewsList[index]);
                         
                    }),
                  )
wooyq4lh

wooyq4lh1#

不要将加载指示器添加为网格项。这就是为什么它被定位在右边。我会使用CustomScrollViewSliverGrid来显示活动指示器,而不是PagedGridViewSliverFillRemaining

CustomScrollView(
    slivers: [
      SliverGrid(
        delegate: SliverChildBuilderDelegate(
            itemBuilder: (context, index) {
          return AllNewsCard(
              allNews: newsHeadlineController.getAllNewsList[index]);
        }),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          childAspectRatio: 5.2 / 8.0,
          crossAxisCount: 2,
          crossAxisSpacing: 1.5,
          mainAxisSpacing: 3.0,
          mainAxisExtent: 225,
        ),
      ),
      if (isLoading)
        SliverFillRemaining(
          hasScrollBody: false,
          child: CircularProgressIndicator(),
        ),
    ],
  );
shyt4zoc

shyt4zoc2#

PagedGridView中添加showNewPageProgressIndicatorAsGridChild: false
就像这样:

PagedGridView(
        showNewPageProgressIndicatorAsGridChild: false,
        ....

这将使PagedGridView不将加载指示符视为网格项。

相关问题