updateChamber method
Future<void>
updateChamber(
- String itemlistId,
- Chamber itemlist
)
override
Implementation
@override
Future<void> updateChamber(String itemlistId, Chamber itemlist) async {
AppConfig.logger.d("Updating to $itemlist");
try {
isLoading.value = true;
update([AppPageIdConstants.itemlist]);
String newName = newChamberNameController.text;
String newDesc = newChamberDescController.text;
if((newName.isNotEmpty && newName.toLowerCase() != itemlist.name.toLowerCase())
|| (newDesc.isNotEmpty && newDesc.toLowerCase() != itemlist.description.toLowerCase())) {
if(newChamberNameController.text.isNotEmpty) {
itemlist.name = newChamberNameController.text;
}
if(newChamberDescController.text.isNotEmpty) {
itemlist.description = newChamberDescController.text;
}
if(await ChamberFirestore().update(itemlist)){
AppConfig.logger.d("Chamber $itemlistId updated");
chambers[itemlist.id] = itemlist;
clearNewChamber();
AppUtilities.showSnackBar(
title: CommonTranslationConstants.itemlistPrefs.tr,
message: CommonTranslationConstants.itemlistUpdated.tr
);
} else {
AppConfig.logger.i("Something happens trying to update itemlist");
AppUtilities.showSnackBar(
title: CommonTranslationConstants.itemlistPrefs.tr,
message: MessageTranslationConstants.itemlistUpdatedErrorMsg.tr
);
}
} else {
AppUtilities.showSnackBar(
title: CommonTranslationConstants.itemlistPrefs.tr,
message: CommonTranslationConstants.itemlistUpdateSameInfo.tr
);
}
} catch (e) {
AppConfig.logger.e(e.toString());
AppUtilities.showSnackBar(
title: CommonTranslationConstants.itemlistPrefs.tr,
message: MessageTranslationConstants.itemlistUpdatedErrorMsg.tr
);
}
isLoading.value = false;
update([AppPageIdConstants.chamber]);
}