@@ -7,10 +7,11 @@ import 'package:simple_edge_detection/edge_detection.dart';
7
7
import 'package:flutter/material.dart' ;
8
8
import 'package:image_picker/image_picker.dart' ;
9
9
import 'package:path_provider/path_provider.dart' ;
10
- import 'package:simple_edge_detection_example/image_preview .dart' ;
10
+ import 'package:simple_edge_detection_example/cropping_preview .dart' ;
11
11
12
12
import 'camera_view.dart' ;
13
13
import 'edge_detector.dart' ;
14
+ import 'image_view.dart' ;
14
15
15
16
class Scan extends StatefulWidget {
16
17
@override
@@ -21,6 +22,7 @@ class _ScanState extends State<Scan> {
21
22
CameraController controller;
22
23
List <CameraDescription > cameras;
23
24
String imagePath;
25
+ String croppedImagePath;
24
26
EdgeDetectionResult edgeDetectionResult;
25
27
26
28
@override
@@ -44,6 +46,10 @@ class _ScanState extends State<Scan> {
44
46
}
45
47
46
48
Widget _getMainWidget () {
49
+ if (croppedImagePath != null ) {
50
+ return ImageView (imagePath: croppedImagePath);
51
+ }
52
+
47
53
if (imagePath == null && edgeDetectionResult == null ) {
48
54
return CameraView (
49
55
controller: controller
@@ -91,12 +97,18 @@ class _ScanState extends State<Scan> {
91
97
return Align (
92
98
alignment: Alignment .bottomCenter,
93
99
child: FloatingActionButton (
94
- //foregroundColor: Colors.white,
95
- child: Icon (Icons .arrow_back),
100
+ child: Icon (Icons .check),
96
101
onPressed: () {
102
+ if (croppedImagePath == null ) {
103
+ return _processImage (
104
+ imagePath, edgeDetectionResult
105
+ );
106
+ }
107
+
97
108
setState (() {
98
- edgeDetectionResult = null ;
99
109
imagePath = null ;
110
+ edgeDetectionResult = null ;
111
+ croppedImagePath = null ;
100
112
});
101
113
},
102
114
),
@@ -163,6 +175,24 @@ class _ScanState extends State<Scan> {
163
175
});
164
176
}
165
177
178
+ Future _processImage (String filePath, EdgeDetectionResult edgeDetectionResult) async {
179
+ if (! mounted || filePath == null ) {
180
+ return ;
181
+ }
182
+
183
+ bool result = await EdgeDetector ().processImage (filePath, edgeDetectionResult);
184
+
185
+ if (result == false ) {
186
+ return ;
187
+ }
188
+
189
+ setState (() {
190
+ imageCache.clearLiveImages ();
191
+ imageCache.clear ();
192
+ croppedImagePath = imagePath;
193
+ });
194
+ }
195
+
166
196
void onTakePictureButtonPressed () async {
167
197
String filePath = await takePicture ();
168
198
@@ -172,8 +202,8 @@ class _ScanState extends State<Scan> {
172
202
}
173
203
174
204
void _onGalleryButtonPressed () async {
175
- final picker = ImagePicker ();
176
- final pickedFile = await picker.getImage (source: ImageSource .gallery);
205
+ ImagePicker picker = ImagePicker ();
206
+ PickedFile pickedFile = await picker.getImage (source: ImageSource .gallery);
177
207
final filePath = pickedFile.path;
178
208
179
209
log ('Picture saved to $filePath ' );
0 commit comments