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;

View file

@ -38,7 +38,7 @@ class _HomePageState extends State<HomePage> {
: ListView(
children: [
for (Bal bal in widget.viewModel.bals.where(
(el) => el.id != widget.viewModel.currentBal?.id,
(el) => el.id != widget.viewModel.ongoingBal?.id,
))
Padding(
padding: const EdgeInsets.symmetric(
@ -81,20 +81,20 @@ class _HomePageState extends State<HomePage> {
],
),
),
switch (widget.viewModel.currentBal == null) {
switch (widget.viewModel.ongoingBal == null) {
true => SizedBox(),
false => Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Card(
child: ListTile(
leading: Icon(Icons.event_available),
title: Text(widget.viewModel.currentBal!.name),
title: Text(widget.viewModel.ongoingBal!.name),
subtitle: Text("BAL en cours"),
trailing: IconButton(
onPressed: () {
_moveToBal(
context,
widget.viewModel.currentBal!.id,
widget.viewModel.ongoingBal!.id,
);
},
icon: Icon(Icons.arrow_forward),