changed firebase storage folder name. now includes uid's

This commit is contained in:
2023-05-19 17:57:50 +02:00
parent 3f43a016db
commit fe4f1d52ae
+9 -3
View File
@@ -129,12 +129,18 @@ class _AddScreenState extends State<AddScreen> {
Future<String> uploadImageToFirebaseStorage( Future<String> uploadImageToFirebaseStorage(
File imageFile, String collectionName) async { File imageFile, String collectionName) async {
String? userId = FirebaseAuth.instance.currentUser?.uid;
if (userId != null) {
Reference ref = FirebaseStorage.instance Reference ref = FirebaseStorage.instance
.ref() .ref()
.child("$collectionName/${DateTime.now().toString()}"); .child("$collectionName/$userId/${DateTime.now().toString()}");
UploadTask uploadTask = ref.putFile(imageFile); UploadTask uploadTask = ref.putFile(imageFile);
return await (await uploadTask).ref.getDownloadURL(); return await (await uploadTask).ref.getDownloadURL();
} else {
throw Exception('Cannot upload without user ID');
} }
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -248,7 +254,8 @@ class _AddScreenState extends State<AddScreen> {
? Expanded( ? Expanded(
child: LayoutBuilder( child: LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
double imageHeight = max(0, constraints.maxHeight - keyboardHeight); double imageHeight =
max(0, constraints.maxHeight - keyboardHeight);
return Container( return Container(
height: imageHeight, height: imageHeight,
child: Image.file(_imageFile!), child: Image.file(_imageFile!),
@@ -256,7 +263,6 @@ class _AddScreenState extends State<AddScreen> {
}, },
), ),
) )
: Container( : Container(
height: 200.0, height: 200.0,
decoration: BoxDecoration( decoration: BoxDecoration(