mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-21 20:39:22 +00:00
Added image picker
This commit is contained in:
parent
3f75c565ca
commit
c2891c3c84
@ -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);
|
||||
}
|
@ -46,6 +46,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
image_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: image_picker
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.4+3"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -30,6 +30,9 @@ dependencies:
|
||||
# SQLite database is used for caching
|
||||
sqflite: ^1.1.5
|
||||
|
||||
# Image picker is used whenever the user wants to send an image
|
||||
image_picker: ^0.5.4+3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
Loading…
Reference in New Issue
Block a user