How to add the 'pinned item' functionality, similar to Google Keep, on a ListView?
I tried doing 2 list view, and putting the pinned one on top of a Column. But the problem is they scrolled separately, and if I wrapped the column in a Singlechildscrollview, it just gives error.
Am I on the right track of doing it or there is a way by just using a single list view?
CodePudding user response:
Implement if you want:
- add an extra field to your object: bool pinned -> then you sort the list to make sure the pinned items are on top of the list
- put a GestureDetector around the item and use the onTap to set the
pinned
value -> pinned = !pinned
Or try this package I just found:
https://pub.dev/packages/pinnable_listview
CodePudding user response:
I think I got the Singlechildscrollview worked the way I want it to. I just have to set the ListView shrinkWrap: true
, and physics: NeverScrollableScrollPhysics()
. I'm not sure if this is a good idea tho, since most people say that shrinkWrap is quite a heavy operation to use.
SingleChildScrollView(
physics: ScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Pinned'),
PinnedListItemHere(), //ListView of Pinned Items
Divider(
height: 25.0,
thickness: 2.0,
),
Text('Others'),
UnpinnedListItemHere(), //ListView of Unpinned Items
],
),
),