fix: continuing error managment and documentation

This commit is contained in:
alzalia1 2025-08-23 12:35:36 +02:00
parent 59e1c2558c
commit dad000a1b9
24 changed files with 389 additions and 182 deletions

View file

@ -18,18 +18,25 @@ class HomeViewModel extends ChangeNotifier {
* =================
*/
/// [List<Bal>] of all [Bal]
List<Bal> _bals = [];
/// [List<Bal>] of all [Bal]
List<Bal> get bals => _bals;
Bal? _currentBal;
Bal? get currentBal => _currentBal;
/// [Bal] currently [BalState.ongoing]
Bal? _ongoingBal;
/// [Bal] currently [BalState.ongoing]
Bal? get ongoingBal => _ongoingBal;
/// Creates a [Bal] from its [name], [startTime] and [endTime]
Future<Result<void>> createBal(
String name,
DateTime start,
DateTime end,
DateTime startTime,
DateTime endTime,
) async {
final result = await _balRepository.addBal(name, start, end);
final result = await _balRepository.addBal(name, startTime, endTime);
switch (result) {
case Ok():
final result2 = await _balRepository.getBals();
@ -54,9 +61,11 @@ class HomeViewModel extends ChangeNotifier {
* =================================
*/
/// Command to load all necessary data
late final Command0 load;
bool isLoaded = false;
/// Manages loaders
Future<Result<void>> _load() async {
final result2 = await _loadBal();
switch (result2) {
@ -70,12 +79,13 @@ class HomeViewModel extends ChangeNotifier {
return result2;
}
/// Loads data about [Bal]
Future<Result<void>> _loadBal() async {
final result = await _balRepository.getBals();
switch (result) {
case Ok():
_bals = result.value..sort((a, b) => a.compareTo(b));
_currentBal = _bals
_ongoingBal = _bals
.where((bal) => bal.state == BalState.ongoing)
.firstOrNull;
break;