ANDREAS_LATANOWSKY_CPD_1910877/lib/ocr_page.dart

63 lines
1.7 KiB
Dart
Raw Normal View History

2023-11-21 19:48:58 +01:00
import 'package:cpd_app/http_utils.dart';
import 'package:cpd_app/image_uploader.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class OCRPage extends StatefulWidget {
const OCRPage({super.key});
@override
State<OCRPage> createState() => _OCRPageState();
}
class _OCRPageState extends State<OCRPage> {
String _extractedText = '';
final ImageUploader _imageUploader = ImageUploader();
final HttpUtils _httpUtils = HttpUtils();
@override
void initState() {
super.initState();
uploadImage("lorem.png");
}
Future<void> uploadImage(String img) async {
//hier wird der user sein bild auswählen können
//aktuell hardcoded bild zum testen
String imageName = img;
Uint8List imageBytes = await _imageUploader.buildImageFile(imageName);
String lang = await _httpUtils.performHttpRequest(imageBytes, imageName);
String text = await _imageUploader.performOcr(imageBytes, imageName, lang);
setState(() {
_extractedText = text;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('OCR'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () => uploadImage("lorem.png"),
child: const Text('Test Upload Image'),
),
Text(_extractedText),
TextButton(
onPressed: () {
Clipboard.setData(ClipboardData(text: _extractedText));
},
child: const Text('Copy to Clipboard'),
),
],
),
),
);
}
}