Ahmadre / FlutterIconPicker

An adaptive comprehensive IconPicker for Flutter
MIT License
112 stars 76 forks source link

Optimize app size by loading icons on demand remotely #60

Closed SethuSenthil closed 6 months ago

SethuSenthil commented 1 year ago

Issue Description: Currently, all the Icons need to be embedded with the binary, which causes the app to be larger than it needs to be. This increases the app's installation size and consumes unnecessary device storage. To improve the app's efficiency and reduce its size, it would be ideal to implement a solution that loads icons on demand through network requests and saves only the icons chosen by the user to the disk during runtime.

Issue Details:

  1. The current approach of embedding all icons within the binary is causing the app's size to be larger than necessary. This adversely affects the user experience by increasing installation time and consuming more device storage space.
  2. An optimized solution is desired where icons are fetched from the network on demand. This means that icons should only be downloaded and loaded into memory when they are required by the user.
  3. When a user selects an icon, it should be saved to disk for future use, eliminating the need for repeated network requests. By storing selected icons locally, the app can load them from the device's storage instead of fetching them over the network.
  4. Icons that have not been selected by the user should not be stored permanently on the device. Instead, they should be fetched from the network whenever needed and discarded from memory when no longer in use.
  5. The implementation should ensure a seamless user experience with minimal latency. Users should not experience any significant delays when loading icons or selecting them.
  6. Care should be taken to handle scenarios where the network connection is poor or unavailable. In such cases, the app should gracefully handle the situation and provide appropriate feedback to the user.
  7. The solution should be implemented in a way that allows easy scalability and future additions of new icons. The app should be able to fetch and save icons without major code changes or disruptions.

Expected Outcome: By implementing this solution, the app's installation size will be significantly reduced as only selected icons are saved to the disk. Users will experience faster installation times and utilize less storage space on their devices. Additionally, the dynamic loading of icons on demand will improve the app's performance and enhance the overall user experience.

Ahmadre commented 1 year ago

Thank you so much for your time writing such a great issue and suggestion โค๏ธ

I really like your ideas and would appreciate any PR's. But I will definetly prioritize this, because I also think it's better to provide users a simple way to configure this IconPicker to work network-based, to cache (or not) and other great features :)

Definetly noted and will look for a solution ๐Ÿ‘

SethuSenthil commented 1 year ago

No problem! ๐Ÿ˜ƒ I'm excited to work on implementing this feature and I'll be sure to open a few pull requests for it.

Based on my current understanding (though I could be mistaken), it appears that the most practical approach to loading each icon individually would be to utilize SVGs. IconData, as you may be aware, relies on code points that necessitate the use of the entire font file. However, SVGs can be loaded on demand, one by one.

Fortunately, I came across a library that seems to provide the functionality we're seeking. I haven't tested it thoroughly yet, but it appears promising. You can check it out here: https://pub.dev/packages/flutter_svg_icons

Ahmadre commented 6 months ago

No problem! ๐Ÿ˜ƒ I'm excited to work on implementing this feature and I'll be sure to open a few pull requests for it.

Based on my current understanding (though I could be mistaken), it appears that the most practical approach to loading each icon individually would be to utilize SVGs. IconData, as you may be aware, relies on code points that necessitate the use of the entire font file. However, SVGs can be loaded on demand, one by one.

Fortunately, I came across a library that seems to provide the functionality we're seeking. I haven't tested it thoroughly yet, but it appears promising. You can check it out here: https://pub.dev/packages/flutter_svg_icons

Thanks for mentioning :).

Of course using SVG's remotely would be much easier. A collegue of mine also created an CachedSVGNetworkImageWidget for the best use case.

Under the hood your linked package is just relying and using SVGPicture.asset so I would recommend directly loading svg's from backend and use them like you need :).

This package is only for quick-and-dirty usage of icons or even Generators.

Have a nice day man ๐Ÿ™Œ

Ahmadre commented 6 months ago

@SethuSenthil I resolved the app size issue by generating icons on demand. Please see latest update and let me know.

Ahmadre commented 6 months ago

I will close this issue due to inactiveness. Please see latest version for app size & icon generation news :).

Thanks.