addMobileMoney function
Implementation
Future addMobileMoney(Map<String, dynamic> payload) async {
try{
String id = await getUserID();
final mobileMoney = await getRecords("mobileMoney");
String? deviceId = await getPlatformIdentifier();
print(deviceId);
payload.addAll({"userID": id, "deviceID": deviceId!});
if (mobileMoney.items.isNotEmpty) {
for (var element in mobileMoney.items) {
if (element.data['deviceID'] == deviceId) {
pocketBase
.collection('mobileMoney')
.update(element.id, body: payload)
.then((value) => {
showMsgSuccess("Mobile Money","Encrypted and saved successfully"),
print(value.data),
}
)
.onError((error, stackTrace) => {
showMsgFailed("Mobile Money","Failed to encrypt and save"),
});
}
}
} else {
pocketBase
.collection("mobileMoney")
.create(body: payload)
.then((value) => showMsgSuccess("Mobile Money","Encrypted and saved"))
.onError((error, stackTrace) => showMsgFailed("Mobile Money","Failed to encrypt and save"));
}
}catch (e){
showMsgFailed("Mobile Money","Something happened to prevent saving");
}
}