5

Do we need to write the path of the asset from the asset folder or it saves somewhere else when it generate apk or ipa? Tried with using path from asset but didn't work.

String s="<img src="file:///asset/images/test.png" width="42" height="42" align="right">"

We are using this as a string and passing it in web view but web view is not showing the image.

6
  • Why are you using html like this in Flutter? Commented Nov 30, 2018 at 6:07
  • Good Question. I need to show the static content coming from backend and have to show even if I am not connected to a network. So, I saved html content coming from backend to my local file. This static screen contains an image and I need to take that image that is stored in asset folder to open it in web view. Therefore, I make html string containing my image from asset and html content coming from the API and show that in the web view. Commented Nov 30, 2018 at 6:57
  • Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. Commented Nov 30, 2018 at 7:44
  • @PrakharAnand If I understand you right your building and html file in Flutter to put in a webview? Why not just use flutter.io/docs/cookbook/images/network-image in normal Flutter? Edit: Or if you want to do that, just makes PWA? Commented Nov 30, 2018 at 12:52
  • @halfer, Thanks for your suggestions. Will look into it Commented Dec 7, 2018 at 5:44

2 Answers 2

0
<img src=\"file:///android_asset/flutter_assets/assets  

the above code works for me in with this package -> flutter_inappbrowser
but i think it will work only for android.

Sign up to request clarification or add additional context in comments.

2 Comments

Work for android. What about iOS?
Work for android but unable to render image in iOS. If you can please help!! stackoverflow.com/questions/57702924/…
-1

You need to define your images in pubspec.yaml file as follows:

assets:
      - assets/your_image.png

then you can use your images in code using their path.

2 Comments

Defined this in yaml and even used in ImageAsset in the code and is working but not Getting the image if we provide path to the src tag in html string. I want to use image in src html tag. Kindly help
Can you specify whole pubspec.yaml file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.