init static method
SwipeLockProvider
init({
- int times = 5,
- Duration lockoutDuration = const Duration(hours: 8),
- DateTime? now,
- bool lockoutRemainder = true,
- required OnSwipeLockProviderReader reader,
- required OnSwipeLockProviderWriter writer,
- OnSwipeLockProviderCounter? counter,
- OnSwipeLockProviderRemainder? remainder,
Initializes the SwipeLockProvider singleton instance.
Implementation
static SwipeLockProvider init({
int times = 5,
Duration lockoutDuration = const Duration(hours: 8),
DateTime? now,
bool lockoutRemainder = true,
required OnSwipeLockProviderReader reader,
required OnSwipeLockProviderWriter writer,
OnSwipeLockProviderCounter? counter,
OnSwipeLockProviderRemainder? remainder,
}) {
_instance ??= SwipeLockProvider._(
times: times,
lockoutRemainder: lockoutRemainder,
lockoutDuration: lockoutDuration,
reader: reader,
writer: writer,
counter: counter,
remainder: remainder,
);
instance._swipe = reader(_kSwipeLimitationTimes) ?? 0;
final lt = reader(_kSwipeLimitationTime) ?? 0;
now ??= DateTime.now();
if (instance._isLocked(now: now, lockoutTime: lt)) {
final x = DateTime.fromMillisecondsSinceEpoch(lt).difference(now);
final y = x > lockoutDuration ? lockoutDuration : x;
instance._startTimer(now: now, lockoutTime: lt, remainingDuration: y);
}
return instance;
}