This repository has been archived on 2025-08-25. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Seshat/lib/ui/add_page/view_model/add_view_model.dart

100 lines
2.4 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:mobile_scanner/mobile_scanner.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/utils/result.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,
);
}
bool _askPrice = true;
bool get askPrice => _askPrice;
set askPrice(bool newValue) {
_askPrice = newValue;
notifyListeners();
}
Future<Result<Book>> scanBook(BarcodeCapture barcode) async {
return Result.ok(
Book(
author: "Patrick K. Dewdney",
ean: barcode.barcodes.first.rawValue!,
id: 56,
priceNew: "50 EUR",
title: "Les chiens et la charrue",
),
);
}
// Result<BookInstance> sendBook() {};
}