addMobileMoney function

Future addMobileMoney(
  1. Map<String, dynamic> payload
)

Implementation

Future addMobileMoney(Map<String, dynamic> payload) async {
  String id = await getUserID();
  final mobileMoney = await getRecords("mobileMoney");
  String? deviceId = await getPlatformIdentifier();
  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) => print("success"))
            .onError((error, stackTrace) => print("error---$error"));
      }
    }
  } else {
    pocketBase
        .collection("mobileMoney")
        .create(body: payload)
        .then((value) => print("success"))
        .onError((error, stackTrace) => print("error---$error"));
  }
}