1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Force square account image

This commit is contained in:
Pierre HUBERT 2021-03-13 18:11:28 +01:00
parent e70aaabbc9
commit f8910c8f8b
5 changed files with 14 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import 'package:file_picker/file_picker.dart';
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mime/mime.dart';
@ -91,6 +92,7 @@ Future<BytesFile> showPickFileDialog({
List<String> allowedMimeTypes,
int imageMaxWidth,
int imageMaxHeight,
CropAspectRatio aspectRatio,
}) async {
assert(allowedMimeTypes != null);
@ -133,7 +135,7 @@ Future<BytesFile> showPickFileDialog({
file = BytesFile(image.path.split("/").last, await image.readAsBytes());
file = await showImageCropper(context, file);
file = await showImageCropper(context, file, aspectRatio: aspectRatio);
break;

View File

@ -17,8 +17,8 @@ import '../../utils/files_utils.dart';
/// Attempt to crop image
///
/// Return original image in case of error / if the user did not crop the image
Future<BytesFile> showImageCropper(
BuildContext context, BytesFile source) async {
Future<BytesFile> showImageCropper(BuildContext context, BytesFile source,
{CropAspectRatio aspectRatio}) async {
assert(context != null);
assert(source != null);
@ -32,6 +32,7 @@ Future<BytesFile> showImageCropper(
File cropped = await ImageCropper.cropImage(
sourcePath: file.absolute.path,
compressFormat: ImageCompressFormat.png,
aspectRatio: aspectRatio,
androidUiSettings: AndroidUiSettings(
toolbarColor: Colors.black,
toolbarTitle: tr("Crop Photo"),

View File

@ -12,6 +12,7 @@ import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
import 'package:identicon/identicon.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:random_string/random_string.dart';
import 'package:settings_ui/settings_ui.dart';
@ -160,7 +161,8 @@ class _AccountImageSettingsScreenState
/// Upload a new account image
void _uploadAccountImage() async {
try {
final image = await pickImage(context);
final image = await pickImage(context,
aspectRatio: CropAspectRatio(ratioX: 5, ratioY: 5));
if (image == null) return;

View File

@ -254,7 +254,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
});
} catch (e, s) {
logError(e, s);
snack(context, tr("Failed to pick image for post!"));
snack(context, tr("Failed to pick an image for the post!"));
}
}

View File

@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:random_string/random_string.dart';
@ -15,12 +16,14 @@ import '../ui/dialogs/pick_file_dialog.dart';
/// Ask the user to choose an image, either from the gallery or using the camera
///
/// Throws an exception null in case of failure
Future<BytesFile> pickImage(BuildContext context) async {
Future<BytesFile> pickImage(BuildContext context,
{CropAspectRatio aspectRatio}) async {
return await showPickFileDialog(
context: context,
allowedMimeTypes: ["image/png", "image/jpeg", "image/gif"],
imageMaxHeight: 10000,
imageMaxWidth: 10000,
aspectRatio: aspectRatio,
);
}