feat: add an owner + sell screen
This commit is contained in:
parent
d2cbb43bcb
commit
073f8bd334
15 changed files with 354 additions and 82 deletions
|
|
@ -32,15 +32,14 @@ class AddViewModel extends ChangeNotifier {
|
|||
}
|
||||
|
||||
List<Owner> _owners = [];
|
||||
|
||||
List<Owner>? get owners => _owners;
|
||||
|
||||
Future<Result<Owner>> addOwner(
|
||||
String firstName,
|
||||
String lastName,
|
||||
String contact,
|
||||
) async {
|
||||
final result = await _ownerRepository.postOwner(
|
||||
debugPrint("\n\n\n\n(2) TRANFERRING\n\n\n\n");
|
||||
final result = await _ownerRepository.addOwner(
|
||||
firstName,
|
||||
lastName,
|
||||
contact,
|
||||
|
|
@ -52,7 +51,9 @@ class AddViewModel extends ChangeNotifier {
|
|||
|
||||
switch (secondResult) {
|
||||
case Ok():
|
||||
debugPrint("\n\n\n${secondResult.value.length}");
|
||||
_owners = secondResult.value;
|
||||
debugPrint("\n\n\n${_owners.length}");
|
||||
_currentOwner = result.value;
|
||||
notifyListeners();
|
||||
return Result.ok(result.value);
|
||||
|
|
@ -130,16 +131,7 @@ class AddViewModel extends ChangeNotifier {
|
|||
debugPrint("Oupsie daysie, ${result.error}");
|
||||
}
|
||||
notifyListeners();
|
||||
sub = _ownerRepository.liveOwners.listen((Owner owner) {
|
||||
debugPrint("\n\n\n\n[5] Updated UI : $owner\n\n\n\n");
|
||||
_owners.add(owner);
|
||||
_owners.sort(
|
||||
(a, b) => "${a.firstName} ${a.lastName}".compareTo(
|
||||
"${b.firstName} ${b.lastName}",
|
||||
),
|
||||
);
|
||||
notifyListeners();
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ class _AddPageState extends State<AddPage> {
|
|||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(height: 5),
|
||||
Center(
|
||||
child: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 50),
|
||||
|
|
@ -132,12 +133,11 @@ class _AddPageState extends State<AddPage> {
|
|||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 100),
|
||||
SvgPicture.asset('assets/scan-overlay.svg'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(child: SvgPicture.asset('assets/scan-overlay.svg')),
|
||||
SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
|
|
@ -157,6 +157,7 @@ class _AddPageState extends State<AddPage> {
|
|||
child: Text("Enregistrer manuellement"),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class OwnerPopup extends StatefulWidget {
|
|||
|
||||
class _OwnerPopupState extends State<OwnerPopup> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
bool showNewOwner = false;
|
||||
String? firstName;
|
||||
String? lastName;
|
||||
|
|
@ -25,6 +26,9 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
searchController.text = (widget.viewModel.currentOwner == null)
|
||||
? ""
|
||||
: "${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}";
|
||||
final theme = Theme.of(context);
|
||||
return ListenableBuilder(
|
||||
listenable: widget.viewModel,
|
||||
|
|
@ -35,19 +39,14 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
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 || widget.viewModel.owners!.isEmpty)
|
||||
? SizedBox()
|
||||
: DropdownMenu<Owner>(
|
||||
enableFilter: true,
|
||||
controller: searchController,
|
||||
label: Text("Rechercher un·e propriétaire"),
|
||||
requestFocusOnTap: true,
|
||||
dropdownMenuEntries: [
|
||||
for (var owner in widget.viewModel.owners!)
|
||||
DropdownMenuEntry(
|
||||
|
|
@ -65,7 +64,6 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
),
|
||||
),
|
||||
],
|
||||
initialSelection: widget.viewModel.currentOwner,
|
||||
onSelected: (Owner? owner) {
|
||||
widget.viewModel.currentOwner = owner;
|
||||
},
|
||||
|
|
@ -151,6 +149,7 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
if (showNewOwner) {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
debugPrint("\n\n\n\n(1) SENDING REQUEST\n\n\n\n");
|
||||
await widget.viewModel.addOwner(
|
||||
firstName!,
|
||||
lastName!,
|
||||
|
|
@ -160,9 +159,8 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
showNewOwner = false;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
widget.onPressAccept(context);
|
||||
}
|
||||
widget.onPressAccept(context);
|
||||
},
|
||||
child: Text("Valider"),
|
||||
),
|
||||
|
|
|
|||
Reference in a new issue