4

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");
    }
  }
}

1 Answer 1

5

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

if this show unbounded height exception, then try

return Scaffold(
        body: Expanded(
        ListView.builder(....your code..
Sign up to request clarification or add additional context in comments.

8 Comments

its showing unbounded height exception eventhough i add Scaffold as parent
put your ListView.builder into the Expanded widget. It will solve the unbounded height exception.
can you please check by removing PostSomething widgets, just your scrolling and scroll listener is working or not?
if it works, then your PostSomething() widget need to be wrap in expanded widget.
Problem Solved!shrinkWrap=false and Expanded/Flexible solves problem,Thank you
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.