Hi team,
I have taken the code given on the Flutterflow docs to reorder lists and it works perfectly for me for reordering strings in an array. https://docs.flutterflow.io/widgets-and-components/widgets/layout-elements/listview#reorder-list
Could you please help me with the modifications required to the code for reordering a list of data types?
I have created a data type named info_card
Inside this data type, I have 2 fields below
info_card_title
info_card_description
I am using a page state variable to store the values which I want to reorder.
Would be very thankful if you could help me out.
below is the code from the docs
// Define a function called reorderItems that returns a Future of a list of strings.
// It takes in a list of strings, an old index, and a new index as parameters.
Future<List<String>> reorderItems(
List<String> list,
int oldIndex,
int newIndex,
) async {
// If the item is being moved to a position further down the list
// (i.e., to a higher index), decrement the newIndex by 1.
// This adjustment is needed because removing an item from its original
// position will shift the indices of all subsequent items.
if (oldIndex < newIndex) {
newIndex -= 1;
}
// Remove the item from its original position in the list and store
// it in the 'item' variable.
final item = list.removeAt(oldIndex);
// Insert the removed item into its new position in the list.
list.insert(newIndex, item);
// Return the modified list.
return list;
}