first commit
This commit is contained in:
commit
faf67cc6d8
148 changed files with 6580 additions and 0 deletions
75
lib/ui/add_page/view_model/add_view_model.dart
Normal file
75
lib/ui/add_page/view_model/add_view_model.dart
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:seshat/domain/models/owner.dart';
|
||||
|
||||
class AddViewModel extends ChangeNotifier {
|
||||
AddViewModel();
|
||||
|
||||
final _log = Logger("AddViewModel");
|
||||
|
||||
Owner? _currentOwner;
|
||||
Owner? get currentOwner => _currentOwner;
|
||||
set currentOwner(Owner? owner) {
|
||||
_currentOwner = owner;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
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;
|
||||
Owner addOwner(String firstName, String lastName, String contact) {
|
||||
_owners!.add(
|
||||
Owner(
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
contact: contact,
|
||||
id: _owners!.last.id + 1,
|
||||
),
|
||||
);
|
||||
notifyListeners();
|
||||
return Owner(
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
contact: contact,
|
||||
id: 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
120
lib/ui/add_page/widgets/add_page.dart
Normal file
120
lib/ui/add_page/widgets/add_page.dart
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:seshat/ui/add_page/view_model/add_view_model.dart';
|
||||
import 'package:seshat/ui/add_page/widgets/owner_popup.dart';
|
||||
import 'package:seshat/ui/core/ui/navigation_bar.dart';
|
||||
|
||||
class AddPage extends StatefulWidget {
|
||||
const AddPage({super.key, required this.viewModel});
|
||||
|
||||
final AddViewModel viewModel;
|
||||
|
||||
@override
|
||||
State<AddPage> createState() => _AddPageState();
|
||||
}
|
||||
|
||||
class _AddPageState extends State<AddPage> {
|
||||
bool askPrice = true;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final MobileScannerController controller = MobileScannerController(
|
||||
formats: [BarcodeFormat.ean13],
|
||||
detectionTimeoutMs: 1000,
|
||||
);
|
||||
// return Consumer<TabScreen>(
|
||||
// builder: (context, screen, child) {
|
||||
return Scaffold(
|
||||
bottomNavigationBar: AppNavigationBar(startIndex: 1),
|
||||
body: Stack(
|
||||
children: [
|
||||
ColoredBox(color: Colors.black),
|
||||
MobileScanner(
|
||||
controller: controller,
|
||||
onDetect: (barcodes) {
|
||||
onBarcodeScan(barcodes, controller);
|
||||
},
|
||||
),
|
||||
SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Center(
|
||||
child: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 50),
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.person),
|
||||
title: TextButton(
|
||||
child: Text("No"),
|
||||
onPressed: () => _ownerDialogBuilder(
|
||||
context,
|
||||
controller,
|
||||
widget.viewModel,
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.attach_money),
|
||||
title: TextButton(
|
||||
child: Text(
|
||||
(askPrice)
|
||||
? "Demander à chaque fois"
|
||||
: "Prix libre toujours",
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
askPrice = !askPrice;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: SizedBox()),
|
||||
SvgPicture.asset('assets/scan-overlay.svg'),
|
||||
Expanded(child: SizedBox()),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: Text("Enregistrer manuellement"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
// },
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
void onBarcodeScan(
|
||||
BarcodeCapture barcodes,
|
||||
MobileScannerController controller,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
Future<void> _ownerDialogBuilder(
|
||||
BuildContext context,
|
||||
MobileScannerController controller,
|
||||
AddViewModel viewModel,
|
||||
) {
|
||||
controller.stop();
|
||||
|
||||
void onPressAccept(BuildContext localContext) {
|
||||
controller.start();
|
||||
Navigator.of(localContext).pop();
|
||||
}
|
||||
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) =>
|
||||
OwnerPopup(viewModel: viewModel, onPressAccept: onPressAccept),
|
||||
);
|
||||
}
|
||||
0
lib/ui/add_page/widgets/form_screen.dart
Normal file
0
lib/ui/add_page/widgets/form_screen.dart
Normal file
172
lib/ui/add_page/widgets/owner_popup.dart
Normal file
172
lib/ui/add_page/widgets/owner_popup.dart
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:seshat/domain/models/owner.dart';
|
||||
import 'package:seshat/ui/add_page/view_model/add_view_model.dart';
|
||||
|
||||
class OwnerPopup extends StatefulWidget {
|
||||
const OwnerPopup({
|
||||
super.key,
|
||||
required this.viewModel,
|
||||
required this.onPressAccept,
|
||||
});
|
||||
|
||||
final AddViewModel viewModel;
|
||||
final Function(BuildContext) onPressAccept;
|
||||
|
||||
@override
|
||||
State<OwnerPopup> createState() => _OwnerPopupState();
|
||||
}
|
||||
|
||||
class _OwnerPopupState extends State<OwnerPopup> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
bool showNewOwner = false;
|
||||
String? firstName;
|
||||
String? lastName;
|
||||
String? contact;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return ListenableBuilder(
|
||||
listenable: widget.viewModel,
|
||||
builder: (context, child) => AlertDialog(
|
||||
title: Center(child: Text("Propriétaire du livre")),
|
||||
content: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
(widget.viewModel.currentOwner == null)
|
||||
? "Choix actuel : aucun"
|
||||
: "Choix actuel : ${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}",
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
(showNewOwner)
|
||||
? SizedBox()
|
||||
: DropdownMenu<Owner>(
|
||||
enableFilter: true,
|
||||
label: Text("Rechercher un·e propriétaire"),
|
||||
dropdownMenuEntries: [
|
||||
for (var owner in widget.viewModel.owners!)
|
||||
DropdownMenuEntry(
|
||||
value: owner,
|
||||
label: "${owner.firstName} ${owner.lastName}",
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
(widget.viewModel.currentOwner == owner)
|
||||
? WidgetStatePropertyAll<Color>(
|
||||
theme.highlightColor,
|
||||
)
|
||||
: WidgetStatePropertyAll<Color>(
|
||||
theme.canvasColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
initialSelection: widget.viewModel.currentOwner,
|
||||
onSelected: (Owner? owner) {
|
||||
widget.viewModel.currentOwner = owner;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showNewOwner = !showNewOwner;
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
(showNewOwner) ? "Annuler" : "Ajouter un propriétaire",
|
||||
),
|
||||
),
|
||||
(!showNewOwner)
|
||||
? SizedBox()
|
||||
: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Nom",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
lastName = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un nom";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Prénom",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
firstName = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un prénom";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Contact",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
contact = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un moyen de contact";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
setState(() {
|
||||
widget.viewModel.currentOwner = widget.viewModel
|
||||
.addOwner(firstName!, lastName!, contact!);
|
||||
showNewOwner = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text("Créer"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
widget.onPressAccept(context);
|
||||
},
|
||||
child: Text("Valider"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
75
lib/ui/add_page/widgets/scan_screen.dart
Normal file
75
lib/ui/add_page/widgets/scan_screen.dart
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// class ScanPage extends StatefulWidget {
|
||||
// const ScanPage({super.key});
|
||||
|
||||
// @override
|
||||
// State<ScanPage> createState() => _ScanPage();
|
||||
// }
|
||||
|
||||
// class _ScanPage extends State<ScanPage> {
|
||||
// final MobileScannerController controller = MobileScannerController(
|
||||
// detectionTimeoutMs: 1000,
|
||||
// );
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Stack(
|
||||
// children: <Widget>[
|
||||
// MobileScanner(
|
||||
// controller: controller,
|
||||
// onDetect: (result) {
|
||||
// print(result.barcodes.first.rawValue);
|
||||
// },
|
||||
// ),
|
||||
// SafeArea(
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// Center(
|
||||
// child: Card(
|
||||
// margin: EdgeInsets.symmetric(horizontal: 50),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// Consumer<TabScreen>(
|
||||
// builder: (context, screen, child) {
|
||||
// return ListTile(
|
||||
// leading: Icon(Icons.person),
|
||||
// title: TextButton(
|
||||
// child: Text("No"),
|
||||
// onPressed: () {
|
||||
// screen.change("ownerPage");
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// ListTile(
|
||||
// leading: Icon(Icons.attach_money),
|
||||
// title: TextButton(
|
||||
// child: Text("Demander à chaque fois"),
|
||||
// onPressed: () {
|
||||
// return;
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Expanded(child: SizedBox()),
|
||||
// SvgPicture.asset('assets/scan-overlay.svg'),
|
||||
// Expanded(child: SizedBox()),
|
||||
// TextButton(
|
||||
// onPressed: () {},
|
||||
// child: Text("Enregistrer manuellement"),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
Reference in a new issue