πͺWorking with Assets
Assets are the files your app needs to function, like images, fonts, or data files. Hereβs how you can include and use assets in your Flutter app.
1. Adding Assets to Your Project ποΈ
First, create a folder named assets
in the root of your project and place your asset files in it.
2. Updating pubspec.yaml π
Next, update your pubspec.yaml
file to include the assets. Under flutter:
, add an assets:
section like so:
3. Using Images from Assets πΈ
Now that youβve added your assets, you can use them in your app. Hereβs how to display an image:
4. Using Custom Fonts π
°οΈ
You can also include custom fonts in your assets. First, create a fonts
folder inside assets
, then update your pubspec.yaml
:
Now, you can use your custom font in your app:
5. Loading and Using Data Files π
You can read data from files stored in your assets as well:
Assignments π
Time for some hands-on practice:
With these assignments, you'll get a practical understanding of working with assets in Flutter.
Congratulations you're done with the basics of flutter!
Let's move to intermediate stuff now.
Last updated