The method 'map' isn't defined for the type 'Function'. Try correcting the name to a name of an existing method, or defining a method named 'map'

Viewed 1751

I do not know why but the method map is wrong. Can someone please help me with this issue?

import 'package:pwff/models/user.dart' as models;
import 'package:firebase_auth/firebase_auth.dart';

class AuthService {

  final FirebaseAuth _auth = FirebaseAuth.instance;

   models.User? _userFromFirebaseUser(User user) {
    return user != null ? models.User(uid: user.uid) : null;
  }

  Stream<models.User> get user {
    return _auth.authStateChanges
      .map(_userFromFirebaseUser);
  }
2 Answers

authStateChanges is a function, so you need to call it first, like this:

  Stream<models.User> get user {
    return _auth.authStateChanges()
      .map(_userFromFirebaseUser);
  }
Stream<models.User> get user {
    return _auth.authStateChanges()
      .map(_userFromFirebaseUser!);
}

Try the above code instead

Related