| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'models/user.dart';
- class DatabaseManager {
- CollectionReference usersList =
- FirebaseFirestore.instance.collection("Users");
- // Get stream with users ordered by total points from firestore
- Stream<List> getUsersList() async* {
- List<dynamic> users = [];
- try {
- await usersList.orderBy("total_points", descending: true).snapshots().
- listen((snap){
- snap.docs.forEach((element){
- users.add(element.data());
- });
- });
- yield users;
- } catch(e){
- print(e.toString());
- yield [];
- }
- }
- //It is not necessary.At least right now
- // List<User> _userListFromSnapshot(QuerySnapshot snapshot){
- // return snapshot.docs.map((doc){
- // return User(
- // shared_id: doc.get('shared_id'),
- // name: doc.get('name'),
- // total_points: doc.get('total_ponts'),
- // );
- // }).toList();
- // }
- //
- // dynamic get users {
- // return usersList.orderBy("total_points", descending: true).snapshots();
- // }
- }
|