Libreria class
Modello dati che rappresenta la libreria. Gestisce l'insieme dei libri, le operazioni CRUD e la sincronizzazione con il database. Implementa il pattern Singleton e notifica i listener tramite ChangeNotifier.
- Inheritance
-
- Object
- ChangeNotifier
- Libreria
Constructors
- Libreria.new()
-
Costruttore factory che restituisce l'istanza singleton.
Chiamando Libreria() si ottiene sempre la stessa istanza condivisa.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- numeroTotaleLibri → int
-
Getter che restituisce il numero totale di libri.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
aggiungiLibro(
Libro libro) → Future< void> - Aggiunge un libro alla libreria se non presente. Aggiorna sia il database che la mappa interna.
-
cerca(
bool criterio(Libro)) → List< Libro> -
Ricerca generica che restituisce una lista di libri che soddisfano un criterio specificato.
Prende in input una funzione
criterio
che rappresenta il filtro di ricerca. Il metodo inserisce nella lista solo i libri che soddisfano il criterio, ovvero quelli per cui la funzionecriterio
restituisce true. Esempio: cerca((libro) => libro.annoPubblicazione > 2000) -
cercaLibroPerIsbn(
String isbn) → Libro? - Ricerca un libro tramite ISBN. Restituisce il libro se trovato, altrimenti null.
-
cercaLibroPerNome(
String nome) → Libro? - Ricerca per titolo (case insensitive). Restituisce il primo libro che contiene la stringa cercata nel titolo.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
inherited
-
getLibri(
) → List< Libro> - Restituisce tutti i libri come lista non ordinata.
-
getLibriFiltrati(
{GenereLibro? genere, StatoLibro? stato, bool soloPreferiti = false, String? titolo}) → List< Libro> - Metodo helper per il filtraggio combinato dei libri. Permette di filtrare per genere, stato, preferiti e titolo contemporaneamente.
-
getLibriOrdinati(
) → List< Libro> - Restituisce tutti i libri come lista ordinata alfabeticamente per titolo.
-
getLibriPerGenere(
GenereLibro? genere) → List< Libro> -
Restituisce i libri in base al genere specificato.
Se
genere
è null, restituisce tutti i libri. -
getLibriPerStato(
StatoLibro? stato) → List< Libro> -
Restituisce i libri in base allo stato specificato.
Se
stato
è null, restituisce tutti i libri. -
init(
) → Future< void> - Metodo di inizializzazione che carica i libri dal database nella mappa interna. Da chiamare una sola volta all'avvio dell'app.
-
modificaLibro(
Libro vecchioLibro, Libro nuovoLibro) → void - Modifica un libro esistente sostituendolo con uno nuovo. Rimuove il vecchio libro e aggiunge quello nuovo.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
rimuoviLibro(
Libro libro) → Future< void> - Rimuove un libro dalla libreria e dal database. Lancia un'eccezione se l'ISBN non viene trovato.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited