I tried uploading image from flutter to firebase storage but when I try to do so nothing changes. I have made connection from firebase to flutter and when I run the code this error appears: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp(). Also when I execute the code the showDialog method isn't poping off (This is a popup screen). Thanks in advance :)
class _MyHomePageState extends State<MyHomePage> {
Future <File> file;
//final storage = FirebaseStorage.instance;
openGatePhoto() async{
final file = await ImagePicker.pickImage(source: ImageSource.gallery);
var reference = FirebaseStorage.instance.ref().child('last_image/car5');
await reference.putFile(file);
//var snapshot = await storage.ref().child('last_image/car5.png').putFile(file).onComplete;
showDialog(
context: context,
builder: (context) => CustomDialogOpen(
title: "Gates are open",
description:
"Licence plate numbers have been successfully stored in the database",
));
I tried fixing the code as @jitesh mentioned but still the same error, the code:
final file = await ImagePicker.pickImage(source: ImageSource.gallery);
Reference reference =
FirebaseStorage.instance.ref().child('last_image/car5');
FirebaseStorage storage = FirebaseStorage.instance;
UploadTask uploadTask = reference.putFile(file);
uploadTask.then((res) {
res.ref.getDownloadURL().then(
(value) => print("Done: $value"),
);
});