Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

android - Want whole list view scroll down when use flutter smart refresher

Use pull to refresh from fetching data from API with listView.Builder and StreamBuilder. When I pulldown refresh indicator appear and all is work. But I want whole of the list view to scroll down, not only showing refresh indicator. After that I can only use ListView.Builder widget, when I use listView, anything not showing in that page of scaffold.

I want like that in that photo which shown in pull_to_refresh Readme section. https://github.com/peng8350/flutter_pulltorefresh/raw/master/arts/example5.gif

newfeed.dart file

class _NewsFeedState extends State<NewsFeed> {
  HomeBloc _homeBc;
  RefreshController _refreshController = RefreshController();

  @override
  void initState() {
    _homeBc = HomeBloc();
    _homeBc.homePostRequest();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      initialData: ResponseObj(message: MsgState.loading),
      stream: _homeBc.homePostStream(),
      builder: (context, snapshot) {
        ResponseObj received = snapshot.data;
        if (received.message == MsgState.loading) {
          return Center(
            child: CircularProgressIndicator(),
          );
        } else if (received.message == MsgState.data) {
          print('=>=>=>=>=> ${received.data}');
          List<HomePostData> list = received.data;
          return Expanded(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: SmartRefresher(
                onRefresh: () {
                  _homeBc.homePostRequest();
                },
                onLoading: () {
                  _homeBc.loadMoreHomeRequest();
                },
                controller: _refreshController,
                // child: ListView(
                //   padding: EdgeInsets.all(10),
                //     children: list.map((e) {
                //       Post(
                //         onTap: (){},
                //         image: e.image,
                //         postTitle: e.title,
                //         uploadDateTime: e.createdAt,
                //         postContent: e.description,
                //       );
                //     }).toList(),
                //   ),


                child: ListView.builder(
                  padding: EdgeInsets.all(8.0),
                  physics: AlwaysScrollableScrollPhysics(),
                  itemCount: list.length,
                  itemBuilder: (context, index) {
                    return Post(
                      onTap: () {},
                      image: list[index].image,
                      postContent: list[index].description,
                      uploadDateTime: list[index].createdAt.split('T')[0],
                      postTitle: list[index].title,
                    );
                  },
                ),
              ),
            ),
          );
        } else {
          return Center(
            child: Text('Something Wrong'),
          );
        }
      },
    );
  }

  @override
  void dispose() {
    _homeBc.homeRqClose();
    super.dispose();
  }
}

home_body.dart file

class HomeBody extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        children: [
          SizedBox(height: getScreenHeightRation(10.0),),
          HomeHeader(),
          SizedBox(height: getScreenHeightRation(30.0),),
          HomeCatergories(),
          SizedBox(height: getScreenHeightRation(10.0),),
          NewsFeed(),
        ],
      ),
    );
  }
}
question from:https://stackoverflow.com/questions/65898383/want-whole-list-view-scroll-down-when-use-flutter-smart-refresher

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...