Skip to content

Commit

Permalink
Stop camera when processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed Sep 24, 2024
1 parent da888dc commit 87c038c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/screens/editor/photo_ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PhotoAiPage extends StatefulWidget {

class _PhotoAiPageState extends State<PhotoAiPage> {
static final _logger = Logger('PhotoAiPage');
bool processing = false;

processPhoto(file) async {
final nav = Navigator.of(context);
Expand Down Expand Up @@ -69,12 +70,18 @@ class _PhotoAiPageState extends State<PhotoAiPage> {
title: 'Nothing found',
message: 'Nothing tag-worthy found in the image.');
}
setState(() {
processing = false;
});
} else if (data['error'] != null) {
_logger.warning('Error: ${data["error"]}');
if (mounted) {
await showOkAlertDialog(
context: context, title: 'Error', message: '${data["error"]}');
}
setState(() {
processing = false;
});
}
} on FormatException {
_logger
Expand All @@ -85,20 +92,26 @@ class _PhotoAiPageState extends State<PhotoAiPage> {
title: 'Server error',
message: 'Malformed response from image-to-osm.');
}
nav.pop();
}
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: CameraCamera(
enableAudio: false,
resolutionPreset: ResolutionPreset.veryHigh,
onFile: (file) {
processPhoto(file);
},
),
body: processing
? Center(child: Text('processing...'))
: CameraCamera(
enableAudio: false,
resolutionPreset: ResolutionPreset.veryHigh,
onFile: (file) {
processPhoto(file);
setState(() {
processing = true;
});
},
),
);
}
}

0 comments on commit 87c038c

Please sign in to comment.