mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Added image picker
This commit is contained in:
@ -4,6 +4,7 @@ import 'package:comunic/lists/conversation_messages_list.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/new_conversation_message.dart';
|
||||
import 'package:comunic/ui/tiles/conversation_message_tile.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/list_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -82,6 +83,11 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Pick and send an image
|
||||
Future<void> _sendImage(BuildContext context) async {
|
||||
final image = await pickImage(context);
|
||||
}
|
||||
|
||||
/// Send a new message
|
||||
Future<void> _submitMessage(BuildContext context, String content) async {
|
||||
//Send the message
|
||||
@ -141,15 +147,15 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
// Image area
|
||||
/*new Container(
|
||||
new Container(
|
||||
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
||||
child: new IconButton(
|
||||
icon: new Icon(
|
||||
Icons.photo_camera,
|
||||
color: Theme.of(context).accentColor,
|
||||
),
|
||||
onPressed: () async {}),
|
||||
),*/
|
||||
onPressed: () => _sendImage(context)),
|
||||
),
|
||||
|
||||
// Message area
|
||||
new Flexible(
|
||||
|
50
lib/utils/files_utils.dart
Normal file
50
lib/utils/files_utils.dart
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user