Mindinventory / flutter_draggable_gridview

This package supports drag & drop widgets inside the GridView.builder for multiplatform. It provides all the properties which are available in Gridview. builder and easy to implement with the few lines of code.
https://www.mindinventory.com/flutter-app-development.php
MIT License
100 stars 19 forks source link

Added an Index to DraggableGridItem #25

Open Michael2543 opened 8 months ago

Michael2543 commented 8 months ago

Hi,

I made a straightforward change to your package - I added an Index to DraggableGridItem. This change allows Shared Preferences to store the list of DraggableGridItems and sort them accordingly.

Please feel free to dismiss the pull request and bear with me if I did something wrong: it's my first pull request for a package. :) (I also had to add some properties to DragTargetGrid, these were mandatory by the compiler)

Thanks for your great package!

Michael

Sorting Example:

Future onDragAccept( List list, int beforeIndex, int afterIndex) async { List indexes = []; for (var item in list) { indexes.add(item.index.toString()); } prefs.setStringList('indexes', indexes); } }


if (prefs.getStringList('indexes') != null) { List indexes = prefs.getStringList('indexes')!; draggableGridItems.sort((a, b) => indexes .indexOf(a.index.toString()) .compareTo(indexes.indexOf(b.index.toString()))); }