From 2a80c8dc699b9da56c9767b39d0566a24001e686 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 2 Sep 2023 15:38:08 +0900 Subject: [PATCH 1/3] add trailing commas --- .../photo_edit_state_notifier.dart | 248 ++++++++++++------ 1 file changed, 163 insertions(+), 85 deletions(-) diff --git a/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart b/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart index f9aec226d..7a92f0501 100644 --- a/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart +++ b/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart @@ -79,7 +79,8 @@ class PhotoEditStateNotifier extends StateNotifier { throw UnsupportedError("$file is unsupported."); } final imageData = await ImageDescriptor.encoded( - await ImmutableBuffer.fromUint8List(initialImage)); + await ImmutableBuffer.fromUint8List(initialImage), + ); final defaultSize = Size(imageData.width.toDouble(), imageData.height.toDouble()); @@ -93,7 +94,9 @@ class PhotoEditStateNotifier extends StateNotifier { } Future _drawImage( - PhotoEdit attemptState, bool isReactionMarge) async { + PhotoEdit attemptState, + bool isReactionMarge, + ) async { final initialImage = state.initialImage; if (initialImage == null) return null; final editorOption = ImageEditorOption(); @@ -104,18 +107,27 @@ class PhotoEditStateNotifier extends StateNotifier { if (!attemptState.clipMode) { final offset = attemptState.cropOffset; final size = attemptState.cropSize; - editorOption.addOption(ClipOption( - x: offset.dx, y: offset.dy, width: size.width, height: size.height)); + editorOption.addOption( + ClipOption( + x: offset.dx, + y: offset.dy, + width: size.width, + height: size.height, + ), + ); } final presets = ColorFilterPresets().presets; for (final colorPreset in attemptState.adaptivePresets) { editorOption.addOptions( - presets.firstWhere((element) => element.name == colorPreset).option); + presets.firstWhere((element) => element.name == colorPreset).option, + ); } final result = await ImageEditor.editImage( - image: initialImage, imageEditorOption: editorOption); + image: initialImage, + imageEditorOption: editorOption, + ); return result; } @@ -139,22 +151,26 @@ class PhotoEditStateNotifier extends StateNotifier { final padding = 20 * state.defaultSize.width / state.actualSize.width; final removedPaddingImage = await ImageEditor.editImage( - image: resultImage, - imageEditorOption: ImageEditorOption() - ..addOptions([ - ClipOption( - x: padding + - (state.defaultSize.width - state.cropSize.width) / 2, - y: padding + - (state.defaultSize.height - state.cropSize.height) / 2, - width: state.cropSize.width, - height: state.cropSize.height) - ])); + image: resultImage, + imageEditorOption: ImageEditorOption() + ..addOptions([ + ClipOption( + x: padding + (state.defaultSize.width - state.cropSize.width) / 2, + y: padding + (state.defaultSize.height - state.cropSize.height) / 2, + width: state.cropSize.width, + height: state.cropSize.height, + ), + ]), + ); return removedPaddingImage; } Offset resolveRotatedOffset( - Offset cropOffset, Size cropSize, Size defaultSize, int angle) { + Offset cropOffset, + Size cropSize, + Size defaultSize, + int angle, + ) { final rotatedX = defaultSize.width - cropSize.width - cropOffset.dx; return Offset(cropOffset.dy, rotatedX); } @@ -162,30 +178,41 @@ class PhotoEditStateNotifier extends StateNotifier { /// 画像を回転する void rotate() { final angle = ((state.angle - 90) % 360).abs(); - draw(state.copyWith( - angle: angle, - defaultSize: Size(state.defaultSize.height, state.defaultSize.width), - cropSize: Size(state.cropSize.height, state.cropSize.width), - cropOffset: resolveRotatedOffset( - state.cropOffset, state.cropSize, state.defaultSize, angle), - emojis: [ - for (final emoji in state.emojis) - emoji.copyWith( + draw( + state.copyWith( + angle: angle, + defaultSize: Size(state.defaultSize.height, state.defaultSize.width), + cropSize: Size(state.cropSize.height, state.cropSize.width), + cropOffset: resolveRotatedOffset( + state.cropOffset, + state.cropSize, + state.defaultSize, + angle, + ), + emojis: [ + for (final emoji in state.emojis) + emoji.copyWith( angle: emoji.angle - pi / 2, - position: Offset(emoji.position.dy, - state.defaultSize.width - emoji.scale - emoji.position.dx)) - ], - selectedEmojiIndex: null, - )); + position: Offset( + emoji.position.dy, + state.defaultSize.width - emoji.scale - emoji.position.dx, + ), + ), + ], + selectedEmojiIndex: null, + ), + ); } /// 画像を切り取る void crop() { - draw(state.copyWith( - clipMode: !state.clipMode, - colorFilterMode: false, - selectedEmojiIndex: null, - )); + draw( + state.copyWith( + clipMode: !state.clipMode, + colorFilterMode: false, + selectedEmojiIndex: null, + ), + ); } void decideDrawArea(Size size) { @@ -198,10 +225,13 @@ class PhotoEditStateNotifier extends StateNotifier { final defaultSize = state.defaultSize; final offset = state.cropOffset; final validatedCropSize = Size( - max(0, min(size.width, defaultSize.width - offset.dx + 1)), - max(0, min(size.height, defaultSize.height - offset.dy + 1))); - final validateOffset = Offset(max(0, min(offset.dx, defaultSize.width)), - max(0, min(offset.dy, defaultSize.height))); + max(0, min(size.width, defaultSize.width - offset.dx + 1)), + max(0, min(size.height, defaultSize.height - offset.dy + 1)), + ); + final validateOffset = Offset( + max(0, min(offset.dx, defaultSize.width)), + max(0, min(offset.dy, defaultSize.height)), + ); return state.copyWith( cropSize: validatedCropSize, @@ -211,36 +241,60 @@ class PhotoEditStateNotifier extends StateNotifier { /// 画像の切り取り範囲の左上を移動する void cropMoveLeftTop(PointerMoveEvent detail) { - state = validateCrop(state.copyWith( + state = validateCrop( + state.copyWith( cropOffset: state.cropOffset + detail.localDelta, - cropSize: Size(state.cropSize.width - detail.localDelta.dx, - state.cropSize.height - detail.localDelta.dy))); + cropSize: Size( + state.cropSize.width - detail.localDelta.dx, + state.cropSize.height - detail.localDelta.dy, + ), + ), + ); } /// 画像の切り取り範囲の右上を移動する void cropMoveRightTop(PointerMoveEvent detail) { - state = validateCrop(state.copyWith( + state = validateCrop( + state.copyWith( cropOffset: Offset( - state.cropOffset.dx, state.cropOffset.dy + detail.localDelta.dy), - cropSize: Size(state.cropSize.width + detail.localDelta.dx, - state.cropSize.height - detail.localDelta.dy))); + state.cropOffset.dx, + state.cropOffset.dy + detail.localDelta.dy, + ), + cropSize: Size( + state.cropSize.width + detail.localDelta.dx, + state.cropSize.height - detail.localDelta.dy, + ), + ), + ); } /// 画像の切り取り範囲の左下を移動する void cropMoveLeftBottom(PointerMoveEvent detail) { - state = validateCrop(state.copyWith( + state = validateCrop( + state.copyWith( cropOffset: Offset( - state.cropOffset.dx + detail.localDelta.dx, state.cropOffset.dy), - cropSize: Size(state.cropSize.width - detail.localDelta.dx, - state.cropSize.height + detail.localDelta.dy))); + state.cropOffset.dx + detail.localDelta.dx, + state.cropOffset.dy, + ), + cropSize: Size( + state.cropSize.width - detail.localDelta.dx, + state.cropSize.height + detail.localDelta.dy, + ), + ), + ); } /// 画像の切り取り範囲の右下を移動する void cropMoveRightBottom(PointerMoveEvent detail) { - state = validateCrop(state.copyWith( + state = validateCrop( + state.copyWith( cropOffset: Offset(state.cropOffset.dx, state.cropOffset.dy), - cropSize: Size(state.cropSize.width + detail.localDelta.dx, - state.cropSize.height + detail.localDelta.dy))); + cropSize: Size( + state.cropSize.width + detail.localDelta.dx, + state.cropSize.height + detail.localDelta.dy, + ), + ), + ); } /// 画像の色調補正のプレビューを切り替える @@ -258,18 +312,20 @@ class PhotoEditStateNotifier extends StateNotifier { final editedImage = state.editedImage; if (editedImage == null) return; final previewImage = await ImageEditor.editImage( - image: editedImage, - imageEditorOption: ImageEditorOption() - ..addOption(const ScaleOption(300, 300, keepRatio: true))); + image: editedImage, + imageEditorOption: ImageEditorOption() + ..addOption(const ScaleOption(300, 300, keepRatio: true)), + ); if (previewImage == null) return; final result = [ for (final preset in ColorFilterPresets().presets) ColorFilterPreview( - name: preset.name, - image: await ImageEditor.editImage( - image: previewImage, - imageEditorOption: ImageEditorOption() - ..addOptions(preset.option))) + name: preset.name, + image: await ImageEditor.editImage( + image: previewImage, + imageEditorOption: ImageEditorOption()..addOptions(preset.option), + ), + ), ].whereNotNull(); state = state.copyWith(colorFilterPreviewImages: result.toList()); @@ -283,7 +339,8 @@ class PhotoEditStateNotifier extends StateNotifier { await draw(state.copyWith(adaptivePresets: list)); } else { await draw( - state.copyWith(adaptivePresets: [...state.adaptivePresets, name])); + state.copyWith(adaptivePresets: [...state.adaptivePresets, name]), + ); } await createPreviewImage(); } @@ -291,9 +348,10 @@ class PhotoEditStateNotifier extends StateNotifier { /// リアクションを追加する Future addReaction(Account account, BuildContext context) async { final reaction = await showDialog( - context: context, - builder: (context) => - ReactionPickerDialog(account: account, isAcceptSensitive: true)); + context: context, + builder: (context) => + ReactionPickerDialog(account: account, isAcceptSensitive: true), + ); if (reaction == null) return; switch (reaction) { @@ -302,9 +360,12 @@ class PhotoEditStateNotifier extends StateNotifier { if (_acceptReactions.none((e) => e == reaction.baseName)) { if (!mounted) return; final dialogResult = await showDialog( - context: context, - builder: (context) => LicenseConfirmDialog( - emoji: reaction.baseName, account: account)); + context: context, + builder: (context) => LicenseConfirmDialog( + emoji: reaction.baseName, + account: account, + ), + ); if (dialogResult != true) return; _acceptReactions.add(reaction.baseName); } @@ -316,16 +377,22 @@ class PhotoEditStateNotifier extends StateNotifier { return; } - state = state.copyWith(emojis: [ - ...state.emojis, - EditedEmojiData( + state = state.copyWith( + emojis: [ + ...state.emojis, + EditedEmojiData( emoji: reaction, scale: 100, position: Offset( - state.cropOffset.dx + (state.cropSize.width) / 2 - 50, - state.cropOffset.dy + (state.cropSize.height) / 2 - 50), - angle: 0), - ], selectedEmojiIndex: state.emojis.length, clipMode: false); + state.cropOffset.dx + (state.cropSize.width) / 2 - 50, + state.cropOffset.dy + (state.cropSize.height) / 2 - 50, + ), + angle: 0, + ), + ], + selectedEmojiIndex: state.emojis.length, + clipMode: false, + ); } double _startScale = 0; @@ -345,8 +412,9 @@ class PhotoEditStateNotifier extends StateNotifier { if (selectedIndex == null) return; final emojis = state.emojis.toList(); emojis[selectedIndex] = emojis[selectedIndex].copyWith( - scale: _startScale * detail.scale, - angle: _startAngle + detail.rotation); + scale: _startScale * detail.scale, + angle: _startAngle + detail.rotation, + ); state = state.copyWith(emojis: emojis, clipMode: false); } @@ -357,9 +425,11 @@ class PhotoEditStateNotifier extends StateNotifier { if (selectedIndex == null) return; final emojis = state.emojis.toList(); emojis[selectedIndex] = emojis[selectedIndex].copyWith( - position: Offset( - emojis[selectedIndex].position.dx + event.localDelta.dx, - emojis[selectedIndex].position.dy + event.localDelta.dy)); + position: Offset( + emojis[selectedIndex].position.dx + event.localDelta.dx, + emojis[selectedIndex].position.dy + event.localDelta.dy, + ), + ); state = state.copyWith(emojis: emojis); } @@ -367,11 +437,19 @@ class PhotoEditStateNotifier extends StateNotifier { /// リアクションを選択する void selectReaction(int index) { state = state.copyWith( - clipMode: false, colorFilterMode: false, selectedEmojiIndex: index); + clipMode: false, + colorFilterMode: false, + selectedEmojiIndex: index, + ); } void clearSelectMode() { - draw(state.copyWith( - selectedEmojiIndex: null, colorFilterMode: false, clipMode: false)); + draw( + state.copyWith( + selectedEmojiIndex: null, + colorFilterMode: false, + clipMode: false, + ), + ); } } From a19869349fd878beee0536931a30501454851e5e Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:48:40 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E5=BC=95=E6=95=B0=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/providers.dart | 5 +---- .../photo_edit_state_notifier.dart | 17 ++++------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/providers.dart b/lib/providers.dart index 1a526b112..d12721829 100644 --- a/lib/providers.dart +++ b/lib/providers.dart @@ -161,10 +161,7 @@ final errorEventProvider = final photoEditProvider = StateNotifierProvider.autoDispose( - (ref) => PhotoEditStateNotifier( - const PhotoEdit(), - ref.read(dioProvider), - ), + (ref) => PhotoEditStateNotifier(const PhotoEdit()), ); final importExportRepository = diff --git a/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart b/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart index 7a92f0501..ec5931bfb 100644 --- a/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart +++ b/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart @@ -3,8 +3,6 @@ import 'dart:typed_data'; import 'dart:ui'; import 'package:collection/collection.dart'; -import 'package:dio/dio.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -56,13 +54,9 @@ class EditedEmojiData with _$EditedEmojiData { } class PhotoEditStateNotifier extends StateNotifier { - static List _acceptReactions = []; + static final List _acceptReactions = []; - final Dio dio; - PhotoEditStateNotifier( - super.state, - this.dio, - ); + PhotoEditStateNotifier(super.state); /// 状態を初期化する Future initialize(MisskeyPostFile file) async { @@ -93,10 +87,7 @@ class PhotoEditStateNotifier extends StateNotifier { ); } - Future _drawImage( - PhotoEdit attemptState, - bool isReactionMarge, - ) async { + Future _drawImage(PhotoEdit attemptState) async { final initialImage = state.initialImage; if (initialImage == null) return null; final editorOption = ImageEditorOption(); @@ -133,7 +124,7 @@ class PhotoEditStateNotifier extends StateNotifier { /// 画像の描画を反映する Future draw(PhotoEdit attemptState) async { - final editedImage = await _drawImage(attemptState, false); + final editedImage = await _drawImage(attemptState); if (editedImage == null) return; state = attemptState.copyWith(editedImage: editedImage); } From b18f555f0cfe4d8f5015a02c68420921ecae7121 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:51:27 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=82=AF=E3=83=AD=E3=83=83=E3=83=97?= =?UTF-8?q?=E6=99=82=E3=81=AB=E5=85=83=E3=81=AE=E7=94=BB=E5=83=8F=E3=81=AE?= =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=82=BA=E3=82=92=E8=B6=85=E3=81=88=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photo_edit_page/photo_edit_state_notifier.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart b/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart index ec5931bfb..989144cb5 100644 --- a/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart +++ b/lib/state_notifier/photo_edit_page/photo_edit_state_notifier.dart @@ -215,18 +215,18 @@ class PhotoEditStateNotifier extends StateNotifier { final size = state.cropSize; final defaultSize = state.defaultSize; final offset = state.cropOffset; - final validatedCropSize = Size( - max(0, min(size.width, defaultSize.width - offset.dx + 1)), - max(0, min(size.height, defaultSize.height - offset.dy + 1)), - ); - final validateOffset = Offset( + final validatedOffset = Offset( max(0, min(offset.dx, defaultSize.width)), max(0, min(offset.dy, defaultSize.height)), ); + final validatedCropSize = Size( + max(1, min(size.width, defaultSize.width - validatedOffset.dx)), + max(1, min(size.height, defaultSize.height - validatedOffset.dy)), + ); return state.copyWith( cropSize: validatedCropSize, - cropOffset: validateOffset, + cropOffset: validatedOffset, ); }