Flutter- How to open phone gallery?
9,841
If you only want to select from the Gallery, then you can use the image_picker plugin. If cropping is important to you, then I'll reconsider my answer as image_picker
doesn't provide that.
import 'package:image_picker/image_picker.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Image Picker Example'),
),
body: new Center(
child: _image == null
? new Text('No image selected.')
: new Image.file(_image),
),
floatingActionButton: new FloatingActionButton(
onPressed: getImage,
tooltip: 'Pick Image',
child: new Icon(Icons.add_a_photo),
),
);
}
}
![satish](https://lh6.googleusercontent.com/-PA8dauX8bto/AAAAAAAAAAI/AAAAAAAAAGg/b6BphmC227g/photo.jpg?sz=256)
Author by
satish
Updated on December 06, 2022Comments
-
satish over 1 year
I want to open gallery directory here, I am using this code but is showing all option I want to open the only gallery.
List images; int maxImageNo = 10; bool selectSingleImage = false; File _imageFile; _pickImageFromGallery() async { File file; String result; try { result = await FlutterImagePickCrop.pickAndCropImage(_gallery); } on PlatformException catch (e) { result = e.message; print(e.message); } if (!mounted) return; setState(() { imageFile = new File(result); _platformMessage = result; });}