Libro.fromMap constructor
Costruisce un oggetto Libro a partire da una mappa, tipicamente estratta da SQLite.
Implementation
factory Libro.fromMap(Map<String, dynamic> map) {
return Libro(
titolo: map['titolo'] as String,
autori: (map['autori'] as String?)?.split(',').toList(),
numeroPagine: map['numeroPagine'] as int?,
genere:
map['genere'] != null
? GenereLibro.values.firstWhere(
(g) => g.toString() == map['genere'],
)
: null,
lingua: map['lingua'] as String?,
trama: map['trama'] as String?,
isbn: map['isbn'] as String,
dataPubblicazione:
map['dataPubblicazione'] != null
? DateTime.parse(map['dataPubblicazione'] as String)
: null,
voto: (map['voto'] as num?)?.toDouble(),
copertina: map['copertina'] as String?,
note: map['note'] as String?,
stato:
map['stato'] != null
? StatoLibro.values.firstWhere(
(s) => s.toString() == map['stato'],
)
: null,
publisher: map['publisher'] as String?,
preferito: (map['preferito'] as int?) == 1,
);
}