You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
justMusic/Sources/justMUSIC/lib/services/PostService.dart

34 lines
932 B

import 'dart:io';
import 'package:tuple/tuple.dart';
import 'package:firebase_storage/firebase_storage.dart';
import '../main.dart';
class PostService {
createPost(String? description, String idMusic, File? image,
Tuple2<String, String>? location) async {
var id = MyApp.userViewModel.userCurrent.id;
final post = <String, dynamic>{
"user_id": id,
"description": description,
"date": DateTime.now(),
"place": [location?.item1, location?.item2],
"song_id": idMusic,
"likes": 0
};
var postAdd = await MyApp.db.collection("posts").add(post);
if (image != null) {
var imageRef = FirebaseStorage.instance.ref('$id${postAdd.id}.jpg');
await imageRef.putFile(image);
var imageUrl = await imageRef.getDownloadURL();
postAdd.update({"selfie": imageUrl});
}
}
deletePost() {}
getPostsById(String id) {}
}