97 lines
2.2 KiB
Dart
97 lines
2.2 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/owner.dart';
|
|
import 'package:seshat/utils/result.dart';
|
|
|
|
class AddViewModel extends ChangeNotifier {
|
|
AddViewModel();
|
|
|
|
final _log = Logger("AddViewModel");
|
|
|
|
/*
|
|
* ====================
|
|
* =====[ OWNERS ]=====
|
|
* ====================
|
|
*/
|
|
|
|
Owner? _currentOwner;
|
|
Owner? get currentOwner => _currentOwner;
|
|
set currentOwner(Owner? owner) {
|
|
_currentOwner = owner;
|
|
notifyListeners();
|
|
}
|
|
|
|
final List<Owner> _owners = [];
|
|
|
|
List<Owner>? get owners => _owners;
|
|
|
|
Owner addOwner(String firstName, String lastName, String contact) {
|
|
if (_owners.isEmpty) {
|
|
_owners.add(
|
|
Owner(
|
|
firstName: firstName,
|
|
lastName: lastName,
|
|
contact: contact,
|
|
id: 1,
|
|
),
|
|
);
|
|
} else {
|
|
_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,
|
|
);
|
|
}
|
|
|
|
/*
|
|
* ===================
|
|
* =====[ PRICE ]=====
|
|
* ===================
|
|
*/
|
|
|
|
bool _askPrice = true;
|
|
bool get askPrice => _askPrice;
|
|
set askPrice(bool newValue) {
|
|
_askPrice = newValue;
|
|
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 {
|
|
return Result.ok(
|
|
Book(
|
|
author: "Patrick K. Dewdney",
|
|
ean: barcode.barcodes.first.rawValue!,
|
|
id: 56,
|
|
priceNew: "50 EUR",
|
|
title: "Les chiens et la charrue",
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Sens an api request with
|
|
// Result<BookInstance> newBookInstance() {
|
|
|
|
// };
|
|
}
|