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
+23 -17
View File
@@ -129,13 +129,19 @@ class _AddScreenState extends State<AddScreen> {
Future<String> uploadImageToFirebaseStorage(
File imageFile, String collectionName) async {
Reference ref = FirebaseStorage.instance
.ref()
.child("$collectionName/${DateTime.now().toString()}");
UploadTask uploadTask = ref.putFile(imageFile);
return await (await uploadTask).ref.getDownloadURL();
String? userId = FirebaseAuth.instance.currentUser?.uid;
if (userId != null) {
Reference ref = FirebaseStorage.instance
.ref()
.child("$collectionName/$userId/${DateTime.now().toString()}");
UploadTask uploadTask = ref.putFile(imageFile);
return await (await uploadTask).ref.getDownloadURL();
} else {
throw Exception('Cannot upload without user ID');
}
}
@override
Widget build(BuildContext context) {
String appBarTitle = '';
@@ -246,18 +252,18 @@ class _AddScreenState extends State<AddScreen> {
const SizedBox(height: 16.0),
_imageFile != null
? Expanded(
child: LayoutBuilder(
builder: (context, constraints) {
double imageHeight = max(0, constraints.maxHeight - keyboardHeight);
return Container(
height: imageHeight,
child: Image.file(_imageFile!),
);
},
),
)
: Container(
child: LayoutBuilder(
builder: (context, constraints) {
double imageHeight =
max(0, constraints.maxHeight - keyboardHeight);
return Container(
height: imageHeight,
child: Image.file(_imageFile!),
);
},
),
)
: Container(
height: 200.0,
decoration: BoxDecoration(
color: Colors.grey[200],