Skip to content

Instantly share code, notes, and snippets.

@prasadshirvandkar
Created July 25, 2020 18:17
Show Gist options
  • Save prasadshirvandkar/ccc4dc828a874740bf09192a0364c6c6 to your computer and use it in GitHub Desktop.
Save prasadshirvandkar/ccc4dc828a874740bf09192a0364c6c6 to your computer and use it in GitHub Desktop.
import 'package:firebase_auth/firebase_auth.dart';
class User {
String id;
String name;
String imageUrl;
String email;
String address;
User({this.id, this.name, this.imageUrl, this.email, this.address});
factory User.create(FirebaseUser data) => User(id: data.uid, name: data.displayName, imageUrl: data.photoUrl, email: data.email);
factory User.fromMap(Map<String, dynamic> userInfoMap, String id) => User(
id: id ?? 'asd12e12q2d12f',
name: userInfoMap['name'] ?? 'No Name',
imageUrl: userInfoMap['imageUrl'] ?? 'Image URL',
email: userInfoMap['email'] ?? 'random@random.com',
address: userInfoMap['address'] ?? 'No Address Found'
);
Map<String, dynamic> toMap() => {
'id': this.id,
'name': this.name,
'imageUrl': this.imageUrl,
'email': this.email,
'address': this.address
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment