【问题标题】:How to align loading icon at center horizontally in PagedGridView?如何在 PagedGridView 中水平对齐中心的加载图标?
【发布时间】:2021-12-13 09:04:01
【问题描述】:

我正在尝试使用无限滚动在 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]);
                         
                    }),
                  )

【问题讨论】:

    标签: flutter gridview flutter-layout flutter-dependencies infinite-scroll


    【解决方案1】:

    不要将加载指示器添加为网格项。这就是为什么它位于右侧。 我会使用 CustomScrollView 和 SliverGrid 而不是 PagedGridView 和 SliverFillRemaining 来显示活动指示器。

      CustomScrollView(
        slivers: [
          SliverGrid(
            delegate: PagedChildBuilderDelegate<Post>(
                itemBuilder: (context, item, 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(),
            ),
        ],
      );
    

    【讨论】:

    • 它给了我错误,因为参数类型“PagedChildBuilderDelegate”不能分配给参数类型“SliverChildDelegate”。
    猜你喜欢
    • 2021-08-12
    • 2011-02-04
    • 2015-09-02
    • 1970-01-01
    • 2012-03-15
    • 2018-06-23
    • 1970-01-01
    • 2015-05-21
    • 2019-01-27
    相关资源
    最近更新 更多