import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:image_picker/image_picker.dart'; import '../../core/constants/app_theme.dart'; import '../../core/models/recipe.dart'; import '../../core/providers.dart'; import '../share_receiver/quick_share_sheet.dart'; class ScannerScreen extends ConsumerStatefulWidget { const ScannerScreen({super.key}); @override ConsumerState createState() => _ScannerScreenState(); } class _ScannerScreenState extends ConsumerState { final ImagePicker _picker = ImagePicker(); bool _isProcessing = false; Future _captureFromCamera() async { final XFile? photo = await _picker.pickImage( source: ImageSource.camera, maxWidth: 1600, maxHeight: 1600, imageQuality: 85, ); if (photo != null) { _processImage(photo.path); } } Future _pickFromGallery() async { final XFile? image = await _picker.pickImage( source: ImageSource.gallery, maxWidth: 1600, maxHeight: 1600, imageQuality: 85, ); if (image != null) { _processImage(image.path); } } Future _processImage(String path) async { showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: Colors.transparent, builder: (ctx) => QuickShareSheet(imagePath: path), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Scan Recipe Photo'), ), body: Stack( children: [ // Viewfinder guide Padding( padding: const EdgeInsets.all(24.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( height: 320, width: double.infinity, decoration: BoxDecoration( color: AppTheme.surfaceElevated.withOpacity(0.5), borderRadius: BorderRadius.circular(20), border: Border.all(color: AppTheme.primary, width: 2), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppTheme.primary.withOpacity(0.12), shape: BoxShape.circle, ), child: const Icon( Icons.camera_enhance_rounded, color: AppTheme.primary, size: 44, ), ), const SizedBox(height: 16), const Text( 'Align Cookbook or Recipe Card', style: TextStyle( fontSize: 16, fontWeight: FontWeight.w700, color: AppTheme.textMain, ), ), const SizedBox(height: 6), const Padding( padding: EdgeInsets.symmetric(horizontal: 20), child: Text( 'Our multimodal Gemini AI automatically parses ingredients, instructions, and cooking times.', textAlign: TextAlign.center, style: TextStyle(fontSize: 12, color: AppTheme.textMuted), ), ), ], ), ), const SizedBox(height: 32), // Shutter actions Row( mainAxisAlignment: MainAxisAlignment.center, children: [ OutlinedButton.icon( onPressed: _pickFromGallery, icon: const Icon(Icons.photo_library_rounded), label: const Text('Gallery'), ), const SizedBox(width: 16), ElevatedButton.icon( onPressed: _captureFromCamera, icon: const Icon(Icons.camera_alt_rounded), label: const Text('Take Photo'), style: ElevatedButton.styleFrom( padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), ), ), ], ), ], ), ), if (_isProcessing) Container( color: Colors.black54, child: const Center( child: CircularProgressIndicator(color: AppTheme.primary), ), ), ], ), ); } }