Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: The name 'User' is defined in the libraries 'package:firebase_auth/firebase_auth.dart' and 'package:tuned_in/models/user.dart'. (ambiguous_import at [tuned_in] lib/resources/firebase_methods.dart:13) #9

Open
goc20 opened this issue Nov 27, 2020 · 0 comments

Comments

@goc20
Copy link

goc20 commented Nov 27, 2020

//this is firebase_methods.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:tuned_in/models/user.dart';
import 'package:tuned_in/utils/utilities.dart';

class FirebaseMethods {
final FirebaseAuth _auth = FirebaseAuth.instance;
GoogleSignIn _googleSignIn = GoogleSignIn();
static final Firestore firestore = Firestore.instance;

//user class
User user = User();

Future getCurrentUser() async {
FirebaseUser currentUser;
currentUser = await _auth.currentUser();
return currentUser;
}

Future signIn() async {
GoogleSignInAccount _signInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication _signInAuthentication =
await _signInAccount.authentication;

final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: _signInAuthentication.accessToken,
    idToken: _signInAuthentication.idToken);

FirebaseUser user = await _auth.signInWithCredential(credential);
return user;

}

Future authenticateUser(FirebaseUser user) async {
QuerySnapshot result = await firestore
.collection("users")
.where("email", isEqualTo: user.email)
.getDocuments();

final List<DocumentSnapshot> docs = result.documents;

//if user is registered then length of list > 0 or else less than 0
return docs.length == 0 ? true : false;

}

Future addDataToDb(FirebaseUser currentUser) async {
String username = Utils.getUsername(currentUser.email);

user = User(
    uid: currentUser.uid,
    email: currentUser.email,
    name: currentUser.displayName,
    profilePhoto: currentUser.photoUrl,
    username: username);

firestore
    .collection("users")
    .document(currentUser.uid)
    .setData(user.toMap(user));

}

Future signOut() async {
await _googleSignIn.disconnect();
await _googleSignIn.signOut();
return await _auth.signOut();
}

}
Screenshot 2020-11-27 at 9 57 07 PM
Screenshot 2020-11-27 at 9 57 33 PM
Screenshot 2020-11-27 at 9 57 40 PM
Screenshot 2020-11-27 at 9 57 52 PM

//this is my user.dart
class User {
String uid;
String name;
String email;
String username;
String status;
int state;
String profilePhoto;

User({
this.uid,
this.name,
this.email,
this.username,
this.status,
this.state,
this.profilePhoto,
});

Map toMap(User user) {
var data = Map<String, dynamic>();
data['uid'] = user.uid;
data['name'] = user.name;
data['email'] = user.email;
data['username'] = user.username;
data["status"] = user.status;
data["state"] = user.state;
data["profile_photo"] = user.profilePhoto;
return data;
}

User.fromMap(Map<String, dynamic> mapData) {
this.uid = mapData['uid'];
this.name = mapData['name'];
this.email = mapData['email'];
this.username = mapData['username'];
this.status = mapData['status'];
this.state = mapData['state'];
this.profilePhoto = mapData['profile_photo'];
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant