Home > OS >  Display an image from the asset in the documentation
Display an image from the asset in the documentation

Time:04-28

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?

CodePudding user response:

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

2:

Image.asset("assets/icons/my-image.svg",width: 100,height: 100,)

CodePudding user response:

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);
  • Related