The Dart Analysis shows the following errors:
error: Undefined class 'FirebaseUser'. (undefined_class at [quizmaker] lib\services\auth.dart:7)
error: The name 'User' is defined in the libraries 'package:firebase_auth/firebase_auth.dart' and 'package:quizmaker/models/user.dart'. (ambiguous_import at [quizmaker] lib\services\auth.dart:7)
error: The name 'User' is defined in the libraries 'package:firebase_auth/firebase_auth.dart' and 'package:quizmaker/models/user.dart'. (ambiguous_import at [quizmaker] lib\services\auth.dart:8)
error: 'User' isn't a function. (invocation_of_non_function at [quizmaker] lib\services\auth.dart:8)
error: The name 'User' is defined in the libraries 'package:firebase_auth/firebase_auth.dart' and 'package:quizmaker/models/user.dart'. (ambiguous_import at [quizmaker] lib\services\auth.dart:15)
The code is following:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:quizmaker/models/user.dart';
class AuthService {
FirebaseAuth _auth = FirebaseAuth.instance;
User _userFromFirebaseUser(FirebaseUser user){
return user != null ? User(uid: user.uid) : null;
}
Future signInEmailAndPassword(String email, password) async {
try {
UserCredential authResult = await _auth.signInWithEmailAndPassword(
email: email, password: password);
User? firebaseUser = authResult.user;
return _userFromFirebaseUser(firebaseUser);
} catch (e) {
print(e.toString());
}
}
}