feat: add alot

This commit is contained in:
2026-10-08 04:12:36 +02:00
parent ccf5165417
commit fc607cb7bd
99 changed files with 4981 additions and 3655 deletions
+28 -23
View File
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import '../models/app_error.dart';
import '../services/pin_lock_service.dart';
import '../services/settings_service.dart';
@@ -14,7 +15,7 @@ class PinLockViewModel extends ChangeNotifier {
bool _isLoading = false;
bool _hasLoaded = false;
bool _pinRequired = true;
String? _errorMessage;
AppError? _error;
bool get isPinSet => _isPinSet;
@@ -26,7 +27,7 @@ class PinLockViewModel extends ChangeNotifier {
bool get pinRequired => _pinRequired;
String? get errorMessage => _errorMessage;
AppError? get error => _error;
void setPinRequired(bool value) {
if (_pinRequired == value) return;
@@ -45,7 +46,7 @@ class PinLockViewModel extends ChangeNotifier {
if (_isLoading) return;
_isLoading = true;
_errorMessage = null;
_error = null;
notifyListeners();
try {
@@ -58,7 +59,7 @@ class PinLockViewModel extends ChangeNotifier {
}
} catch (e) {
debugPrint('PinLockViewModel: load error: $e');
_errorMessage = 'Could not check PIN status.';
_error = AppError.checkPinStatus;
} finally {
_hasLoaded = true;
_isLoading = false;
@@ -67,7 +68,7 @@ class PinLockViewModel extends ChangeNotifier {
}
Future<bool> setPin(String pin) async {
_errorMessage = null;
_error = null;
try {
await pinLockService.setPin(pin);
@@ -85,14 +86,14 @@ class PinLockViewModel extends ChangeNotifier {
return true;
} catch (e) {
debugPrint('PinLockViewModel: setPin error: $e');
_errorMessage = 'Could not save PIN.';
_error = AppError.savePin;
notifyListeners();
return false;
}
}
Future<bool> verify(String pin) async {
_errorMessage = null;
_error = null;
try {
final matches = await pinLockService.verifyPin(pin);
@@ -103,12 +104,16 @@ class PinLockViewModel extends ChangeNotifier {
return true;
}
_errorMessage = 'Incorrect PIN.';
_error = AppError.incorrectPin;
notifyListeners();
return false;
} on PinLockedOutException {
_error = AppError.tooManyPinAttempts;
notifyListeners();
return false;
} catch (e) {
debugPrint('PinLockViewModel: verify error: $e');
_errorMessage = 'Could not verify PIN.';
_error = AppError.verifyPin;
notifyListeners();
return false;
}
@@ -118,25 +123,13 @@ class PinLockViewModel extends ChangeNotifier {
required String currentPin,
required String newPin,
}) async {
final currentMatches = await pinLockService.verifyPin(currentPin);
if (!currentMatches) {
_errorMessage = 'Current PIN is incorrect.';
notifyListeners();
return false;
}
if (!await _verifyCurrentPin(currentPin)) return false;
return setPin(newPin);
}
Future<bool> disablePin(String currentPin) async {
final matches = await pinLockService.verifyPin(currentPin);
if (!matches) {
_errorMessage = 'Current PIN is incorrect.';
notifyListeners();
return false;
}
if (!await _verifyCurrentPin(currentPin)) return false;
await pinLockService.clearPin();
_isPinSet = false;
@@ -152,6 +145,18 @@ class PinLockViewModel extends ChangeNotifier {
return true;
}
Future<bool> _verifyCurrentPin(String pin) async {
try {
if (await pinLockService.verifyPin(pin)) return true;
_error = AppError.currentPinIncorrect;
} on PinLockedOutException {
_error = AppError.tooManyPinAttempts;
}
notifyListeners();
return false;
}
void lock() {
if (!_isUnlocked) return;