63 lines
1.7 KiB
Dart
63 lines
1.7 KiB
Dart
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'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|