#[SOLVED] How to get an asset image in a Dart Function?

12 messages · Page 1 of 1 (latest)

surreal wing
#

Hi,
I need to access an image file in my dart function. The file is in the lib folder just like the main.dart but all the paths I have tried didn't work like lib/image.png or just image.png. Any ideas? Thanks

I am sending an email with an attachment, the mailer package says to use File('/path/to/file') but the image is never included in the emails that get sent.

thorny kernel
surreal wing
#

Hi. Thanks for the references but I can't seem to find what I'm looking for. Is there a specific example using a Dart function to access an asset? Thanks.

thorny kernel
#

lemme check once

glass drift
surreal wing
#

oh ok. There has to be a way in dart to reference a file outside of the main.dart. I tried using File('lib/file.png') noting works. I guess because the path changes after the Function gets compiled?

#

I did a print statement in the code print(Directory.default.path) and after i looked at the execution logs i got back /usr/code-start

glass drift
surreal wing
#

Ok. Might just have to use node mailer instead. I just am way more comfortable with dart. 😟

glass drift
surreal wing
#

Yes. That is an option also, and just reference the file from there.

#

Made it work using that method. Thanks.