Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why only the content in ListView.builder() is not scrolling?

I have a screen with Text widgets and ListView, and when I try to scroll inside the ListView, it doesn't allow me to scroll.

My body is SingleChildScrollView but that doesn't provide scrollView for the ListView.builder. I tried to wrap the ListView.build inside Expanded, but didn't work out.

class HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          title: Text("MyBar"),
          centerTitle: true,
        ),
        body: SingleChildScrollView(child: Column(
          children: <Widget>[
            Text(
                "Information"),
            Container(
                child: ListView.builder(
                    scrollDirection: Axis.vertical,
                    shrinkWrap: true,
                    itemCount: widget.match.players.length,
                    itemBuilder: (context, index) {
                      return Column(
                        children: <Widget>[
                          Card(
                              child: ListTile(
                            leading: CircleAvatar(
                              radius: 30.0,
                              foregroundColor: 
                                Theme.of(context).primaryColor,
                              backgroundColor: Colors.grey,
                              backgroundImage: 
                          CachedNetworkImageProvider("url"),
                            ),
                            title: new Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: <Widget>[
                                  new Text("Some text",
                                    style: new TextStyle(
                                        fontWeight: FontWeight.bold),
                                  ),
                                  new Text(
                                    "Some text",
                                    style: new TextStyle(
                                        fontWeight: FontWeight.bold),
                                  ),
                                ]),

                          ))
                        ],
                      );
                    }))
          ],
        )));}
  } 

Anyone has an idea how I can make the listView.builder() scrollable.

like image 264
Antoni Dobrenov Avatar asked Oct 31 '19 09:10

Antoni Dobrenov


People also ask

Is ListView builder scrollable?

ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView. If non-null, the itemExtent forces the children to have the given extent in the scroll direction.

How do I make my ListView builder not scrollable?

You can make the ListView widget never scrollable by setting physics property to NeverScrollableScrollPhysics().

How do I scroll to a specific item in ListView flutter?

All you have to do is set Global Keys for your widgets and call Scrollable. ensureVisible on the key of your widget you want to scroll to. For this to work your ListView should be a finite List of objects.

How do I scroll ListView horizontally in flutter?

To scroll a Flutter ListView widget horizontally, set scrollDirection property of the ListView widget to Axis. horizontal. This arranges the items side by side horzontally. Following is the basic syntax to arrange the items horizontally in a ListView and scroll them horizontally.


1 Answers

You need to make the ListView.builder not scrollable so the SingleChildScrollView can scroll. You could achieve that by setting one of these two properties to the ListView.builder:

physics: NeverScrollableScrollPhysics()

or

primary: false

But using the ListView.builder the way you're using it, it will create all the items at once. If you want to use the ListView.builder efficiently to create the items only when they're scrolled onto the screen, you could remove the SingleChildScrollView and just use ListView.builder like this:

ListView.builder(
  itemCount: widget.match.players.length + 1,
  itemBuilder: (context, index) {
    if (index == 0) {
      return Text("Information");
    }
    int listIndex = index - 1;
    // then you could use: widget.match.players[listIndex];
    return Column(...);
  }
)
like image 155
Pablo Barrera Avatar answered Oct 20 '22 12:10

Pablo Barrera