Initialize and configure the SDK

  1. Import the Passio Nutrition AI Package

import 'package:nutrition_ai/nutrition_ai_sdk.dart';
  1. Configure the SDK with the Key you obtained by signing up at https://www.passio.ai/nutrition-ai.

void configureSDK() async {
  String passioKey = "Your_PassioSDK_Key";
  var configuration = PassioConfiguration(passioKey);
  passioStatus = await NutritionAI.instance.configureSDK(configuration);
  switch(passioStatus.mode) {
    // Handle result of the configuration process.
    case PassioMode.notReady: { break; }
    case PassioMode.isBeingConfigured: { break; }
    case PassioMode.failedToConfigure: { break; }
    case PassioMode.isDownloadingModels: { break; }
    case PassioMode.isReadyForDetection: { break; }
  }
}
class PassioStatus {
  PassioMode mode = PassioMode.notReady;
  List<String>? missingFiles;
  String? debugMessage;
  PassioSDKError? error;
  int? activeModels;
}

The mode of the PassioStatus defines what is the current status of the configuration process. There are 5 different modes, and they all should be handled by the implementing side.

enum PassioMode {
  notReady,
  failedToConfigure,
  isBeingConfigured,
  isDownloadingModels,
  isReadyForDetection
}
  • notReady -> The configuration process hasn't started yet.

  • failedToConfigure -> There was an error during the configuration process.

  • isBeingConfigured -> The SDK is still in the configuration process. Normally, you shouldn't receive this mode as a callback to the configure method. If you do please contact our support team.

  • isDownloadingModels -> The files required by the SDK to work are not present and are currently being downloaded.

  • isReadyForDetection -> The configuration process is over and all the SDKs functionalities are available.

  1. Request authorization to use the camera and add the PassioPreview widget:

Future<void> _checkPermission() async {
  if (await Permission.camera.request().isGranted) {
    _startFoodDetection();
  }
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Stack(
      children: [
        const PassioPreview(),
        ...
      ],
    ),
  );
}
  1. Add the method startFoodDetection() and register a FoodRecognitionListener

void _startFoodDetection() {
  var detectionConfig = FoodDetectionConfiguration();
  detectionConfig.detectBarcodes = true;
  NutritionAI.instance.startFoodDetection(detectionConfig, this);
}

@override
void recognitionResults(FoodCandidates foodCandidates) {
  // Handle recognition results
}
  1. Stop Food Detection on widget dispose:

@override
void dispose() {
  NutritionAI.instance.stopFoodDetection();
  super.dispose();
}
  1. Get nutritional information for food using a PassioID as a food identifier:

var attributes = await NutritionAI.instance.lookupPassioAttributesFor(passioID);

If at any point you need help from the Passio team, please reach out to us at support@passiolife.com

Last updated