fix: repair recognition — migrate vision model and fix XFile handling

- Replace decommissioned llama-3.2-11b-vision-preview with
  meta-llama/llama-4-scout-17b-16e-instruct (Groq deprecation)
- Use XFile.readAsBytes() instead of File(path).readAsBytes() so
  Android content URIs (from gallery picks) are read correctly
- Add maxWidth/maxHeight constraints to image picker calls to reduce
  payload size
- Increase receiveTimeout from 30s to 120s to accommodate slow vision AI
- Log recognition errors via debugPrint instead of swallowing them

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-02-22 11:41:33 +02:00
parent deceedd4a7
commit 612a0eda60
4 changed files with 28 additions and 17 deletions

View File

@@ -1,5 +1,4 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
@@ -70,19 +69,28 @@ class ScanScreen extends ConsumerWidget {
) async {
final picker = ImagePicker();
List<File> files = [];
List<XFile> files = [];
if (mode == _Mode.products) {
// Allow up to 3 images.
final picked = await picker.pickMultiImage(imageQuality: 70);
final picked = await picker.pickMultiImage(
imageQuality: 70,
maxWidth: 1024,
maxHeight: 1024,
);
if (picked.isEmpty) return;
files = picked.take(3).map((x) => File(x.path)).toList();
files = picked.take(3).toList();
} else {
final source = await _chooseSource(context);
if (source == null) return;
final picked = await picker.pickImage(source: source, imageQuality: 70);
final picked = await picker.pickImage(
source: source,
imageQuality: 70,
maxWidth: 1024,
maxHeight: 1024,
);
if (picked == null) return;
files = [File(picked.path)];
files = [picked];
}
if (!context.mounted) return;
@@ -116,7 +124,8 @@ class ScanScreen extends ConsumerWidget {
context.push('/scan/dish', extra: dish);
}
}
} catch (e) {
} catch (e, s) {
debugPrint('Recognition error: $e\n$s');
if (context.mounted) {
Navigator.pop(context); // close loading
ScaffoldMessenger.of(context).showSnackBar(