feat: added authentification and redirection
This commit is contained in:
parent
1c9c5ce5fe
commit
ef641d4023
24 changed files with 731 additions and 173 deletions
|
|
@ -32,130 +32,137 @@ class _AddPageState extends State<AddPage> {
|
|||
// builder: (context, screen, child) {
|
||||
return Scaffold(
|
||||
bottomNavigationBar: AppNavigationBar(startIndex: 1),
|
||||
body: Stack(
|
||||
children: [
|
||||
ColoredBox(color: Colors.black),
|
||||
MobileScanner(
|
||||
controller: controller,
|
||||
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 {
|
||||
setState(() {
|
||||
price = newPrice;
|
||||
});
|
||||
}
|
||||
|
||||
Result<Book> result = await widget.viewModel.scanBook(barcodes);
|
||||
|
||||
switch (result) {
|
||||
case Ok():
|
||||
await _confirmationDialogBuilder(
|
||||
context,
|
||||
setPrice,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
result.value,
|
||||
);
|
||||
break;
|
||||
case Error():
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Erreur : ${result.error}"),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
),
|
||||
SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Center(
|
||||
child: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 50),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListenableBuilder(
|
||||
listenable: widget.viewModel,
|
||||
builder: (context, child) => ListTile(
|
||||
leading: Icon(Icons.person),
|
||||
title: TextButton(
|
||||
child: Text(
|
||||
(widget.viewModel.currentOwner == null)
|
||||
? "Aucun"
|
||||
: "${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}",
|
||||
),
|
||||
onPressed: () => _ownerDialogBuilder(
|
||||
context,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.attach_money),
|
||||
title: TextButton(
|
||||
child: Text(
|
||||
(widget.viewModel.askPrice)
|
||||
? "Demander à chaque fois"
|
||||
: "Prix libre toujours",
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
widget.viewModel.askPrice =
|
||||
!widget.viewModel.askPrice;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
body: ListenableBuilder(
|
||||
listenable: widget.viewModel,
|
||||
builder: (context, child) => switch (widget.viewModel.isLoaded) {
|
||||
false => CircularProgressIndicator(),
|
||||
true => Stack(
|
||||
children: [
|
||||
ColoredBox(color: Colors.black),
|
||||
MobileScanner(
|
||||
controller: controller,
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 100),
|
||||
SvgPicture.asset('assets/scan-overlay.svg'),
|
||||
],
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
void setPrice(num newPrice) async {
|
||||
setState(() {
|
||||
price = newPrice;
|
||||
});
|
||||
}
|
||||
|
||||
Result<Book> result = await widget.viewModel.scanBook(
|
||||
barcodes,
|
||||
);
|
||||
|
||||
switch (result) {
|
||||
case Ok():
|
||||
await _confirmationDialogBuilder(
|
||||
context,
|
||||
setPrice,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
result.value,
|
||||
);
|
||||
break;
|
||||
case Error():
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Erreur : ${result.error}"),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Center(
|
||||
child: TextButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
|
||||
),
|
||||
onPressed: () => _formDialogBuilder(
|
||||
context,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
),
|
||||
child: Text("Enregistrer manuellement"),
|
||||
SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Center(
|
||||
child: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 50),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.person),
|
||||
title: TextButton(
|
||||
child: Text(
|
||||
(widget.viewModel.currentOwner == null)
|
||||
? "Aucun"
|
||||
: "${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}",
|
||||
),
|
||||
onPressed: () => _ownerDialogBuilder(
|
||||
context,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.attach_money),
|
||||
title: TextButton(
|
||||
child: Text(
|
||||
(widget.viewModel.askPrice)
|
||||
? "Demander à chaque fois"
|
||||
: "Prix libre toujours",
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
widget.viewModel.askPrice =
|
||||
!widget.viewModel.askPrice;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 100),
|
||||
SvgPicture.asset('assets/scan-overlay.svg'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Center(
|
||||
child: TextButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
theme.cardColor,
|
||||
),
|
||||
),
|
||||
onPressed: () => _formDialogBuilder(
|
||||
context,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
),
|
||||
child: Text("Enregistrer manuellement"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
);
|
||||
// },
|
||||
|
|
|
|||
|
|
@ -141,11 +141,14 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
),
|
||||
SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
widget.viewModel.currentOwner = widget.viewModel
|
||||
.addOwner(firstName!, lastName!, contact!);
|
||||
await widget.viewModel.addOwner(
|
||||
firstName!,
|
||||
lastName!,
|
||||
contact!,
|
||||
);
|
||||
setState(() {
|
||||
showNewOwner = false;
|
||||
});
|
||||
|
|
|
|||
Reference in a new issue