Here's my function to upload the 2 files into firebase storage I am not sure if i am using proper exception handling and second of all where to put the await statement to give time for uploading itself.
void _uploadtocloud() async {
//File? filesong,fileimage; initialized outside the function
String songname = songName.text.toString();
String thumbnail = '${songName.text}thumbnail';
final Reference storageRef =
FirebaseStorage.instance.ref().child('music/$songname');
final UploadTask uploadTaskSong = storageRef.putFile(filesong!);
final Reference storageRefimage =
FirebaseStorage.instance.ref().child('image/$thumbnail');
final UploadTask uploadTaskimage = storageRefimage.putFile(fileimage!);
final TaskSnapshot snapshot1 = await uploadTaskSong;
final TaskSnapshot snapshot2 = await uploadTaskimage;
if (snapshot1.state == TaskState.success &&
snapshot2.state == TaskState.success) {
await Future.delayed(const Duration(seconds: 10));
//is this the right place to put await statement.
setState(() {
uploaded = true;
songName.clear();
});
} else {
setState(() {
uploadfaliure = true;
});
}
}