saveCustomSymptomsLogs function
dynamic
saveCustomSymptomsLogs({})
Save your own logs into DB
Implementation
saveCustomSymptomsLogs(
{required Map<String, dynamic>? userSymptomsData,
String userId = "0",
String symptomsLogDate = "",
required Function? onSuccess,
required Function? onError}) async {
String currentDate = "";
String logDate = "";
if (symptomsLogDate.isEmpty) {
var now = DateTime.now();
logDate = defaultDateFormat.format(now);
} else {
try {
logDate = symptomsLogDate;
} catch (e) {
throw "Invalid symptoms log date. Date format is yyyy-MM-dd";
}
}
final dbHelper = MenstrualCycleDbHelper.instance;
currentDate = currentDateFormat.format(DateTime.now());
String encryptedData =
Encryption.instance.encrypt(json.encode(userSymptomsData));
printLogs("encryptedData $encryptedData");
Map<String, dynamic> userData = {
MenstrualCycleDbHelper.columnUserId: userId,
MenstrualCycleDbHelper.columnUserEncryptDate: encryptedData,
MenstrualCycleDbHelper.columnLogDate: logDate,
MenstrualCycleDbHelper.columnCreatedDateTime: currentDate,
};
int id = await dbHelper.insertDailyLog(userData, logDate, userId);
printLogs("Save Id: $id");
if (id > 0) {
printLogs("Save Data");
if (onSuccess != null) {
onSuccess.call(id);
}
} else {
printLogs("False to save Data");
if (onError != null) {
onError.call();
}
}
}