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