Code Monkey home page Code Monkey logo

Comments (6)

YeFei572 avatar YeFei572 commented on July 16, 2024 2

问题已经解决了, 直接上代码吧,

 @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
    return RefreshIndicator(
      onRefresh: _refreshData,
      child: Container(
        color: Colors.grey[100],
        child: StaggeredGridView.countBuilder(
          controller: _scrollController,
          itemCount: posts.length,
          primary: false,
          crossAxisCount: 4,
          mainAxisSpacing: 4.0,
          crossAxisSpacing: 4.0,
          itemBuilder: (context, index) => TileCard(
                img: '${posts[index]['images'][0]}',
                title: '${posts[index]['title']}',
                author: '${posts[index]['userName']}',
                authorUrl: '${posts[index]['iconUrl']}',
                type: '${posts[index]['type']}',
                worksAspectRatio: posts[index]['worksAspectRatio'],
              ),
          staggeredTileBuilder: (index) => StaggeredTile.fit(2),
        ),
      ),
    );
  }

你要做的就是在StaggeredGridView上面添加一个入参itemCount, 这个入参代表你当前列表的长度, 另外还要加上controller来监控滑动条的位置, 这样就可以实现分页了!

from flutter_staggered_grid_view.

the-maunda avatar the-maunda commented on July 16, 2024

anyone with a solution to this??

from flutter_staggered_grid_view.

YeFei572 avatar YeFei572 commented on July 16, 2024

+1, 是做分页的时候出现的问题吧? 同样碰到了, 使用scrollController来监听分页好像不行呢, 我这边目前是这样的:

@override
  void initState() {
    super.initState();
    _getPosts(_beAdd);
    _scrollController.addListener(() {
      print('cando: ${_scrollController.position.pixels}');
      print('cando: ${_scrollController.position.maxScrollExtent}');

      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent) {
            print('开始翻页了...............');
        _addMoreData();
      }
    });
  }

其中_scrollController.position.maxScrollExtent的值 始终是initify, 所以没有执行_addMoreData()方法. 我判断这边不能使用这个判断条件. 但是目前没有找到解决办法!

from flutter_staggered_grid_view.

wrozwad avatar wrozwad commented on July 16, 2024

I can confirm that @YeFei572 solution works. So you must remember to include itemCount to StaggeredGridView.builder(), StaggeredGridView.countBuilder() or StaggeredGridView.extendBuilder() and if you specify gridDelegate: SliverStaggeredGridDelegateWithFixedCrossAxisCount pass items count as staggeredTileCount argument.

Btw → @YeFei572 pls, use English next time ;)

from flutter_staggered_grid_view.

letsar avatar letsar commented on July 16, 2024

Can you test with the latest 0.5.0 preview? https://pub.dev/packages/flutter_staggered_grid_view/versions/0.5.0-dev.1

from flutter_staggered_grid_view.

letsar avatar letsar commented on July 16, 2024

This thread has been closed since there has not been any response for a while. If you are still experiencing a similar issue, please open a new bug.

from flutter_staggered_grid_view.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.