
Ever wondered if snapping a picture of your food could do more than just look good on Instagram? With Snap & Snack, you can turn food photography into actionable nutritional insights. This blog walks you through how we built this AI-powered nutrition guide, helping users make smarter dietary choices effortlessly.
By the end of this blog, you’ll learn how to:
Use Flutter to create an app for food image uploads.
Set up an API on Cloud Run to process food images using Gemini AI.
Store nutritional data in Firestore.
The Problem
Maintaining a healthy diet is often easier said than done. Manual food logging is tedious, and most people lack the expertise to analyze their meals’ nutritional content. This often leads to poor eating habits and an unbalanced diet. Snap & Snack addresses these challenges by offering an effortless way to analyze and track nutritional intake.
The Solution
Our app leverages advanced AI to process food images and extract detailed nutritional information. By combining instant analysis with data storage and personalized insights, Snap & Snack makes it easy for users to:
Monitor their dietary intake.
Receive actionable recommendations for healthier eating.
Track their progress over time.
Features
Instant Nutrition Analysis: Simply snap a picture of your meal, and let our app do the rest. Using the Gemini API 2.0, Snap & Snack provides a complete nutritional breakdown, including calories, carbohydrates, fiber, vitamins, protein.
Firestore screenshot Effortless Logging: No more manual tracking! Each analysis is automatically saved in Firestore, creating a comprehensive food diary for you to reference anytime
Architecture Overview

Design
Our solution leverages:
Frontend: A Flutter-based app for image uploads.
Backend: Cloud Run to host the API and integrate Gemini AI for food analysis.
Database: Firestore to store detailed nutritional data for each meal.
Design Choices
Flutter: Chosen for its cross-platform capabilities and rich UI components.
Cloud Run: Provides a serverless, scalable solution to host APIs.
Gemini AI: Offers advanced image analysis for extracting nutritional details.
Firestore: Ensures fast, real-time storage and retrieval of user data.
Prerequisites
Before you start, ensure you have the following:
Flutter SDK installed.
Google Cloud SDK for deploying Cloud Run services.
Firestore Database with native mode enabled.
Google Cloud Credits: You can sign up for free credits
A valid API key for Gemini AI
Basic knowledge of Python, Flutter, and REST APIs.
Step-by-Step Instructions
Step 1: Create the Flutter App
Initialize a Flutter project:
flutter create snap_snack
cd snap_snack
Add dependencies for image access and HTTP requests:
dependencies:
image_picker: ^0.8.5+3
http: ^0.15.0
Grant image access permissions in AndroidManifest.xml (Android)
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
Step 2: Implement the Image Upload Feature
Create a button to pick or capture images:
import 'package:image_picker/image_picker.dart';
final picker = ImagePicker();
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
Upload the image to the Cloud Run API using the http package:
import 'dart:convert';
import 'package:http/http.dart' as http;
final response = await http.post(
Uri.parse('<CLOUD_RUN_API_URL>'),
headers: {"Content-Type": "application/json"},
body: json.encode({"file": pickedFile.path}),
);
Step 3: Deploy the Backend on Cloud Run
Prepare the backend environment:
pip install flask google-cloud-firestore google-generativeai
Implement the API in main.py
Deploy the function to Cloud Run
Step 4: Store Data in Firestore
The backend stores processed nutritional data in Firestore:
doc_ref = db.collection('nutrition').document()
doc_ref.set(response)
Step 5: Integrate API in Flutter App
Update your app to display nutritional data returned by the API:
if (response.statusCode == 200) {
final data = json.decode(response.body);
print('Nutritional Info: $data');
}
Result
App functionality
Firestore db Screenshot
Challenges Faced
Firestore Integration: Initially, we encountered issues while integrating Firestore with Cloud Run due to database configuration settings. Switching Firestore to native mode resolved the problem.
Future Developments
Personalized Insights: Enhanced user-specific recommendations based on eating habits.
Interactive Chatbot: A conversational AI feature to answer users’ questions about nutritional values and recommendations.
Reminder: · For those who often fall into unhealthy eating patterns, Snap & Snack sends gentle reminders and alerts to help you stay on track.
Conclusion
Snap & Snack bridges the gap between casual food photography and serious nutrition tracking. By combining the power of AI with user-friendly features, it empowers users to take charge of their health effortlessly.
Comments