feat: crop circle avatar on import

This commit is contained in:
poka 2022-06-12 22:12:00 +02:00
parent 5ee80a5af4
commit 86e2f3b2d7
4 changed files with 53 additions and 7 deletions

View File

@ -42,6 +42,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data

View File

@ -11,6 +11,7 @@ import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
import 'package:gecko/screens/transaction_in_progress.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';
import 'package:image_cropper/image_cropper.dart';
class WalletOptionsProvider with ChangeNotifier {
TextEditingController address = TextEditingController();
@ -88,14 +89,33 @@ class WalletOptionsProvider with ChangeNotifier {
return '';
}
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: imageFile.path,
aspectRatioPresets: [CropAspectRatioPreset.square],
cropStyle: CropStyle.circle,
uiSettings: [
AndroidUiSettings(
hideBottomControls: true,
toolbarTitle: 'Personnalisation',
toolbarColor: Colors.deepOrange,
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: true),
IOSUiSettings(
title: 'Cropper',
),
],
);
final newPath = "${imageDirectory.path}/${pickedFile.name}";
await imageFile.copy(newPath);
// final File newImage = File(newPath);
// await newImage.writeAsBytes(await pickedFile.readAsBytes());
// await pickedFile.saveTo(newPath);
// await Future.delayed(const Duration(milliseconds: 100));
if (croppedFile != null) {
await File(croppedFile.path).rename(newPath);
} else {
log.w('No image selected.');
return '';
}
// await imageFile.copy(newPath);
log.i(newPath);
return newPath;

View File

@ -593,6 +593,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
image_cropper:
dependency: "direct main"
description:
name: image_cropper
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
image_cropper_for_web:
dependency: transitive
description:
name: image_cropper_for_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
image_cropper_platform_interface:
dependency: transitive
description:
name: image_cropper_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
image_picker:
dependency: "direct main"
description:

View File

@ -5,7 +5,7 @@ description: Pay with G1.
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.8+8
version: 0.0.8+9
environment:
sdk: '>=2.12.0 <3.0.0'
@ -71,6 +71,7 @@ dependencies:
dots_indicator: ^2.1.0
web_socket_channel: ^2.2.0
connectivity_plus: ^2.3.3
image_cropper: ^2.0.3
dev_dependencies:
# flutter_launcher_icons: ^0.9.2