Home > Back-end >  Undefined name 'storage'. Try correcting the name to one that is defined, or defining the
Undefined name 'storage'. Try correcting the name to one that is defined, or defining the

Time:06-11

I'm makiing a mthod to Retrieve image from firebase storage,please tell me how i can solve this error

Future<List<Map<String, dynamic>>> _loadImage() async {
        List<Map<String, dynamic>> files = [];
    
        final ListResult result = await storage.ref('pizza').list();//Undefined name 'storage'.
    Try correcting the name to one that is defined, or defining the name.
        final List<Reference> allFiles = result.items;
    
        await Future.forEach<Reference>(allFiles, (file) async {
          final String fileUrl = await file.getDownloadURL();
          final FullMetadata fileMeta = await file.getMetadata();
          files.add({
            "url": fileUrl,
          });
        });
    
        return files;
      }

CodePudding user response:

You're missing the definition of the storage variable. Did you just copy-paste this into your code from somewhere? Try using FirebaseStorage.instance instead.

  • Related