Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // scope.model.dart
- mixin AuthModel on CoreModel {
- bool get isLoading => _isLoading;
- get notification => _notification;
- Observable<Map<String, dynamic>> profileUser;
- // constructor
- Future<void> authService() async {
- user = Observable(_auth.onAuthStateChanged);
- profileUser = user.switchMap((FirebaseUser u) {
- if (u != null) {
- authenticated.add(true);
- _isLoading = false;
- notifyListeners();
- return _db
- .collection('users')
- .document(u.uid)
- .snapshots()
- .map((snap) => snap.data);
- } else {
- authenticated.add(false);
- return Observable.just({});
- }
- });
- }
- // get profile here
- }
- get profile {
- profileUser.listen((user) => _profile = user);
- if (_profile == null) {
- _isLoading = true;
- notifyListeners();
- } else {
- return _profile;
- }
- }
- _model.profile['username'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement