Swaroop Sambhayya
Swaroop Sambhayya

Reputation: 81

Scroll Controller is not listening to scroll in Flutter

Im trying to listen to scroll for lazy loading but im not getting any Listen values,I have used ListView.builder widget and have attached a scroll contoller (_controller) and have instantiated controller in initState() method, need help with the issue

class _FeedsState extends State<Feeds> {
  ScrollController _controller;
  int pageNumber = 1;

  @override
  void initState() {
    super.initState();
    _controller = new ScrollController();
    _controller.addListener(scrollListener);

    SchedulerBinding.instance.addPostFrameCallback((_) {
      _controller.animateTo(
        0.0,
        duration: const Duration(milliseconds: 10),
        curve: Curves.easeOut,
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    print(widget.feedDetails);
    return widget.feedDetails.length == 0
        ? PostSomething(
            isAdmin: widget.isAdmin,
          )
        : ListView.builder(
            shrinkWrap: true,
            controller: _controller,
            itemBuilder: (context, index) {
              return Column(
                children: [
                  index == 0
                      ? PostSomething(
                          isAdmin: widget.isAdmin,
                          profilePic: widget.feedDetails[0]["profile_pic"])
                      : Container(),
                  (Posts(
                    index: index,
                    feedDetails: widget.feedDetails[index],
                    displayProfileNavigation: widget.displayProfileNavigation,
                  )),
                ],
              );
            },
            itemCount: widget.feedDetails.length,
          );
  }

  void scrollListener() {
    print("Scrolling");
    if (_controller.position.pixels == _controller.position.maxScrollExtent) {
      print("Coooool");
    }
  }
}

Upvotes: 4

Views: 3083

Answers (1)

shorol
shorol

Reputation: 1000

make: shrinkWrap: false,, this will enable your scrolling,

if this show unbounded height exception, then try

return Scaffold(
        body: Expanded(
        ListView.builder(....your code..

Upvotes: 5

Related Questions