Open tonyhart7 opened 3 years ago
@cachapa
can Someone told me how UserCollection.fromMap do because im mapping manual <String, dynamic> didnt work
I find that it is best practice to not co-mingle database access code w/ the UI code. Back to your question, what you do is that you query on a collection reference then iterate over each element on the page, which is a document that can directly be converted to a Map type. Here is an example from my data access code:
Future<List<ChessGame>> getAllChessGames() async {
List<ChessGame> _games = [];
CollectionReference cREf = await Glob.controller.firestore.collection("/cchess/atlanta/games");
final page = await cREf.get();
for( Document doc in page){
_games.add(ChessGame.fromMap(doc.map));
_games.last.id = doc.id;
}
return _games;
}
I find that it is best practice to not co-mingle database access code w/ the UI code. Back to your question, what you do is that you query on a collection reference then iterate over each element on the page, which is a document that can directly be converted to a Map type. Here is an example from my data access code:
Future<List<ChessGame>> getAllChessGames() async { List<ChessGame> _games = []; CollectionReference cREf = await Glob.controller.firestore.collection("/cchess/atlanta/games"); final page = await cREf.get(); for( Document doc in page){ _games.add(ChessGame.fromMap(doc.map)); _games.last.id = doc.id; } return _games; }
thanks you, you saved my day bro
I want to make a list based on my collection like picture above but the thing is firedart dsnt return document snapshot How I can display that ? because I using Map<String, dynamic > the return Type is Page document level not a Map<String, dynamic>