I'm trying to send an image and text to Gemini using the firebase_ai package in Flutter, but I'm getting a persistent error: The method 'DataPart' isn't defined for the type 'AiAssistantService'.
The strange thing is that I am using the official code structure from the examples.
Here is my function:
import 'dart:typed_data';
import 'package:firebase_ai/firebase_ai.dart';
// ... other imports
Future<void> getResponseForImage(String userInput, Uint8List imageBytes) async {
try {
final googleAI = FirebaseAI.googleAI();
final model = googleAI.generativeModel(
model: 'gemini-1.5-flash-latest',
);
// According to docs, this should be the correct way to structure the content
final content = [
TextPart("Some text prompt"),
DataPart('image/jpeg', imageBytes), // <-- The error happens here
];
final response = await model.generateContent(content);
print(response.text);
} catch (e) {
print("An error occurred: $e");
}
}
I was expecting the code to work correctly without any errors. Instead, I always get the error: 'DataPart' isn't defined.
I have already tried many things to fix this:
- I ran 'flutter clean'.
- I deleted the pubspec.lock file and ran 'flutter pub get'.
- I ran 'flutter pub cache repair'.
- I restarted VS Code many times.
None of these solutions worked.
DataPart is not definederror.