项目作者: taylanyildiz

项目描述 :
Google, Facebook and Apple API sign and register with email and messaging
高级语言: Dart
项目地址: git://github.com/taylanyildiz/Firebase-Get-Users.git
创建时间: 2021-05-29T20:02:54Z
项目社区:https://github.com/taylanyildiz/Firebase-Get-Users

开源协议:

下载


firebase get all user account.

This project get all user from Firebase

Screenshot




Database service class

  1. class FirebaseDataService {
  2. final String? uid;
  3. FirebaseDataService({this.uid});
  4. final CollectionReference _reference =
  5. FirebaseFirestore.instance.collection('users');
  6. Future createUser(String? name, String? email, String? profile) async {
  7. return _reference.doc(uid).set({
  8. 'name': name,
  9. 'email': email,
  10. 'profile': profile,
  11. });
  12. }
  13. List<UserModel> _userListFromSnapshot(QuerySnapshot? snapshot) {
  14. return snapshot!.docs.map((DocumentSnapshot doc) {
  15. return UserModel(
  16. doc['name'] ?? '',
  17. doc['email'] ?? '',
  18. doc['profile'] ?? '',
  19. );
  20. }).toList();
  21. }
  22. Stream<List<UserModel?>?> get users {
  23. return _reference.snapshots().map(_userListFromSnapshot);
  24. }
  25. }

Get User from Firebase

  1. Widget _listProfileUser(BuildContext context) {
  2. return StreamBuilder<List<UserModel?>?>(
  3. stream: FirebaseDataService().users,
  4. builder: (context, snapshot) {
  5. if (snapshot.hasData) {
  6. return ListView.builder(
  7. padding: EdgeInsets.symmetric(horizontal: 10.0),
  8. scrollDirection: Axis.horizontal,
  9. itemCount: snapshot.data!.length,
  10. itemBuilder: (context, index) {
  11. List<UserModel?> user = snapshot.data!;
  12. return user[index]!.profile != 'none'
  13. ? Padding(
  14. padding: const EdgeInsets.all(2.0),
  15. child: CircleAvatar(
  16. radius: 20.0,
  17. backgroundColor: Colors.grey,
  18. backgroundImage: NetworkImage(user[index]!.profile),
  19. ),
  20. )
  21. : Padding(
  22. padding: const EdgeInsets.all(2.0),
  23. child: CircleAvatar(
  24. radius: 20.0,
  25. child: Text(
  26. user[index]!.email.split('@')[0][0].toUpperCase()),
  27. ),
  28. );
  29. },
  30. );
  31. } else {
  32. return Container();
  33. }
  34. },
  35. );
  36. }

Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our
online documentation, which offers tutorials,
samples, guidance on mobile development, and a full API reference.