0

I'm trying to put a default image in storage when I create a new user. I made that when you create a new accout automatically create a file in storage on firebase with the user uid, now I'm trying to put in the file a image from my assets

How do I do this? enter image description here

I tried something with metadata but doesn't work

 Future<void> resUser() async {
    try {
      final userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(

        email: _gmailController.text,
        password: _contrasenaController.text,
      );


      final uid = userCredential.user!.uid;

      String newDirectory = uid;

      
      final metadata = SettableMetadata(contentType: "assets/usuariDef.png");

      
      await FirebaseStorage.instance.ref('imagenes/$uid').putFile(metadata);

      addUser(_usuarioController.text, _gmailController.text, _contrasenaController.text,uid);

    } catch (e) {
      // Handle any errors
      print('Error creating user: $e');
    }

  }
  • 1
    You need a `File` object to pass to `putFile` as parameter. See [here](https://stackoverflow.com/questions/55295593/how-to-convert-asset-image-to-file) how to convert an asset image into a `File` object. – Peter Koltai Mar 08 '23 at 17:30

0 Answers0