Programmatically scrolling to the end of a ListView

前端 未结 7 1928
既然无缘
既然无缘 2020-11-27 13:03

I have a scrollable ListView where the number of items can change dynamically. Whenever a new item is added to the end of the list, I would like to programmatic

相关标签:
7条回答
  • 2020-11-27 13:59

    I have so much problem trying to use the scroll controller to go to the bottom of the list that I use another approach.

    Instead of creating an event to send the list to the bottom, I change my logic to use a reversed list.

    So, each time I have a new item, I simply, made at insert at the top of the list.

    // add new message at the begin of the list 
    list.insert(0, message);
    // ...
    
    // pull items from the database
    list = await bean.getAllReversed(); // basically a method that applies a descendent order
    
    // I remove the scroll controller
    new Flexible(
      child: new ListView.builder(
        reverse: true, 
        key: new Key(model.count().toString()),
        itemCount: model.count(),
        itemBuilder: (context, i) => ChatItem.displayMessage(model.getItem(i))
      ),
    ),
    
    0 讨论(0)
提交回复
热议问题