saveCustomSymptomsLogs method

dynamic saveCustomSymptomsLogs({
  1. required Map<String, dynamic>? userSymptomsData,
  2. String symptomsLogDate = "",
  3. required Function? onSuccess,
  4. required Function? onError,
})

Sae your own logs into DB

Implementation

saveCustomSymptomsLogs(
    {required Map<String, dynamic>? userSymptomsData,
    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 Strings.errorInvalidSymptomsLogDate;
    }
  }

  final dbHelper = MenstrualCycleDbHelper.instance;

  currentDate = currentDateFormat.format(DateTime.now());

  String encryptedData =
      Encryption.instance.encrypt(json.encode(userSymptomsData));
  final instance = MenstrualCycleWidget.instance!;

  String encryptedUserid = instance.getCustomerId();

  //printLogs(("encryptedData $encryptedData");

  Map<String, dynamic> userData = {
    MenstrualCycleDbHelper.columnCustomerId: encryptedUserid,
    MenstrualCycleDbHelper.columnUserEncryptData: encryptedData,
    MenstrualCycleDbHelper.columnLogDate: logDate,
    MenstrualCycleDbHelper.columnCreatedDateTime: currentDate,
  };

  // TODO set customLog tags to identify custom logs data
  int id = await dbHelper.insertDailyLog(userData, logDate, encryptedUserid);
  //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();
    }
  }
}