scan to list working fine

This commit is contained in:
davmar
2026-08-29 11:23:24 +02:00
parent 2d8fc46a30
commit 2a5a922aab
13 changed files with 1233 additions and 8 deletions
+50 -2
View File
@@ -8,10 +8,16 @@ import 'package:flutter/services.dart';
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
import 'package:image_picker/image_picker.dart';
import 'products_screen.dart';
import 'review_screen.dart';
import 'services/product_repository.dart';
import 'services/receipt_parser.dart';
import 'utils/constants.dart';
class ScanScreen extends StatefulWidget {
const ScanScreen({super.key});
const ScanScreen({super.key, required this.repository});
final ProductRepository repository;
@override
State<ScanScreen> createState() => _ScanScreenState();
@@ -99,6 +105,32 @@ class _ScanScreenState extends State<ScanScreen> {
setState(() => _busy = false);
}
}
if (mounted && _extractedText.isNotEmpty) {
await _openReview(_extractedText);
}
}
Future<void> _openReview(String rawText) async {
final items = ReceiptParser.parse(rawText);
if (!mounted) return;
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => ReviewScreen(
items: items,
rawText: rawText,
repository: widget.repository,
),
),
);
}
void _openProducts() {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => ProductsScreen(repository: widget.repository),
),
);
}
@override
@@ -106,7 +138,16 @@ class _ScanScreenState extends State<ScanScreen> {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text(kAppName)),
appBar: AppBar(
title: const Text(kAppName),
actions: [
IconButton(
tooltip: 'Products',
onPressed: _openProducts,
icon: const Icon(Icons.inventory_2_outlined),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
@@ -130,6 +171,13 @@ class _ScanScreenState extends State<ScanScreen> {
icon: const Icon(Icons.receipt_long_outlined),
label: const Text('Use sample receipt'),
),
if (_extractedText.isNotEmpty) ...[
const SizedBox(height: 8),
OutlinedButton(
onPressed: _busy ? null : () => _openReview(_extractedText),
child: const Text('Review items'),
),
],
if (_busy) ...[
const SizedBox(height: 16),
const LinearProgressIndicator(),