mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Force square account image
This commit is contained in:
parent
e70aaabbc9
commit
f8910c8f8b
@ -8,6 +8,7 @@ import 'package:file_picker/file_picker.dart';
|
|||||||
import 'package:filesize/filesize.dart';
|
import 'package:filesize/filesize.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:image_cropper/image_cropper.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ Future<BytesFile> showPickFileDialog({
|
|||||||
List<String> allowedMimeTypes,
|
List<String> allowedMimeTypes,
|
||||||
int imageMaxWidth,
|
int imageMaxWidth,
|
||||||
int imageMaxHeight,
|
int imageMaxHeight,
|
||||||
|
CropAspectRatio aspectRatio,
|
||||||
}) async {
|
}) async {
|
||||||
assert(allowedMimeTypes != null);
|
assert(allowedMimeTypes != null);
|
||||||
|
|
||||||
@ -133,7 +135,7 @@ Future<BytesFile> showPickFileDialog({
|
|||||||
|
|
||||||
file = BytesFile(image.path.split("/").last, await image.readAsBytes());
|
file = BytesFile(image.path.split("/").last, await image.readAsBytes());
|
||||||
|
|
||||||
file = await showImageCropper(context, file);
|
file = await showImageCropper(context, file, aspectRatio: aspectRatio);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ import '../../utils/files_utils.dart';
|
|||||||
/// Attempt to crop image
|
/// Attempt to crop image
|
||||||
///
|
///
|
||||||
/// Return original image in case of error / if the user did not crop the image
|
/// Return original image in case of error / if the user did not crop the image
|
||||||
Future<BytesFile> showImageCropper(
|
Future<BytesFile> showImageCropper(BuildContext context, BytesFile source,
|
||||||
BuildContext context, BytesFile source) async {
|
{CropAspectRatio aspectRatio}) async {
|
||||||
assert(context != null);
|
assert(context != null);
|
||||||
assert(source != null);
|
assert(source != null);
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ Future<BytesFile> showImageCropper(
|
|||||||
File cropped = await ImageCropper.cropImage(
|
File cropped = await ImageCropper.cropImage(
|
||||||
sourcePath: file.absolute.path,
|
sourcePath: file.absolute.path,
|
||||||
compressFormat: ImageCompressFormat.png,
|
compressFormat: ImageCompressFormat.png,
|
||||||
|
aspectRatio: aspectRatio,
|
||||||
androidUiSettings: AndroidUiSettings(
|
androidUiSettings: AndroidUiSettings(
|
||||||
toolbarColor: Colors.black,
|
toolbarColor: Colors.black,
|
||||||
toolbarTitle: tr("Crop Photo"),
|
toolbarTitle: tr("Crop Photo"),
|
||||||
|
@ -12,6 +12,7 @@ import 'package:comunic/utils/intl_utils.dart';
|
|||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:identicon/identicon.dart';
|
import 'package:identicon/identicon.dart';
|
||||||
|
import 'package:image_cropper/image_cropper.dart';
|
||||||
import 'package:random_string/random_string.dart';
|
import 'package:random_string/random_string.dart';
|
||||||
import 'package:settings_ui/settings_ui.dart';
|
import 'package:settings_ui/settings_ui.dart';
|
||||||
|
|
||||||
@ -160,7 +161,8 @@ class _AccountImageSettingsScreenState
|
|||||||
/// Upload a new account image
|
/// Upload a new account image
|
||||||
void _uploadAccountImage() async {
|
void _uploadAccountImage() async {
|
||||||
try {
|
try {
|
||||||
final image = await pickImage(context);
|
final image = await pickImage(context,
|
||||||
|
aspectRatio: CropAspectRatio(ratioX: 5, ratioY: 5));
|
||||||
|
|
||||||
if (image == null) return;
|
if (image == null) return;
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
});
|
});
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
logError(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!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:image_cropper/image_cropper.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:random_string/random_string.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
|
/// Ask the user to choose an image, either from the gallery or using the camera
|
||||||
///
|
///
|
||||||
/// Throws an exception null in case of failure
|
/// 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(
|
return await showPickFileDialog(
|
||||||
context: context,
|
context: context,
|
||||||
allowedMimeTypes: ["image/png", "image/jpeg", "image/gif"],
|
allowedMimeTypes: ["image/png", "image/jpeg", "image/gif"],
|
||||||
imageMaxHeight: 10000,
|
imageMaxHeight: 10000,
|
||||||
imageMaxWidth: 10000,
|
imageMaxWidth: 10000,
|
||||||
|
aspectRatio: aspectRatio,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user