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

94 lines
2.1 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.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();
/*
* ====================
* =====[ 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() {
// };
}