deleteItem method
Implementation
Future<bool> deleteItem(int? index) async {
try {
// get index
index ??= myDataSource?.data?.indexOf(data) ?? 0;
if (index < 0) index = 0;
if (index > items.length) index = items.length;
// lookup the item
var item = items.containsKey(index) ? items[index] : null;
if (item != null) {
// fire the rows onDelete event
bool ok = await item.onDeleteHandler();
// continue?
if (ok) {
// reorder hashmap
deleteInHashmap(items, index);
// remove the data associated with the row
notificationsEnabled = false;
myDataSource?.delete(index, notifyListeners: false);
data = myDataSource?.data ?? data;
notificationsEnabled = true;
// notify
data = myDataSource?.notify();
}
}
} catch (e) {
Log().exception(e);
}
return true;
}