I have being trying to update the data from/to Firebase, but i have some issue, and when i update the data, in the firestore, the fields are being set in null value. How can i fix?
he error is just ocorring in the Armas object, the rest data in AtributteData is fine.
MODEL
class AtributeData {
final List<int> atributtes;
final List<int> perks;
final List<int> customPerksValue;
final List<String> customPerksName;
final List<Armas> armas;
AtributeData(
{this.atributtes,
this.perks,
this.customPerksName,
this.customPerksValue,
this.armas});
}
class Armas {
final String modelo;
final int numero;
final int preco;
Armas({this.modelo, this.numero, this.preco});
}
SCREEN WHEN I MAP THE DATA AND FUNCTION TO UPDATE DA DATA
class AtributteDataService {
final String uid;
AtributteDataService({this.uid});
//Referencia para uma Coleção específica
final CollectionReference atributteSheet =
FirebaseFirestore.instance.collection('atributteSheet');
Future updateAtributteData(
{List<int> atributtes,
List<int> perks,
List<int> customPerksValue,
List<String> customPerksName,
List<Armas> armas,
String modelo,
int numero,
int preco}) async {
return await atributteSheet.doc(uid).set({
'atributtes': atributtes,
'perks': perks,
'customPerksValue': customPerksValue,
'customPerksName': customPerksName,
'armas': [
{
'modelo': modelo,
'numero': numero,
'preco': preco,
}
]
});
}
// retorna um snapshot, mas mapeado para AtributteData
AtributeData _atributteDataFromSnapshot(DocumentSnapshot snapshot) {
return AtributeData(
atributtes: List.from(snapshot['atributtes']),
perks: List.from(snapshot['perks']),
customPerksValue: List.from(snapshot['customPerksValue']),
customPerksName: List.from(snapshot['customPerksName']),
armas: List<Armas>.from(snapshot['armas'].map((e) {
return new Armas(
modelo: e["modelo"],
numero: e["numero"],
preco: e["preco"],
);
}))
// markValue: List.from(snapshot['markValue']),
);
}
//lista de todas as fichas dos usuários retornando em Stream
//Obter Streams do Usuário (sem ser habilidades)
Stream<AtributeData> get atributteData {
return atributteSheet.doc(uid).snapshots().map(_atributteDataFromSnapshot);
}
}
TRY TO FILL THE DATA
await AtributteDataService(uid: user.uid).updateAtributteData(
armas: [
Armas(modelo: 'G2', numero: 3, preco: 3200),
Armas(modelo: 'M4A1', numero: 1, preco: 6400),
Armas(modelo: 'AK-47', numero: 5, preco: 7500),
],
customPerksName: [],
customPerksValue: [],
atributtes: [0, 0, 0, 0, 0, 0, 0, 0, 0],
perks: [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
);