fix: overflow + owner managment error
This commit is contained in:
parent
86094b5d76
commit
f8f1849d9d
4 changed files with 309 additions and 281 deletions
|
|
@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||||
import 'package:seshat/domain/models/book.dart';
|
import 'package:seshat/domain/models/book.dart';
|
||||||
import 'package:seshat/domain/models/book_instance.dart';
|
|
||||||
import 'package:seshat/domain/models/owner.dart';
|
import 'package:seshat/domain/models/owner.dart';
|
||||||
import 'package:seshat/utils/result.dart';
|
import 'package:seshat/utils/result.dart';
|
||||||
|
|
||||||
|
|
@ -12,6 +11,12 @@ class AddViewModel extends ChangeNotifier {
|
||||||
|
|
||||||
final _log = Logger("AddViewModel");
|
final _log = Logger("AddViewModel");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ====================
|
||||||
|
* =====[ OWNERS ]=====
|
||||||
|
* ====================
|
||||||
|
*/
|
||||||
|
|
||||||
Owner? _currentOwner;
|
Owner? _currentOwner;
|
||||||
Owner? get currentOwner => _currentOwner;
|
Owner? get currentOwner => _currentOwner;
|
||||||
set currentOwner(Owner? owner) {
|
set currentOwner(Owner? owner) {
|
||||||
|
|
@ -19,48 +24,22 @@ class AddViewModel extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Owner> _owners = [];
|
final List<Owner> _owners = [];
|
||||||
// Owner(
|
|
||||||
// firstName: "Jean",
|
|
||||||
// lastName: "Henri",
|
|
||||||
// contact: "contact@gmail.com",
|
|
||||||
// id: 1,
|
|
||||||
// ),
|
|
||||||
// Owner(
|
|
||||||
// firstName: "Jeanette",
|
|
||||||
// lastName: "Henriette",
|
|
||||||
// contact: "contact@gmail.com",
|
|
||||||
// id: 2,
|
|
||||||
// ),
|
|
||||||
// Owner(
|
|
||||||
// firstName: "Jacques",
|
|
||||||
// lastName: "Gerard",
|
|
||||||
// contact: "contact@gmail.com",
|
|
||||||
// id: 3,
|
|
||||||
// ),
|
|
||||||
// Owner(
|
|
||||||
// firstName: "Jacquelines",
|
|
||||||
// lastName: "Geraldine",
|
|
||||||
// contact: "contact@gmail.com",
|
|
||||||
// id: 4,
|
|
||||||
// ),
|
|
||||||
// Owner(
|
|
||||||
// firstName: "Louis",
|
|
||||||
// lastName: "Valentin",
|
|
||||||
// contact: "contact@gmail.com",
|
|
||||||
// id: 5,
|
|
||||||
// ),
|
|
||||||
// Owner(
|
|
||||||
// firstName: "Louise",
|
|
||||||
// lastName: "Valentine",
|
|
||||||
// contact: "contact@gmail.com",
|
|
||||||
// id: 6,
|
|
||||||
// ),
|
|
||||||
// ];
|
|
||||||
|
|
||||||
List<Owner>? get owners => _owners;
|
List<Owner>? get owners => _owners;
|
||||||
|
|
||||||
Owner addOwner(String firstName, String lastName, String contact) {
|
Owner addOwner(String firstName, String lastName, String contact) {
|
||||||
_owners!.add(
|
if (_owners.isEmpty) {
|
||||||
|
_owners.add(
|
||||||
|
Owner(
|
||||||
|
firstName: firstName,
|
||||||
|
lastName: lastName,
|
||||||
|
contact: contact,
|
||||||
|
id: 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_owners.add(
|
||||||
Owner(
|
Owner(
|
||||||
firstName: firstName,
|
firstName: firstName,
|
||||||
lastName: lastName,
|
lastName: lastName,
|
||||||
|
|
@ -68,6 +47,7 @@ class AddViewModel extends ChangeNotifier {
|
||||||
id: _owners.last.id + 1,
|
id: _owners.last.id + 1,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return Owner(
|
return Owner(
|
||||||
firstName: firstName,
|
firstName: firstName,
|
||||||
|
|
@ -77,6 +57,12 @@ class AddViewModel extends ChangeNotifier {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ===================
|
||||||
|
* =====[ PRICE ]=====
|
||||||
|
* ===================
|
||||||
|
*/
|
||||||
|
|
||||||
bool _askPrice = true;
|
bool _askPrice = true;
|
||||||
bool get askPrice => _askPrice;
|
bool get askPrice => _askPrice;
|
||||||
set askPrice(bool newValue) {
|
set askPrice(bool newValue) {
|
||||||
|
|
@ -84,6 +70,14 @@ class AddViewModel extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* =================================
|
||||||
|
* =====[ BOOKS AND INSTANCES ]=====
|
||||||
|
* =================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// Sends an api request with a [bacorde], then gets the [Book] that was
|
||||||
|
/// either created or retrieved. Sens the [Book] back wrapped in a [Result].
|
||||||
Future<Result<Book>> scanBook(BarcodeCapture barcode) async {
|
Future<Result<Book>> scanBook(BarcodeCapture barcode) async {
|
||||||
return Result.ok(
|
return Result.ok(
|
||||||
Book(
|
Book(
|
||||||
|
|
@ -96,5 +90,8 @@ class AddViewModel extends ChangeNotifier {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result<BookInstance> sendBook() {};
|
/// Sens an api request with
|
||||||
|
// Result<BookInstance> newBookInstance() {
|
||||||
|
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,18 @@ class _AddPageState extends State<AddPage> {
|
||||||
MobileScanner(
|
MobileScanner(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
onDetect: (barcodes) async {
|
onDetect: (barcodes) async {
|
||||||
|
if (widget.viewModel.currentOwner == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Attention : vous devez choisir un·e propriétaire",
|
||||||
|
),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void setPrice(num newPrice) async {
|
void setPrice(num newPrice) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
price = newPrice;
|
price = newPrice;
|
||||||
|
|
@ -68,13 +80,16 @@ class _AddPageState extends State<AddPage> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SafeArea(
|
SafeArea(
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: Card(
|
child: Card(
|
||||||
margin: EdgeInsets.symmetric(horizontal: 50),
|
margin: EdgeInsets.symmetric(horizontal: 50),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
ListenableBuilder(
|
ListenableBuilder(
|
||||||
listenable: widget.viewModel,
|
listenable: widget.viewModel,
|
||||||
|
|
@ -114,17 +129,29 @@ class _AddPageState extends State<AddPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(child: SizedBox()),
|
SizedBox(height: 100),
|
||||||
SvgPicture.asset('assets/scan-overlay.svg'),
|
SvgPicture.asset('assets/scan-overlay.svg'),
|
||||||
Expanded(child: SizedBox()),
|
],
|
||||||
TextButton(
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SafeArea(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: TextButton(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
|
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
|
||||||
),
|
),
|
||||||
onPressed: () =>
|
onPressed: () => _formDialogBuilder(
|
||||||
_formDialogBuilder(context, controller, widget.viewModel),
|
context,
|
||||||
|
controller,
|
||||||
|
widget.viewModel,
|
||||||
|
),
|
||||||
child: Text("Enregistrer manuellement"),
|
child: Text("Enregistrer manuellement"),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
title: Text("Prix"),
|
title: Text("Prix"),
|
||||||
content: Form(
|
content: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
|
@ -95,6 +96,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
||||||
listenable: widget.viewModel,
|
listenable: widget.viewModel,
|
||||||
builder: (context, child) => AlertDialog(
|
builder: (context, child) => AlertDialog(
|
||||||
title: Center(child: Text("Propriétaire du livre")),
|
title: Center(child: Text("Propriétaire du livre")),
|
||||||
content: Column(
|
content: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -157,6 +158,7 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
|
|
|
||||||
Reference in a new issue