Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- floatingActionButton: FloatingActionButton(
- onPressed: () async {
- List<TempPost> posts = await fetchallPost() ;
- print("return back to floating action");
- /*
- posts.forEach((element) {
- print(element.description);
- print(element.ownerPhotoUrl);
- print(element.id);
- print(element.ownerEmail);
- print(element.ownerId);
- print(".................................................");
- });
- */
- /*
- flutter ( 3738): return back to floating action
- I/flutter ( 3738): Image tells the secret
- I/flutter ( 3738): https://firebasestorage.googleapis.com/v0/b/socialmdeiaapp.appspot.com/o/images%2F1685724234769?alt=media&token=b2f67a4e-8587-4d9b-aa31-51fc035ac3d4
- I/flutter ( 3738): 1lNW54eZ87CJpMSY2oO0
- I/flutter ( 3738): anik11556@gmail.com
- I/flutter ( 3738): YKjcFlzKIrf4kSVxHWQJEcqIutZ2
- */
- String? newPostId; //= "1lNW54eZ87CJpMSY2oO0";
- String? fieldvalue; //= "anik11556@gmail.com";
- CollectionReference collection = FirebaseFirestore.instance.collection('all_Posts');
- /*
- try {
- await collection.doc(newPostId).update({
- 'ownerEmail': fieldvalue,
- });
- print('Field "newField" added successfully.');
- } catch (e) {
- print('Error adding field: $e');
- }
- */
- posts.forEach((element) async {
- newPostId = element.id;
- fieldvalue = element.ownerPhotoUrl;
- try {
- await collection.doc(newPostId).update({
- 'ownerPhotoUrl': fieldvalue,
- });
- print('Field "postId" updated successfully.');
- } catch (e) {
- print('Error updating field: $e');
- }
- });
- },
- ),
- //////////////////////////////////////////////////////////////////////////////////////////
- List<TempPost> tempPosts = [];
- Future<List<TempPost>> fetchallPost() async {
- print("user fetching");
- List<User> users = await GetWant().getAllUserfromJson();
- //users.forEach((element) {print(element.userName);});
- print("Post Fetching");
- CollectionReference collection = FirebaseFirestore.instance.collection('all_Posts');
- QuerySnapshot querySnapshot = await collection.get();
- querySnapshot.docs.forEach((doc) {
- String? idd = doc.id;
- String? id = doc.id;//doc.get('id');
- String? postId = doc.get('postId');
- String? userName = doc.get('userName');
- String? ownerId = doc.get('ownerId');
- String? location = doc.get('location');
- String? timestamp = doc.get('timestamp');
- String? mediaUrl = doc.get('mediaUrl');
- String? description = doc.get('description');
- /*
- Post curPost = Post.Complete(id,postId,userName,ownerId,location,timestamp,mediaUrl,description);
- bool exists = Post.posts.any((entity) => entity.postId == curPost.postId);
- */
- /*
- print(idd);
- print(postId);
- */
- int index = users.indexWhere((obj) => obj.id == ownerId);
- /*
- print(ownerId);
- print(users[index].email);
- print(users[index].userName);
- print(users[index].id);
- */
- ownerId = users[index].id ;
- String? ownerEmail=users[index].email;
- String? ownerPhotoUrl=users[index].photoUrl;
- TempPost curPost = TempPost.Complete(id,postId,userName,ownerId,location,timestamp,mediaUrl,description,ownerEmail,ownerPhotoUrl);
- bool exists = tempPosts.any((entity) => entity.postId == curPost.postId);
- // print(curUser.userName);
- // //print(DateFormat("MMMM d, y 'at' h:mm:ss a 'UTC'z").format(curUser.lastSeen.toDate()).toString());
- // print(curUser.time.toDate());
- if(exists)
- {
- //print("already in the list");
- }
- else
- {
- // print("not exist in the list");
- tempPosts.add(curPost);
- }
- });
- print(tempPosts.length);
- return tempPosts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement