Skip to content

Instantly share code, notes, and snippets.

@Zfinix
Created June 13, 2020 11:07
Show Gist options
  • Select an option

  • Save Zfinix/5b8f1a9c3b65d6354921a17a11a1dc61 to your computer and use it in GitHub Desktop.

Select an option

Save Zfinix/5b8f1a9c3b65d6354921a17a11a1dc61 to your computer and use it in GitHub Desktop.
import 'package:cloud_firestore/cloud_firestore.dart';
class UserModel {
String username;
String email;
String phone;
String profilePicUrl;
String userId;
String deviceId;
bool isOnline;
List<dynamic> blocked;
bool isAdmin;
final DocumentReference reference;
UserModel({
this.username,
this.email,
this.phone,
this.profilePicUrl,
this.userId,
this.isOnline = false,
this.isAdmin,
this.deviceId,
this.reference,
});
UserModel.fromMap(Map<dynamic, dynamic> map, {this.reference})
: userId = map['userId'],
username = map['username'],
phone = map['phone'],
email = map['email'],
isAdmin = map['isAdmin'],
blocked = map['blocked'] ?? List(),
isOnline = map['is_online'] ?? false,
profilePicUrl = map['profilePicUrl'];
UserModel.fromJson(Map<String, dynamic> json, {this.reference})
: userId = json['userId'],
username = json['username'],
phone = json['phone'],
isOnline = json['is_online'] ?? false,
isAdmin = json['isAdmin'],
email = json['email'],
profilePicUrl = json['profilePicUrl'];
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['userId'] = this.userId;
data['username'] = this.username;
data['isAdmin'] = this.isAdmin;
data['phone'] = this.phone;
data['email'] = this.email;
data['profilePicUrl'] = this.profilePicUrl;
return data;
}
UserModel.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);
@override
String toString() => '${this.runtimeType}(${this.toJson()})';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment