Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Images from URL,Supply any type #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bensalcie
Copy link

@bensalcie bensalcie commented Oct 18, 2022

This PR has fixes to enable one load images from a URL without doing anything on flutter. Just supply the corresponding URL . If it starts with http/https it will be loaded from online. If not, it will loaded from Assets.This has the update to load the images asynchronous, so you don't have to worry about Blocking UI to your flutter App.

  1. Maintain default convinience extension. (FCPExtensions.swift)
convenience init?(withURL url: URL) throws {
                  let imageData = try Data(contentsOf: url)
                  self.init(data: imageData)
                }
  1. When about to render image, check the source. Then dispatch it on a separate thread for both local and url images.
if image != nil {
             if image!.starts(with: "http"){
                 DispatchQueue.global(qos: .background).async {
                     let url = URL(string: self.image!)
                     let stationImage = try? UIImage(withURL: url!)
         //
                         DispatchQueue.main.async {
                             listItem.setImage(stationImage)
                               }
                       }
             }else{
                 listItem.setImage(UIImage().fromFlutterAsset(name: image!))
             }
         }

This will intercept all urls beginning with http with custom loader and those beginning with any other format as asset images.
Thank you.

@oguzhnatly
Copy link
Owner

Thank you for your contribution @vanlooverenkoen!
I'm testing on real devices and cars as well. Once it's done, I will be approving and merge the changes as soon as possible.

@oguzhnatly oguzhnatly added new-feature New feature or request in testing This issue has been testing labels Nov 9, 2022
@vanlooverenkoen
Copy link

Duplicate of #24

@bensalcie
Copy link
Author

Implementation is bit different. We can test for both and see any performance issues. I tried your approach and when #24 inside Isolates, I get some lag. I had to go the approach on the last commit. But my view is relative.

@larry-cariq
Copy link

Hi @oguzhnatly. This is a very nice package and very useful. Are you thinking about merging this PR and releasing a package update? Just curious if I should wait for the update or fork and build it myself. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in testing This issue has been testing new-feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants