I would like to create an Object using data from my Firebase database. I get the data correctly, but I can't create that Objet in the way im trying. I have no idea why it doesn't work, this is my first time using Dart.
Here is my code
MaterialQR selectFromFirebase(String document) { MaterialQR res = MaterialQR(exercises: [], image: '', name: '', id: ''); FirebaseFirestore.instance.collection('MaterialQR') .doc(document).get() .then((value) => res = new MaterialQR( exercises: value['exercises'], image: value['image'], name: value['name'], id: value['id'])); return res; } The objective is return an "empty" Object if the document in my database doesn't exist or return a correct Object if the document exists. When I print(value['id']) inside .then(), I got a correct id, but it doesn't work when I create the new Object.
.then()