Skip to content

Conversation

thatfiredev
Copy link
Collaborator

No description provided.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @thatfiredev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new feature to the Friendly Meals Flutter application, enabling users to extract ingredients from an image using Optical Character Recognition (OCR) powered by Google's Gemini AI model. This enhancement streamlines the process of inputting ingredients for recipe generation by allowing users to simply upload a photo of ingredients rather than typing them manually.

Highlights

  • Image-based Ingredient Extraction: Implemented functionality to select an image from the device gallery and use the Gemini 2.5 Flash Lite model to identify and list food ingredients within the image.
  • Enhanced User Input: Added a camera icon to the ingredient input field, providing a direct way for users to initiate the image-to-text conversion process.
  • Loading State Feedback: Incorporated a visual loading indicator within the input field to inform users when the ingredient extraction process is active.
  • Dependency Management: Updated project dependencies to include the 'image_picker' package and adjusted the minimum Flutter SDK version to support the new features.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new feature for extracting ingredients from an image using a generative AI model. The implementation is well-structured, with clear state management for loading and error handling. My review focuses on improving the robustness and maintainability of the new functionality. I've identified a high-severity issue related to asynchronous UI updates that could cause a crash, and a medium-severity issue concerning hardcoded values that affect maintainability and correctness. Addressing these points will make the new feature more solid.

Comment on lines +57 to +62
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error processing image: $e'),
backgroundColor: Colors.red,
),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using BuildContext after an await call can lead to runtime errors if the widget is removed from the tree while the async operation is running (e.g., the user navigates to another screen). This violates the use_build_context_synchronously lint rule.

To prevent potential crashes, you should always check if the widget is still mounted before interacting with its BuildContext in an async method.

      if (!mounted) return;
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Error processing image: $e'),
          backgroundColor: Colors.red,
        ),
      );

Comment on lines +36 to +48
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-2.5-flash-lite',
);

final prompt = Content.multi([
TextPart("""
Please analyze this image and list all visible food ingredients.
Format the response as a comma-separated list of ingredients.
Be specific with measurements where possible,
but focus on identifying the ingredients accurately.
"""),
InlineDataPart('image/jpeg', imageBytes),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better maintainability and robustness, it's recommended to extract hardcoded values into constants and dynamically determine the image MIME type.

  1. Model Name & Prompt: The model name 'gemini-2.5-flash-lite' and the prompt text are hardcoded. Extracting them into const variables improves readability and makes them easier to update.
  2. MIME Type: The MIME type is hardcoded as 'image/jpeg'. The user might select a different image format (e.g., PNG), which could cause processing to fail. Using the mime package to determine the MIME type from the file path makes this more robust.

To apply this suggestion, you'll need to add import 'package:mime/mime.dart'; at the top of your file. The mime package is already available as a transitive dependency.

        const modelName = 'gemini-2.5-flash-lite';
        const ocrPrompt = """
            Please analyze this image and list all visible food ingredients.
            Format the response as a comma-separated list of ingredients.
            Be specific with measurements where possible, 
            but focus on identifying the ingredients accurately.
            """;
        final mimeType = lookupMimeType(pickedFile.path) ?? 'image/jpeg';
        final model = FirebaseAI.googleAI().generativeModel(
          model: modelName,
        );

        final prompt = Content.multi([
          TextPart(ocrPrompt),
          InlineDataPart(mimeType, imageBytes),
        ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant