mirror of
https://github.com/mdanics/fluttergram.git
synced 2025-08-06 13:19:53 +08:00
updated image_picker plugin + added dialog to choose camera or gallery
This commit is contained in:
@ -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>(
|
||||||
setState(() {
|
context: context,
|
||||||
file = imageFile;
|
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(() {
|
||||||
|
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 {
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user