updateItem method
Implementation
Future<void> updateItem(Map item, int index, {String idKey = '_id', Function? onSuccess, Function? onError}) async {
final controllers = <String, TextEditingController>{};
Map<String, dynamic> updatedItem = Map<String, dynamic>.from(item);
updatedItem.forEach((key, value) {
controllers[key] = TextEditingController(text: value.toString());
});
bool? isUpdated = await showDialog<bool>(
context: context,
builder: (dialogContext) => _buildUpdateDialog(
controllers, updatedItem, updatedItem.remove(idKey), index, idKey, onSuccess: onSuccess, onError: onError
),
);
if (isUpdated != null) {
showSnackBar(context, isUpdated ? 'Updated Successfully' : 'Failed to Update');
}
}