We can add images from the gallery using the image_picker package in Flutter. For this, you’ll need to use your real device.
Follow the below steps to display the images from the gallery:
Step 1: Create a new flutter application:
flutter create <YOUR_APP_NAME>
Step 2: Now, delete the code from the main.dart file to add your own code.
Step 3: Add the dependency to your pubspec.yaml file:
Step 4: Use the below code in the main.dart file :
When no image is selected, it will result:
When the button is pressed, it will ask for accessing photos, media, and files on your device as shown below:
When the permission is given to access photos and any image is selected from the gallery, it will be displayed on the screen as shown below:
- import image_picker package in main.dart file.
- for a gallery image, we have async function imageSelectorGallery() and await for gallery image.
- the image will be displayed after loaded.
- Camera Access in Flutter
- Getting Started with Cross-Platform Mobile Application using Flutter
- Difference between React Native and Flutter
- Difference Between Rows and Columns vs Container in Flutter
- Multi Page Applications in Flutter
- Routes and Navigator in Flutter
- Container class in Flutter
- Difference Between Stateless and Stateful Widget in Flutter
- Rive animations in Flutter
- ProgressIndicator in Flutter
- Flutter - Stateful vs Stateless Widgets
- Listview.builder in Flutter
- Splash Screen in Flutter
- How to Add images in Flutter App?
- Raised Button widget in Flutter
- Fluttertoast in Flutter
- Flutter - Architecture Application
- Designing a Form Submission Page in Flutter
- Creating a Simple Application in Flutter
- Customizing Fonts in Flutter
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.