mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22: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/lists/users_list.dart';
|
||||||
import 'package:comunic/models/new_conversation_message.dart';
|
import 'package:comunic/models/new_conversation_message.dart';
|
||||||
import 'package:comunic/ui/tiles/conversation_message_tile.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/intl_utils.dart';
|
||||||
import 'package:comunic/utils/list_utils.dart';
|
import 'package:comunic/utils/list_utils.dart';
|
||||||
import 'package:comunic/utils/ui_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
|
/// Send a new message
|
||||||
Future<void> _submitMessage(BuildContext context, String content) async {
|
Future<void> _submitMessage(BuildContext context, String content) async {
|
||||||
//Send the message
|
//Send the message
|
||||||
@ -141,15 +147,15 @@ class _ConversationScreenState extends State<ConversationScreen> {
|
|||||||
child: new Row(
|
child: new Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Image area
|
// Image area
|
||||||
/*new Container(
|
new Container(
|
||||||
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
child: new IconButton(
|
child: new IconButton(
|
||||||
icon: new Icon(
|
icon: new Icon(
|
||||||
Icons.photo_camera,
|
Icons.photo_camera,
|
||||||
color: Theme.of(context).accentColor,
|
color: Theme.of(context).accentColor,
|
||||||
),
|
),
|
||||||
onPressed: () async {}),
|
onPressed: () => _sendImage(context)),
|
||||||
),*/
|
),
|
||||||
|
|
||||||
// Message area
|
// Message area
|
||||||
new Flexible(
|
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
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -30,6 +30,9 @@ dependencies:
|
|||||||
# SQLite database is used for caching
|
# SQLite database is used for caching
|
||||||
sqflite: ^1.1.5
|
sqflite: ^1.1.5
|
||||||
|
|
||||||
|
# Image picker is used whenever the user wants to send an image
|
||||||
|
image_picker: ^0.5.4+3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
Loading…
Reference in New Issue
Block a user