Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get collection posts
- final CollectionReference posts = FirebaseFirestore.instance.collection("User posts");
- Future<void> getUsername() async {
- try {
- final DocumentSnapshot docRef = await FirebaseFirestore.instance
- .collection("Users")
- .doc("${user!.email}").get();
- if (docRef.exists) {
- final map = docRef.data() as Map<String, dynamic>;
- String name = map['username'];
- print(name); //or add your own logic to handle the user's info
- } else {
- print("document with id : \"${user!.email}\" does not exists");
- }
- } catch (e) {
- print(e.toString());
- rethrow;
- }
- }
- //post the [posts]
- Future<void> addPosts(String message, String title, fileurl) {
- final data = getUsername();
- return posts.add({
- 'posttitle': title,
- 'UserEmail': user!.email,
- 'postMessage': message,
- 'TimeStamp': Timestamp.now(),
- 'Likes': [],
- 'comments': [],
- 'postfile': fileurl,
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement