feat: compelete bal pending screen

This commit is contained in:
alzalia1 2025-08-14 01:02:39 +02:00
parent b12809ba93
commit 618764f513
4 changed files with 72 additions and 3 deletions

View file

@ -15,6 +15,22 @@ class BalViewModel extends ChangeNotifier {
Bal? _bal;
int? id;
Bal? get bal => _bal;
bool isABalOngoing = false;
Future<Result<void>> startBal(int id) async {
if (isABalOngoing) {
return Result.error(Exception("Cannot have multiple BALs ongoing !"));
}
final result = await _balRepository.startBal(id);
switch (result) {
case Ok():
_bal = result.value;
notifyListeners();
break;
default:
}
return result;
}
Future<Result<void>> editBal(
int id,
@ -46,6 +62,7 @@ class BalViewModel extends ChangeNotifier {
bool isLoaded = false;
Future<Result<void>> _load() async {
isABalOngoing = _balRepository.isABalOngoing();
final result1 = await _loadBal();
switch (result1) {
case Ok():

View file

@ -12,6 +12,7 @@ class BalPendingScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
bottomNavigationBar: AppNavigationBar(startIndex: 0),
appBar: AppBar(
@ -31,7 +32,15 @@ class BalPendingScreen extends StatelessWidget {
),
body: Center(
child: ElevatedButton(
onPressed: () {},
onPressed: viewModel.isABalOngoing
? () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Une BAL est déjà en cours.")),
);
}
: () {
viewModel.startBal(viewModel.bal!.id);
},
child: Text("Démarrer cette BAL"),
),
),