1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Added image picker

This commit is contained in:
2019-04-25 11:13:02 +02:00
parent 3f75c565ca
commit c2891c3c84
4 changed files with 69 additions and 3 deletions

View File

@ -0,0 +1,50 @@
import 'dart:io';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
/// Files utilities
///
/// @author Pierre HUBERT
enum _ChooseImageSource { GALLERY, CAMERA }
/// Ask the user to choose an image, either from the gallery or using the camera
///
/// Returns null in case of failure
Future<File> pickImage(BuildContext context) async {
/// First, we ask the user to choose between image picker and camera
final result = await showDialog<_ChooseImageSource>(
context: context,
builder: (c) {
return AlertDialog(
title: Text(tr("Choose an image")),
actions: <Widget>[
//Gallery
FlatButton(
onPressed: () => Navigator.pop(context, _ChooseImageSource.GALLERY),
child: Text(
tr("Image gallery").toUpperCase(),
),
),
// Camera
FlatButton(
onPressed: () => Navigator.pop(context, _ChooseImageSource.CAMERA),
child: Text(
tr("Camera").toUpperCase(),
),
),
],
);
},
);
if (result == null) return null;
return await ImagePicker.pickImage(
source: result == _ChooseImageSource.CAMERA
? ImageSource.camera
: ImageSource.gallery);
}