import 'package:flutter/material.dart'; import 'recognition_service.dart'; /// Shows the nutritional breakdown of a recognized dish. class DishResultScreen extends StatelessWidget { const DishResultScreen({super.key, required this.dish}); final DishResult dish; @override Widget build(BuildContext context) { final theme = Theme.of(context); final confPct = (dish.confidence * 100).toInt(); return Scaffold( appBar: AppBar(title: const Text('Распознано блюдо')), body: ListView( padding: const EdgeInsets.all(20), children: [ // Dish name + confidence Text( dish.dishName, style: theme.textTheme.headlineSmall ?.copyWith(fontWeight: FontWeight.bold), ), const SizedBox(height: 4), Row( children: [ Icon( Icons.info_outline, size: 14, color: theme.colorScheme.onSurfaceVariant, ), const SizedBox(width: 4), Text( 'Уверенность: $confPct%', style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ], ), const SizedBox(height: 24), // Nutrition card Card( child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Text( '≈ ${dish.calories.toInt()} ккал', style: theme.textTheme.titleLarge?.copyWith( fontWeight: FontWeight.bold, color: theme.colorScheme.primary, ), ), const Spacer(), Tooltip( message: 'Приблизительные значения на основе фото', child: Text( '≈', style: theme.textTheme.titleLarge?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ), ], ), const SizedBox(height: 12), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ _MacroChip( label: 'Белки', value: '${dish.proteinG.toStringAsFixed(1)} г', color: Colors.blue, ), _MacroChip( label: 'Жиры', value: '${dish.fatG.toStringAsFixed(1)} г', color: Colors.orange, ), _MacroChip( label: 'Углеводы', value: '${dish.carbsG.toStringAsFixed(1)} г', color: Colors.green, ), ], ), const SizedBox(height: 8), Text( 'Вес порции: ~${dish.weightGrams} г', style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ], ), ), ), // Similar dishes if (dish.similarDishes.isNotEmpty) ...[ const SizedBox(height: 20), Text('Похожие блюда', style: theme.textTheme.titleSmall), const SizedBox(height: 8), Wrap( spacing: 8, runSpacing: 4, children: dish.similarDishes .map((name) => Chip(label: Text(name))) .toList(), ), ], const SizedBox(height: 32), const Divider(), const SizedBox(height: 8), Text( 'КБЖУ приблизительные — определены по фото.', style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), textAlign: TextAlign.center, ), ], ), ); } } class _MacroChip extends StatelessWidget { const _MacroChip({ required this.label, required this.value, required this.color, }); final String label; final String value; final Color color; @override Widget build(BuildContext context) { return Column( children: [ Text( value, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16, color: color, ), ), Text( label, style: Theme.of(context).textTheme.labelSmall, ), ], ); } }