'The return type of 'Class' isn't a user

import 'package:firebase_auth/firebase_auth.dart';

import 'package:flutter_user_profile/model/user.dart';

class AuthService {

  final FirebaseAuth _auth = FirebaseAuth.instance;

  //creating a user object based on Firebase user
  Client? _userFromCredUser(User? user) {
    return user != null ? Client(uid: user.uid) : null;
  }
  //for authenticate user stream
  Stream<User?> get user {
    return _auth.authStateChanges().map((User? user) => _userFromCredUser(user!));
  }

  //sign in anonymously
  Future signInAnon() async {
    try {
      UserCredential result =  await _auth.signInAnonymously();
      User? user = result.user;
      return _userFromCredUser(user!);
    } 
    catch(e){
      print(e.toString());
      return null;
    }
  }
}

Apparently, it has a problem for the _userFromCredUser(user) where it says that the return type isn't a user. It's for authentication on Sign in



Solution 1:[1]

That is because the function Client? _userFromCredUser is expecting a type Client to return but you return Client object or if user parameter is == to null you return null and null is not a return type Client.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wesleyhodaj