updated image_picker plugin + added dialog to choose camera or gallery

This commit is contained in:
Matthew
2018-05-15 19:32:43 +02:00
parent 985a411cae
commit 4b090a8b33
2 changed files with 41 additions and 10 deletions

View File

@ -21,12 +21,12 @@ class _Uploader extends State<Uploader> {
bool uploading = false; bool uploading = false;
bool promted = false; bool promted = false;
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (file == null && promted == false) {
if (file == null && promted == false){
_selectImage(); _selectImage();
setState(() {promted = true;}); setState(() {
promted = true;
});
} }
return file == null return file == null
@ -66,11 +66,42 @@ class _Uploader extends State<Uploader> {
)); ));
} }
Future<Null> _selectImage() async { _selectImage() async {
File imageFile = await ImagePicker.pickImage(); return showDialog<Null>(
context: context,
barrierDismissible: false, // user must tap button!
child: new SimpleDialog(
title: const Text('Select assignment'),
children: <Widget>[
new SimpleDialogOption(
child: const Text('Take a photo'),
onPressed: () async {
Navigator.pop(context);
File imageFile =
await ImagePicker.pickImage(source: ImageSource.camera);
setState(() { setState(() {
file = imageFile; file = imageFile;
}); });
}),
new SimpleDialogOption(
child: const Text('Choose from Gallery'),
onPressed: () async {
Navigator.of(context).pop();
File imageFile =
await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
file = imageFile;
});
}),
new SimpleDialogOption(
child: const Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
)
],
));
} }
void compressImage() async { void compressImage() async {

View File

@ -5,7 +5,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
cloud_firestore: 0.3.0 cloud_firestore: 0.3.0
image_picker: 0.1.1 image_picker: 0.4.1
firebase_storage: 0.2.0 firebase_storage: 0.2.0
firebase_auth: 0.5.0 firebase_auth: 0.5.0
google_sign_in: 3.0.0 google_sign_in: 3.0.0