The Passio Nutrition AI SDK search functionality gives access to over 2.2 million food records in our nutritional database. The search api takes in a text query and returns a list of PassioFoodDataInfo results as well as a list of suggested searches
The PassioFoodDataInfo is used a reference object to fetch the full nutritional data. It has all of the attributes needed for displaying on a typical search screen: the name of the food, name of the brand (if possible), iconId, and a nutritional preview detailing the macro nutrients for a specified serving size and weight.
To fetch the PassioFoodItem using a search result, invoke the fetchFoodItemForDataInfo.
The search will return 50 items that best match the input term, as well as a list of suggested searches that are semantically or contextually close to the input term.
suggested searches: "coffee with whole milk", "coffee with creamer", "iced coffee"
UI Example
Create an input text field to collect the user query
Create a horizontal list scroll to display the suggestions
Create a vertical list to display the results of the search
If the user clicks on a suggestion, pass that string to the search API and reload the UI with the new results
Food Icons
The SDK gives the ability to fetch food icons for a specific passioId. There are two functions that can be used: lookupIconsFor and fetchIconsFor.
lookupIconsFor does a local search of the icons without doing any networking calls. It returns two icons. One is a placeholder icon depending on the type of food associated with the passioId. The second one is cached icon from a previous fetchIconsFor call, it it exists.
fetchIconsFor does a networking call to fetch an icon associated with the passioId, but it will check the local cache and return a previously fetched icon.
If displaying a PassioFoodItem, PassioIngredient or a PassioFoodDataInfo icon, pass the iconId to the appropriate icon function.
Example of how to use both of these functions to first display the placeholder icon, and then fetch the remote icon:
There are several functions that are used to retrieve the PassioFoodItem object, depending on the origin of the data. If the food item is being scanned using an image, the food item is fetched using either fetchFoodItemForPassioID or fetchFoodItemForProductCode. If search is being used to access to food item, the appropriate call is the fetchFoodItemForDataInfo.
But if there is a use case that requires to save just one attribute to a database, that will later on be used to retrieve the full PassioFoodItem object, then the refCode attribute is the answer. The refCode in combination with the fetchFoodItemForRefCode will retrieve the original food item object from Passio's nutritional database.
PassioSDK.instance.fetchFoodItemForPassioID("VEG0025") { foodItem ->// foodItem is the original object from the databaseval refCode = foodItem!!.refCode// refCode is stored and used in another session PassioSDK.instance.fetchFoodItemForRefCode(refCode) { refFoodItem ->// foodItem == refFoodItem }}
constfoodItem=awaitPassioSDK.fetchFoodItemForPassioID('VEG0025')// foodItem is the original object from the databaseconstrefCode=foodItem?.refCode// refCode is stored and used in another sessionconstrefCodeFoodItem=awaitPassioSDK.fetchFoodItemForRefCode(refCode)
final foodItem =awaitNutritionAI.instance.fetchFoodItemForPassioID('VEG0025');// foodItem is the original object from the databasefinal refCode = foodItem!.refCode;// refCode is stored and used in another sessionfinal refFoodItem =awaitNutritionAI.instance.fetchFoodItemForRefCode(refCode);// foodItem == refFoodItem
refCode is a string hash of a complex object and can reach lengths above 180 characters.
Using v2 PassioID in the v3 SDK
If the implementing app is transitioning from generation 2 to generation 3 of the SDK, and has already stored generation 2 PassioIDs, invoking the fetchFoodItemLegacy will retrieve the PassioFoodItem that was previously structured as PassioIDAttributes.