creek
The AI Image Editor of 2030git clone https://github.com/maydayv7/creek
lib/utils/image_actions_helper.dart (2094B)
1import 'dart:io';
2import 'package:flutter/material.dart';
3import 'package:share_plus/share_plus.dart';
4import 'package:creekui/data/models/image_model.dart';
5import 'package:creekui/services/image_service.dart';
6import 'package:creekui/ui/pages/share_to_file_page.dart';
7import 'package:creekui/ui/widgets/dialog.dart';
8import 'package:creekui/ui/widgets/text_field.dart';
9
10class ImageActionsHelper {
11 static Future<void> shareImage(BuildContext context, String filePath) async {
12 final file = File(filePath);
13 if (await file.exists()) {
14 await Share.shareXFiles([XFile(filePath)]);
15 }
16 }
17
18 static void sendToFiles(BuildContext context, String filePath) {
19 Navigator.push(
20 context,
21 MaterialPageRoute(
22 builder: (_) => ShareToFilePage(sharedImage: File(filePath)),
23 ),
24 );
25 }
26
27 static Future<void> renameImage(
28 BuildContext context,
29 ImageModel image,
30 VoidCallback onSuccess,
31 ) async {
32 final TextEditingController nameController = TextEditingController(
33 text: image.name,
34 );
35
36 await ShowDialog.show(
37 context,
38 title: "Rename Image",
39 primaryButtonText: "Save",
40 content: CommonTextField(
41 hintText: "Enter new name",
42 controller: nameController,
43 autoFocus: true,
44 ),
45 onPrimaryPressed: () async {
46 if (nameController.text.isNotEmpty) {
47 await ImageService().renameImage(
48 image.id,
49 nameController.text.trim(),
50 );
51 onSuccess();
52 if (context.mounted) Navigator.pop(context);
53 }
54 },
55 );
56 }
57
58 static Future<void> deleteImage(
59 BuildContext context,
60 ImageModel image,
61 VoidCallback onSuccess,
62 ) async {
63 await ShowDialog.show(
64 context,
65 title: "Delete Image?",
66 description: "This action cannot be undone.",
67 primaryButtonText: "Delete",
68 isDestructive: true,
69 onPrimaryPressed: () async {
70 await ImageService().deleteImage(image.id);
71 onSuccess();
72 if (context.mounted) Navigator.pop(context);
73 },
74 );
75 }
76}