insertItem method
Implementation
Future<bool> insertItem(String? jsonOrXml, int? index) async {
try {
// get index
index ??= myDataSource?.data?.indexOf(data) ?? 0;
if (index < 0) index = 0;
if (index > items.length) index = items.length;
// add empty element to the data set
// important to do this first as
// get row model below depends on an entry
// in the dataset at specified index
notificationsEnabled = false;
myDataSource?.insert(jsonOrXml, index, notifyListeners: false);
data = myDataSource?.data ?? data;
notificationsEnabled = true;
// open up a space for the new model
insertInHashmap(items, index);
// create new row
var item = getItemModel(index);
// add row to rows
if (item != null) {
items[index] = item;
// fire the rows onInsert event
await item.onInsertHandler();
}
// notify
data = myDataSource?.notify();
} catch (e) {
Log().exception(e);
}
return true;
}