Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. // scope.model.dart
  2. mixin AuthModel on CoreModel {
  3. bool get isLoading => _isLoading;
  4. get notification => _notification;
  5. Observable<Map<String, dynamic>> profileUser;
  6.  
  7. // constructor
  8. Future<void> authService() async {
  9. user = Observable(_auth.onAuthStateChanged);
  10.  
  11. profileUser = user.switchMap((FirebaseUser u) {
  12. if (u != null) {
  13. authenticated.add(true);
  14. _isLoading = false;
  15. notifyListeners();
  16. return _db
  17. .collection('users')
  18. .document(u.uid)
  19. .snapshots()
  20. .map((snap) => snap.data);
  21. } else {
  22. authenticated.add(false);
  23. return Observable.just({});
  24. }
  25. });
  26. }
  27.  
  28. // get profile here
  29. }
  30.  
  31. get profile {
  32. profileUser.listen((user) => _profile = user);
  33. if (_profile == null) {
  34. _isLoading = true;
  35. notifyListeners();
  36. } else {
  37. return _profile;
  38. }
  39. }
  40.  
  41. _model.profile['username'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement