Merge bc9b9f3a92 into 344e84ae3e
This commit is contained in:
commit
7ee05bdaee
4 changed files with 93 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ import 'package:fluffychat/utils/platform_infos.dart';
|
|||
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
||||
import 'package:fluffychat/widgets/avatar_crop_dialog.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_view.dart';
|
||||
|
|
@ -139,10 +141,16 @@ class SettingsController extends State<Settings> {
|
|||
final result = await selectFiles(context, type: FileType.image);
|
||||
final pickedFile = result.firstOrNull;
|
||||
if (pickedFile == null) return;
|
||||
file = MatrixFile(
|
||||
bytes: await pickedFile.readAsBytes(),
|
||||
name: pickedFile.name,
|
||||
);
|
||||
var bytes = await pickedFile.readAsBytes();
|
||||
if (PlatformInfos.isDesktop || PlatformInfos.isWeb) {
|
||||
final cropped = await showDialog<Uint8List>(
|
||||
context: context,
|
||||
builder: (context) => AvatarCropDialog(image: bytes),
|
||||
);
|
||||
if (cropped == null) return;
|
||||
bytes = cropped;
|
||||
}
|
||||
file = MatrixFile(bytes: bytes, name: pickedFile.name);
|
||||
}
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
|
|||
72
lib/widgets/avatar_crop_dialog.dart
Normal file
72
lib/widgets/avatar_crop_dialog.dart
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:crop_image/crop_image.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
|
||||
class AvatarCropDialog extends StatefulWidget {
|
||||
final Uint8List image;
|
||||
|
||||
const AvatarCropDialog({super.key, required this.image});
|
||||
|
||||
@override
|
||||
AvatarCropDialogController createState() => AvatarCropDialogController();
|
||||
}
|
||||
|
||||
class AvatarCropDialogController extends State<AvatarCropDialog> {
|
||||
final controller = CropController(
|
||||
aspectRatio: 1,
|
||||
defaultCrop: const Rect.fromLTWH(0.1, 0.1, 0.8, 0.8),
|
||||
);
|
||||
|
||||
void onCancelAction() => Navigator.of(context).pop();
|
||||
|
||||
Future<void> onCropAction() async {
|
||||
final image = await controller.croppedBitmap();
|
||||
if (mounted) {
|
||||
final data = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
Navigator.of(context).pop(data?.buffer.asUint8List());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AvatarCropDialogView(this);
|
||||
}
|
||||
|
||||
class AvatarCropDialogView extends StatelessWidget {
|
||||
final AvatarCropDialogController controller;
|
||||
|
||||
const AvatarCropDialogView(this.controller, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(L10n.of(context).changeYourAvatar),
|
||||
content: SizedBox(
|
||||
width: 400,
|
||||
height: 400,
|
||||
child: CropImage(
|
||||
controller: controller.controller,
|
||||
image: Image.memory(controller.widget.image),
|
||||
gridColor: Colors.white,
|
||||
gridCornerSize: 20,
|
||||
touchSize: 20,
|
||||
alwaysShowThirdLines: true,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: controller.onCancelAction,
|
||||
child: Text(L10n.of(context).cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: controller.onCropAction,
|
||||
child: Text(L10n.of(context).ok),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -217,6 +217,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.15.0"
|
||||
crop_image:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crop_image
|
||||
sha256: "27cbce1685a595efee62caab81c98b49b636f765c1da86353f58f5b2bf2775d8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.17"
|
||||
cross_file:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ dependencies:
|
|||
blurhash_dart: ^1.2.1
|
||||
chewie: ^1.13.0
|
||||
collection: ^1.18.0
|
||||
crop_image: ^1.0.17
|
||||
cross_file: ^0.3.5
|
||||
desktop_drop: ^0.7.0
|
||||
desktop_notifications: ^0.6.3
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue