Display local pictures in Flutter
1. Create a picture resource directory
First, create a picture resource directory to store pictures.
In the project root directory, create an assets directory, and below it, create a subdirectory called images to store image resources:
/assets/images/
2. Add local pictures to the resource directory
Add the pictures we need to the /assets/images/ directory.
3. Register in pubspec.yaml
Configure the picture directory to the pubspec.yaml file:
flutter:
assets:
- assets/images/
The entire picture catalog is registered above, and then we can use it.
Of course, if we only want to register a picture, we can do this:
flutter:
assets:
- assets/images/task_icon.jpg
4. Picture usage
Now, you can use the image directly in the code:
Image.asset('assets/images/task_icon.jpg')
Flutter Image is a Widget that displays pictures. Image.asset(String name): Get the image from AssetBundler.
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"
**PS: For more exciting content, please check --> "Flutter Development"