updateConfiguration method
void
updateConfiguration({})
Update configuration of MenstrualCycleWidget
Implementation
void updateConfiguration(
{required int? cycleLength,
required int? periodDuration,
String? customerId = "0",
DateTime? lastPeriodDate,
bool isClearData = false,
String fontFamily = "",
DateFormats dateFormat = DateFormats.dmy,
Languages defaultLanguage = Languages.english}) async {
assert(cycleLength! > 0, WidgetBaseLanguage.totalCycleDaysLabel);
assert(periodDuration! > 0, WidgetBaseLanguage.totalPeriodDaysLabel);
// printLogs("userId $userId");
if (customerId!.isNotEmpty) {
_customerId = customerId;
}
initializeDateFormatting();
if (fontFamily.isNotEmpty) {
defaultFontFamily = fontFamily;
}
currentLanguage = defaultLanguage;
_currentDateFormat = dateFormat;
_cycleLength = cycleLength!;
_periodDuration = periodDuration!;
final dbHelper = MenstrualCycleDbHelper.instance;
// Clear Past log data
if (isClearData) {
String customerId = getCustomerId();
await dbHelper.clearPeriodLog(customerId);
}
// insert current user details
await dbHelper.insertCurrentUserDetails(
customerId: Encryption.instance.encrypt(_customerId),
cycleLength: _cycleLength,
periodDuration: _periodDuration);
// Generate periods days based on last selected period date
if (lastPeriodDate != null) {
bool isFoundDate = await dbHelper.isPeriodDateFound(lastPeriodDate);
if (!isFoundDate) {
List<DateTime> selectedPeriodsDate = [];
DateTime lastPeriodDateTime = lastPeriodDate;
selectedPeriodsDate.add(lastPeriodDateTime);
for (int i = 1; i < periodDuration; i++) {
lastPeriodDateTime = lastPeriodDateTime.add(const Duration(days: 1));
selectedPeriodsDate.add(lastPeriodDateTime);
}
await dbHelper.insertPeriodLog(selectedPeriodsDate);
}
}
calculateLastPeriodDate();
}