feat: honestly forgot

This commit is contained in:
Alzalia 2025-08-11 22:41:15 +02:00
parent 48bcf0b1f8
commit da953ba651
19 changed files with 1097 additions and 244 deletions

View file

@ -1,9 +1,18 @@
import 'package:flutter/widgets.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:seshat/data/repositories/bal_repository.dart';
import 'package:seshat/domain/models/bal.dart';
import 'package:seshat/domain/models/book_instance.dart';
import 'package:seshat/utils/command.dart';
import 'package:seshat/utils/result.dart';
class SellViewModel extends ChangeNotifier {
SellViewModel();
SellViewModel({required BalRepository balRepository})
: _balRepository = balRepository {
load = Command0(_load)..execute();
}
final BalRepository _balRepository;
bool _showScan = false;
bool get showScan => _showScan;
@ -12,6 +21,12 @@ class SellViewModel extends ChangeNotifier {
notifyListeners();
}
/*
* ===============================
* =====[ BOOKS & INSTANCES ]=====
* ===============================
*/
final List<BookInstance> _scannedBooks = [];
get scannedBooks => _scannedBooks;
void scanBook(BarcodeCapture barcode) {
@ -36,4 +51,44 @@ class SellViewModel extends ChangeNotifier {
_scannedBooks.removeWhere((book) => book.id == id);
notifyListeners();
}
/*
* =================
* =====[ BAL ]=====
* =================
*/
Bal? _currentBal;
get currentBal => _currentBal;
/*
* =================================
* =====[ COMMAND AND LOADING ]=====
* =================================
*/
late final Command0 load;
bool isLoaded = false;
Future<Result<void>> _load() async {
final result2 = await _loadBal();
isLoaded = true;
notifyListeners();
return result2;
}
Future<Result<void>> _loadBal() async {
final result = await _balRepository.getBals();
switch (result) {
case Ok():
_currentBal = result.value
.where((bal) => bal.state == BalState.ongoing)
.firstOrNull;
break;
case Error():
break;
}
return result;
}
}