Flutter Image Picker in Android Application

Mobile Apps Development A-Z Guide.

Volodymyr Babenko
Pharos Production
2 min readMar 27, 2019

--

Give us a message if you’re interested in Blockchain and FinTech software development or just say Hi at Pharos Production Inc.

Or follow us on Youtube to know more about Software Architecture, Distributed Systems, Blockchain, High-load Systems, Microservices, and Enterprise Design Patterns.

Pharos Production Youtube channel

Users of mobile applications not only view images in social networks or any other applications but also rarely share their pictures. In this article, I would like to show by example how it is possible to directly access photos directly or from the gallery.

Step 1. Create a new Flutter project. Next, we need to add the dependency to the pubspec.yaml:

dependencies:
image_picker: ^0.5.0+9

Step 2. Create a class that extends StatefullVidget and in its state class, we define 2 local variables.

class PickerPage extends StatefulWidget {
PickerPage({Key key, this.title}) : super(key: key);

final String title;

@override
_PickerPageState createState() => _PickerPageState();
}

class _PickerPageState extends State<PickerPage> {
File _cameraFile;
File _galleryFile;

@override
Widget build(BuildContext context) {
return null;
}

Step 3. Then create functions that ImagePicker will immediately call.

void _takeGalleryPicture() async {
var galleryFile = await ImagePicker.pickImage(source: ImageSource.gallery);

setState(() {
_galleryFile = galleryFile;
});
}

void _takeCameraPicture() async {
var cameraFile = await ImagePicker.pickImage(source: ImageSource.camera);

setState(() {
_cameraFile = cameraFile;
});
}

--

--