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;
}
}

View file

@ -5,9 +5,9 @@ import 'package:seshat/ui/sell_page/view_model/sell_view_model.dart';
import 'package:seshat/ui/sell_page/widgets/manual_scan_popup.dart';
class ScanScreen extends StatefulWidget {
ScanScreen({super.key, required this.viewModel});
const ScanScreen({super.key, required this.viewModel});
SellViewModel viewModel;
final SellViewModel viewModel;
@override
State<ScanScreen> createState() => _ScanScreenState();

View file

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:seshat/domain/models/book_instance.dart';
import 'package:seshat/routing/routes.dart';
import 'package:seshat/ui/core/ui/navigation_bar.dart';
import 'package:seshat/ui/sell_page/view_model/sell_view_model.dart';
import 'package:seshat/ui/sell_page/widgets/scan_screen.dart';
@ -21,93 +23,133 @@ class _SellPageState extends State<SellPage> {
body: ListenableBuilder(
listenable: widget.viewModel,
builder: (context, child) {
return Stack(
children: [
SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 6),
Expanded(
child: ListView(
children: [
for (BookInstance bookInstance
in widget.viewModel.scannedBooks)
Card(
child: ListTile(
leading: Text(
"${bookInstance.price.toString()}",
style: TextStyle(fontSize: 30),
),
title: Text(
"Les chiens et la charrue · Patrick K. Dewdney ${bookInstance.id}",
),
subtitle: Text("Union Étudiante Auvergne"),
trailing: IconButton(
onPressed: () {
widget.viewModel.deleteBook(
bookInstance.id,
);
},
icon: Icon(Icons.delete),
),
),
),
],
return switch (widget.viewModel.isLoaded) {
false => Center(child: CircularProgressIndicator()),
true => switch (widget.viewModel.currentBal) {
null => Center(
child: SizedBox(
width: 300,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Aucune bal n'est active.",
style: TextStyle(fontSize: 25),
textAlign: TextAlign.center,
),
),
SizedBox(height: 40),
Text("Somme minimum requise : 20€"),
SizedBox(
width: 400,
child: TextField(
decoration: InputDecoration(
labelText: "Argent reçu",
helperText:
"L'argent reçu sera réparti automatiquement",
suffixText: "",
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
SizedBox(height: 15),
Text(
"Vous devez créer puis activer une BAL pour pouvoir scanner des livres.",
textAlign: TextAlign.center,
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {
widget.viewModel.sendSell();
},
icon: Icon(Icons.check),
style: ButtonStyle(
iconSize: WidgetStatePropertyAll(70),
),
),
SizedBox(width: 70),
IconButton(
onPressed: () {
widget.viewModel.showScan = true;
},
icon: Icon(Icons.add),
style: ButtonStyle(
iconSize: WidgetStatePropertyAll(70),
elevation: WidgetStatePropertyAll(50),
),
),
],
),
SizedBox(height: 5),
],
SizedBox(height: 30),
ElevatedButton(
onPressed: () {
context.go(Routes.home);
},
child: Text("Gérer les BALs"),
),
],
),
),
),
_ => Stack(
children: [
SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 6),
Expanded(
child: ListView(
children: [
for (BookInstance bookInstance
in widget.viewModel.scannedBooks)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15,
),
child: Card(
child: ListTile(
leading: Text(
"${bookInstance.price.toString()}",
style: TextStyle(fontSize: 30),
),
title: Text(
"Les chiens et la charrue · Patrick K. Dewdney ${bookInstance.id}",
),
subtitle: Text(
"Union Étudiante Auvergne",
),
trailing: IconButton(
onPressed: () {
widget.viewModel.deleteBook(
bookInstance.id,
);
},
icon: Icon(Icons.delete),
),
),
),
),
],
),
),
SizedBox(height: 40),
Text("Somme minimum requise : 20€"),
SizedBox(
width: 400,
child: TextField(
decoration: InputDecoration(
labelText: "Argent reçu",
helperText:
"L'argent reçu sera réparti automatiquement",
suffixText: "",
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {
widget.viewModel.sendSell();
},
icon: Icon(Icons.check),
style: ButtonStyle(
iconSize: WidgetStatePropertyAll(70),
),
),
SizedBox(width: 70),
IconButton(
onPressed: () {
widget.viewModel.showScan = true;
},
icon: Icon(Icons.add),
style: ButtonStyle(
iconSize: WidgetStatePropertyAll(70),
elevation: WidgetStatePropertyAll(50),
),
),
],
),
SizedBox(height: 5),
],
),
),
(widget.viewModel.showScan)
? ScanScreen(viewModel: widget.viewModel)
: SizedBox(),
],
);
(widget.viewModel.showScan)
? ScanScreen(viewModel: widget.viewModel)
: SizedBox(),
],
),
},
};
},
),
);