Note: this tip is outdated. For a more modern approach, read: Transform SVG assets at build time
SVGs have some advantages over regular images:
- scalable without loss of quality
- smaller and more performant (for simple shapes)
But have you noticed that when you use SVGs in your apps, they don't always appear immediately?
To fix this, consider pre-caching them: 👇
Once the preloadSVGs
function is defined, simply call it inside your main()
.
Oh, and don't forget to add the assets and declare them in your pubspec.yaml
file. 😉
Then, you can render your SVGs inside your widgets as needed.
And since they have been cached, they will be rendered immediately.
Bonus: you can use the colorFilter
property to apply a specific blend mode (see the API docs for details).
Found this useful? Show some love and share the original tweet
Previous | Next |
---|---|
Environment variables in Dart | Scroll-to-index inside a ListView |