-
-
Notifications
You must be signed in to change notification settings - Fork 493
/
image_editor_demo.dart
79 lines (75 loc) · 2.45 KB
/
image_editor_demo.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import 'package:example/common/image_picker/image_picker.dart';
import 'package:example/common/utils/crop_editor_helper.dart';
import 'package:extended_image/extended_image.dart';
import 'package:ff_annotation_route_core/ff_annotation_route_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
@FFRoute(
name: 'fluttercandies://simpleimageeditor',
routeName: 'ImageEditor',
description: 'Crop with image editor.',
exts: <String, dynamic>{
'group': 'Simple',
'order': 6,
},
)
class SimpleImageEditor extends StatefulWidget {
@override
_SimpleImageEditorState createState() => _SimpleImageEditorState();
}
class _SimpleImageEditorState extends State<SimpleImageEditor> {
final GlobalKey<ExtendedImageEditorState> editorKey =
GlobalKey<ExtendedImageEditorState>();
bool _cropping = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ImageEditor'),
),
body: ExtendedImage.asset(
'assets/image.jpg',
fit: BoxFit.contain,
mode: ExtendedImageMode.editor,
enableLoadState: true,
extendedImageEditorKey: editorKey,
cacheRawData: true,
//maxBytes: 1024 * 50,
initEditorConfigHandler: (ExtendedImageState? state) {
return EditorConfig(
maxScale: 4.0,
cropRectPadding: const EdgeInsets.all(20.0),
hitTestSize: 20.0,
initCropRectType: InitCropRectType.imageRect,
cropAspectRatio: CropAspectRatios.ratio4_3,
editActionDetailsIsChanged: (EditActionDetails? details) {
//print(details?.totalScale);
});
},
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.crop),
onPressed: () {
cropImage();
}),
);
}
Future<void> cropImage() async {
if (_cropping) {
return;
}
_cropping = true;
try {
final EditImageInfo fileData = kIsWeb
? (await cropImageDataWithDartLibrary(state: editorKey.currentState!))
: (await cropImageDataWithNativeLibrary(
state: editorKey.currentState!));
final String? fileFath = await ImageSaver.save(
'extended_image_cropped_image.jpg', fileData.data!);
showToast('save image : $fileFath');
} finally {
_cropping = false;
}
}
}