Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Collection as a List #77

Open
tonyhart7 opened this issue Sep 21, 2021 · 4 comments
Open

Display Collection as a List #77

tonyhart7 opened this issue Sep 21, 2021 · 4 comments

Comments

@tonyhart7
Copy link

tonyhart7 commented Sep 21, 2021

image

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>

@tonyhart7
Copy link
Author

@cachapa

@tonyhart7
Copy link
Author

image
can Someone told me how UserCollection.fromMap do
because im mapping manual <String, dynamic> didnt work

@tpham3783
Copy link

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;
  }

@tonyhart7
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants