selectable_items is the package that provides the type SelectableItems, which encapsulates a list of items and a selected one. Note that it is immutable.

Features

N / A

Getting started

This package depends on the freezed and freezed_annotation package.

Usage

Initialize

final selectedItems = SelectableItems(
    currentIndex: 0,
    items: [1, 2, 3, 4, 5],
)

Get the current item

print(selectableItems.currentItem); // 1

Selects an item

final newSelectedItems = selectedItems.selectItem(2);
print(newSelectedItems.currentItem); // 3

Inserts an item

By default, insertItem inserts an item to the end of the list and set the current item index to the end of list. When given an index, it inserts the item to the specified index and sets the current item index to the given index.

final newSelectedItems = selectedItems.insertItem(10);
print(newSelectedItems.items); // [1, 2, 3, 4, 5, 10]
print(newSelectedItems.currentItem); // 10

Deletes an item

Deletes the item at the specified index.

final newSelectedItems = selectedItems.deleteItem(2);
print(newselectedItems.items); // [1, 2, 4, 5];
print(newSelectedItems.currentItem); // 2

Modifies an item

final newSelectedItems = selectedItems.modifyItem(0, 10);
print(newselectedItems.items); // [10, 2, 3, 4, 5];
print(newSelectedItems.currentItem); // 10

Additional information

N/A

Libraries

selectable_items
Support for doing something awesome.