feat: meal tracking, dish recognition UX improvements, English AI prompts
Backend: - Translate all recognition prompts (receipt, products, dish) from Russian to English - Add lang parameter to Recognizer interface and pass locale.FromContext in handlers - DishResult type uses candidates array for multi-candidate responses Client: - Add meal tracking: diary provider, date selector, meal type model - DishResult parser: backward-compatible with legacy flat format and new candidates format - DishResultScreen: sticky bottom button, full-width portion/meal-type inputs, КБЖУ disclaimer moved under nutrition card, add date field to diary POST body - Recognition prompts now return dish/product names in user's preferred language - Onboarding, profile, home screen visual updates Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,11 +12,36 @@ final _recognitionServiceProvider = Provider<RecognitionService>((ref) {
|
||||
});
|
||||
|
||||
/// Entry screen — lets the user choose how to add products.
|
||||
class ScanScreen extends ConsumerWidget {
|
||||
/// If [GoRouterState.extra] is a non-null String, it is treated as a meal type ID
|
||||
/// and the screen immediately opens the camera for dish recognition.
|
||||
class ScanScreen extends ConsumerStatefulWidget {
|
||||
const ScanScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
ConsumerState<ScanScreen> createState() => _ScanScreenState();
|
||||
}
|
||||
|
||||
class _ScanScreenState extends ConsumerState<ScanScreen> {
|
||||
bool _autoStarted = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_autoStarted) return;
|
||||
final mealType = GoRouterState.of(context).extra as String?;
|
||||
if (mealType != null && mealType.isNotEmpty) {
|
||||
_autoStarted = true;
|
||||
// Defer to avoid calling context navigation during build.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_pickAndRecognize(context, _Mode.dish, mealType: mealType);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Добавить продукты')),
|
||||
body: ListView(
|
||||
@@ -33,21 +58,21 @@ class ScanScreen extends ConsumerWidget {
|
||||
emoji: '🧾',
|
||||
title: 'Сфотографировать чек',
|
||||
subtitle: 'Распознаем все продукты из чека',
|
||||
onTap: () => _pickAndRecognize(context, ref, _Mode.receipt),
|
||||
onTap: () => _pickAndRecognize(context, _Mode.receipt),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ModeCard(
|
||||
emoji: '🥦',
|
||||
title: 'Сфотографировать продукты',
|
||||
subtitle: 'Холодильник, стол, полка — до 3 фото',
|
||||
onTap: () => _pickAndRecognize(context, ref, _Mode.products),
|
||||
onTap: () => _pickAndRecognize(context, _Mode.products),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ModeCard(
|
||||
emoji: '🍽️',
|
||||
title: 'Определить блюдо',
|
||||
subtitle: 'КБЖУ≈ по фото готового блюда',
|
||||
onTap: () => _pickAndRecognize(context, ref, _Mode.dish),
|
||||
onTap: () => _pickAndRecognize(context, _Mode.dish),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ModeCard(
|
||||
@@ -63,9 +88,9 @@ class ScanScreen extends ConsumerWidget {
|
||||
|
||||
Future<void> _pickAndRecognize(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
_Mode mode,
|
||||
) async {
|
||||
_Mode mode, {
|
||||
String? mealType,
|
||||
}) async {
|
||||
final picker = ImagePicker();
|
||||
|
||||
List<XFile> files = [];
|
||||
@@ -120,11 +145,11 @@ class ScanScreen extends ConsumerWidget {
|
||||
final dish = await service.recognizeDish(files.first);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
context.push('/scan/dish', extra: dish);
|
||||
context.push('/scan/dish', extra: {'dish': dish, 'meal_type': mealType});
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
debugPrint('Recognition error: $e\n$s');
|
||||
} catch (recognitionError) {
|
||||
debugPrint('Recognition error: $recognitionError');
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context); // close loading
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
Reference in New Issue
Block a user