Home > Back-end >  Flutter : RefreshIndicator with ListView Scroll
Flutter : RefreshIndicator with ListView Scroll

Time:01-07

i have ListView. and listview have many item. Scroll through the screen.(vertical) and if scroll position is Top, i want to RefreshIndicator work. i don't know what i have to do..

now, only worked listview scroll. but when scroll position is Top, not work RefreshIndicator..

this is my code..

  @override


Widget build(BuildContext context) {
    return FutureBuilder<List<BoadModel>>(
      future: getData(),
      builder: (context, snapshot) {
        List<BoadModel> dataList = snapshot.data ?? [];
        if (snapshot.hasError) print(snapshot.error);
        return RefreshIndicator(
          onRefresh: () async {
            setState(() {});
          },
          child: SingleChildScrollView(
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Opacity(
                        opacity: 0.0,
                        child: ElevatedButton(
                            onPressed: () {}, child: Text("button"))),
                    Text(getCategoryName(widget.categoryPage)),
                    ElevatedButton(
                        onPressed: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => WriteBoadPage(
                                category: widget.categoryPage,
                              ),
                            ),
                          );
                        },
                        child: Text("글쓰기"))
                  ],
                ),
                snapshot.hasData
                    ? Column(
                        children: [
                          ListView.builder(
                            physics: NeverScrollableScrollPhysics(),
                            shrinkWrap: true,
                            itemCount: dataList.length,
                            itemBuilder: (BuildContext context, int index) {
                              return ListViewItem(
                                  title: dataList[index].title,
                                  nickname: dataList[index].nickname,
                                  time: dataList[index].time,
                                  view: dataList[index].view,
                                  commentCount: dataList[index].comment);
                            },
                          ),
                          Row(
                            children: [Text("dafs")],
                          )
                        ],
                      )
                    : Center(
                        child: CircularProgressIndicator(),
                      )
              ],
            ),
          ),
        );
      },
    );
  }

CodePudding user response:

In RefreshIndicator's onRefresh have you add some operations like below link?

RefreshIndicator

CodePudding user response:

i find solution. i have already mistake. problem is i have SingleChildScrollView already in parent widget..

return SingleChildScrollView( //have SingleChildScrollView already
  child: Column(
    children: [
      RefreshIndicator(
          child: SingleChildScrollView(
            child: ListView.builder(
              itemBuilder: (BuildContext context, int index) {
                return ListViewItem();
              },
            ),
          ),
          onRefresh: () async {}),
    ],
  ),
);

like this. and i fixed.

@override
  Widget build(BuildContext context) {
    return RefreshIndicator(
      child: SingleChildScrollView(
        child: Column(
          children: [
            ListView.builder(
              itemBuilder: (BuildContext context, int index) {
                return ListViewItem();
              },
            ),
          ],
        ),
      ),
      onRefresh: () async {},
    );

like this.

  •  Tags:  
  • Related