1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-10 23:22:22 +02:00

fix(mobile): Fix for incorrectly naming edited files and structure change (#11741)

* Fix null name

* Fix null name and Fix button

* Remove extension correctly

* Refactoring the code and formatting

* formatting

* Fix for the extension name
This commit is contained in:
Yuvraj P
2024-08-24 16:30:31 -04:00
committed by GitHub
parent 00a7b80184
commit 843345df4f
4 changed files with 88 additions and 68 deletions

View File

@@ -3,6 +3,7 @@ import 'package:crop_image/crop_image.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/utils/hooks/crop_controller_hook.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'edit.page.dart';
import 'package:auto_route/auto_route.dart';
@@ -14,7 +15,8 @@ import 'package:auto_route/auto_route.dart';
@RoutePage()
class CropImagePage extends HookWidget {
final Image image;
const CropImagePage({super.key, required this.image});
final Asset asset;
const CropImagePage({super.key, required this.image, required this.asset});
@override
Widget build(BuildContext context) {
@@ -34,7 +36,13 @@ class CropImagePage extends HookWidget {
),
onPressed: () async {
final croppedImage = await cropController.croppedImage();
context.pushRoute(EditImageRoute(image: croppedImage));
context.pushRoute(
EditImageRoute(
asset: asset,
image: croppedImage,
isEdited: true,
),
);
},
),
],

View File

@@ -12,6 +12,7 @@ import 'package:immich_mobile/widgets/common/immich_toast.dart';
import 'package:auto_route/auto_route.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:path/path.dart' as p;
import 'package:immich_mobile/providers/album/album.provider.dart';
/// A stateless widget that provides functionality for editing an image.
@@ -24,18 +25,16 @@ import 'package:immich_mobile/providers/album/album.provider.dart';
@immutable
@RoutePage()
class EditImagePage extends ConsumerWidget {
final Asset? asset;
final Image? image;
final Asset asset;
final Image image;
final bool isEdited;
const EditImagePage({
super.key,
this.image,
this.asset,
}) : assert(
(image != null && asset == null) || (image == null && asset != null),
'Must supply one of asset or image',
);
required this.asset,
required this.image,
required this.isEdited,
});
Future<Uint8List> _imageToUint8List(Image image) async {
final Completer<Uint8List> completer = Completer();
image.image.resolve(const ImageConfiguration()).addListener(
@@ -58,19 +57,34 @@ class EditImagePage extends ConsumerWidget {
return completer.future;
}
Future<void> _saveEditedImage(
BuildContext context,
Asset asset,
Image image,
WidgetRef ref,
) async {
try {
final Uint8List imageData = await _imageToUint8List(image);
await PhotoManager.editor.saveImage(
imageData,
title: "${p.withoutExtension(asset.fileName)}_edited.jpg",
);
await ref.read(albumProvider.notifier).getDeviceAlbums();
Navigator.of(context).popUntil((route) => route.isFirst);
} catch (e) {
ImmichToast.show(
durationInSecond: 6,
context: context,
msg: 'Error: $e',
gravity: ToastGravity.CENTER,
);
}
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final ImageProvider provider = (asset != null)
? ImmichImage.imageProvider(asset: asset!)
: (image != null)
? image!.image
: throw Exception('Invalid image source type');
final Image imageWidget = (asset != null)
? Image(image: ImmichImage.imageProvider(asset: asset!))
: (image != null)
? image!
: throw Exception('Invalid image source type');
final Image imageWidget =
Image(image: ImmichImage.imageProvider(asset: asset));
return Scaffold(
appBar: AppBar(
@@ -85,44 +99,24 @@ class EditImagePage extends ConsumerWidget {
Navigator.of(context).popUntil((route) => route.isFirst),
),
actions: <Widget>[
if (image != null)
TextButton(
onPressed: () async {
try {
final Uint8List imageData = await _imageToUint8List(image!);
ImmichToast.show(
durationInSecond: 3,
context: context,
msg: 'Image Saved!',
gravity: ToastGravity.CENTER,
);
await PhotoManager.editor.saveImage(
imageData,
title: '${asset!.fileName}_edited.jpg',
);
await ref.read(albumProvider.notifier).getDeviceAlbums();
Navigator.of(context).popUntil((route) => route.isFirst);
} catch (e) {
ImmichToast.show(
durationInSecond: 6,
context: context,
msg: 'Error: ${e.toString()}',
gravity: ToastGravity.BOTTOM,
);
}
},
child: Text(
'Save to gallery',
style: Theme.of(context).textTheme.displayMedium,
TextButton(
onPressed: isEdited
? () => _saveEditedImage(context, asset, image, ref)
: null,
child: Text(
'Save to gallery',
style: TextStyle(
color:
isEdited ? Theme.of(context).iconTheme.color : Colors.grey,
),
),
),
],
),
body: Column(
children: <Widget>[
Expanded(
child: Image(image: provider),
child: image,
),
Container(
height: 80,
@@ -148,7 +142,9 @@ class EditImagePage extends ConsumerWidget {
color: Theme.of(context).iconTheme.color,
),
onPressed: () {
context.pushRoute(CropImageRoute(image: imageWidget));
context.pushRoute(
CropImageRoute(asset: asset, image: imageWidget),
);
},
),
Text('Crop', style: Theme.of(context).textTheme.displayMedium),