0

I'm writing documentation about a variable and I would like to include an image that is inside the project. For example:

assets/
 |- icons/
 |   |- my-image.svg
lib/
 |- my_file.dart

I know it is possible to display an image from an URL, but what about one from a file?

Those were my unsuccessful tries:

// lib/my_file.dart

/// The image attempt:
/// ![](assets/icons/my-image.svg)
/// ![](../assets/icons/my-image.svg)
const myVariable = 0;

But it doesn't work:

enter image description here


Is there a way to do it?

Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73

3 Answers3

1

There is already an issue on GitHub: #2390 and also a related thread: Using local image assets in dart documentation comments

Effectively, web urls are working, but relative paths aren't, because VSCode doesn't support that. It tries to open the files relative to its application directory. But I can't confirm that for Windows either, because for me, not even absolute paths are working...

So if your project lives in a public repository anyways, you could just use a web url.

puaaaal
  • 196
  • 8
0

1:open pubspec.yaml and click "Pub get"

2:

Image.asset("assets/icons/my-image.svg",width: 100,height: 100,)
  • I think you misunderstood my question, I don't want to display the image in the app (this is already done), I want to display it in the documentation – Valentin Vignal Apr 28 '22 at 02:10
0

So i think you want to let the variable hold the asset image path so do this

  1. Go to pubspecs.yaml file and add this

    flutter: assets: - assets/icons/my-image.svg Then run flutter pub get

then you can use the image this way

//let the variable hold the image path
const myVariable = "assets/icons/my-image.svg";


//to display on widget
Image.asset(myVariable);
  • I think you misunderstood my question, I don't want to display the image in the app (this is already done), I want to display it in the documentation – Valentin Vignal Apr 28 '22 at 02:10