About
The Spike SDK provides a convenient interface for the Nutrition AI API, allowing you to analyze food images directly from your Flutter application. The SDK handles image encoding, API communication, and response parsing, making it easy to integrate nutritional analysis into your app.All Spike SDK async methods return
Future objects. Use try-catch blocks or .catchError() handlers for error handling. See Error Handling for details.Key Features
- AI-Powered Analysis — advanced computer vision for food identification and nutritional calculations
- Flexible Processing — choose between synchronous (wait for results) or asynchronous (background) processing
- Base64 Support — submit images as base64-encoded strings
- Complete Record Management — retrieve, update, and delete nutrition records
Available Methods
Analyzing Food Images
Synchronous Processing
Use synchronous analysis when you want to wait for the complete nutritional analysis before proceeding. This is ideal for scenarios where you need immediate results and can display a loading indicator.Processing Time: Synchronous processing takes some time depending on image complexity. Consider showing a loading indicator to users. If you see that the analysis is taking too long, the recommendation is to use asynchronous processing instead.
Asynchronous Processing
Use asynchronous processing when you want an immediate response without waiting for the analysis to complete. Record ID is returned. The image is processed in the background, and you can retrieve results later by requesting nutrition analysis using the record ID or receive them via webhook.Retrieving Results Asynchronously
After submitting an image for asynchronous processing, you can retrieve the results using the record ID. Check the processing status for completion success.Configuration Options
Customize the analysis usingNutritionalAnalysisConfig:
NutritionalAnalysisConfig
Analysis Modes
Default Nutritional Fields
IfincludeNutritionFields is not specified, only these basic fields are included:
energyKcalproteinGfatTotalGcarbohydrateG
Managing Nutrition Records
List Records by Date Range
Retrieve all nutrition records within a specified date range:Get a Specific Record
Retrieve a single nutrition record by its ID:Update Serving Size
Adjust the serving size of an existing record. All nutritional values are automatically recalculated proportionally:Delete a Record
Permanently remove a nutrition record (success status is returned regardless record is found or not):Response Data
NutritionRecord
The NutritionRecord class contains the analysis results:
NutritionRecordStatus
NutritionalUnit
NutritionRecordIngredient
NutritionalField
Use this enum to specify which nutritional fields to include in the analysis:
Error Handling
All nutrition methods returnFuture objects that can throw exceptions. Always wrap calls in try-catch blocks:
Common Error Scenarios
Image Guidelines
For optimal analysis results, guide your users to capture images that:- Center the food — capture the plate contents as the main subject
- Fill the frame — ensure the meal occupies most of the image
- Use proper lighting — natural or bright lighting works best
- Avoid obstructions — remove packaging and minimize utensils in frame
- Skip filters — avoid filters that alter the food’s appearance
Best Practices
1. Request Only What You Need
Each additional field, ingredient breakdown, or optional data increases processing time. Only request what your app actually uses:2. Consider your actual UI requirements:
- Do you display ingredients? If not, skip
includeIngredients. - Do you show Nutri-Score? If not, skip
includeNutriScore. - Which nutritional values do you actually display? Request only those.
3. Choose the Right Processing Mode
- Synchronous (
analyzeNutrition): Use when you need immediate results and can show a loading state - Asynchronous (
submitNutritionForAnalysis): Use for better UX when you don’t need immediate results, or when processing multiple images
4. Handle All Status Values
When using asynchronous processing, always check the record status before accessing results:5. Implement Webhook Handling
For production apps using asynchronous processing, implement webhook handling on your backend to receive real-time notifications when analysis completes.6. Create Reusable Configuration
If you’re using the same settings across your app, create a shared configuration helper:Related Documentation
- Nutrition AI Overview — API overview and key features
- Implementation Guide — Detailed API implementation patterns
- Asynchronous Processing — Webhook configuration and handling
- Nutritional Fields Reference — Complete list of available nutritional fields
