1

I am using the scrollable_positioned_list as seen here https://pub.dev/packages/scrollable_positioned_list to scroll to a specific item when a notification occurs.

By default the builder take the index to identify which index to go to, but for my purpose i need to take the ID as identifier.

Is it possible to replace this :

itemScrollController.scrollTo(
          index: 3,
          duration: Duration(milliseconds: 500),
          curve: Curves.easeInOut,
        );

but to get to the ID of the object in the list ?

Mcflan_g
  • 61
  • 7

2 Answers2

0

try this:

    var items = list.where((element) => element.id == 'ID');
    if (items != null && items.isNotEmpty) {
      var index = list.indexOf(items.first);
      itemScrollController.scrollTo(
          index: 3,
          duration: Duration(milliseconds: 500),
          curve: Curves.easeInOut,
        );
    }
eamirho3ein
  • 16,619
  • 2
  • 12
  • 23
0
var item = itemList .where((ele) => ele.id == 'YOUR_ID');
    if (item != null && item.isNotEmpty) {
      var itemIndex = list.indexOf(item.first);
      itemScrollController.scrollTo(
          index: itemIndex ,
          duration: Duration(milliseconds: 500),
          curve: Curves.easeInOut,
        );
    }
Thusitha Deepal
  • 1,392
  • 12
  • 19