Lets talk to Gemini Ai
We need an Api Key , you can generate one from
To use the Gemini API, you'll need an API key. If you don't already have one, create a key in Google AI Studio.
Secure your API key
Keep your API key secure. We strongly recommend that you do not include the API key directly in your code, or check files that contain the key into version control systems. Instead, you should use a secrets store for your API key.
All the snippets in this quickstart assume that you're accessing your API key as a process environment variable. If you're developing a Flutter app, you can use String.fromEnvironment and pass --dart-define=API_KEY=$API_KEY to flutter build or flutter run to compile with the API key since the process environment will be different when running the app.
Create a new file consts.dart to store api key , we can also use environments.
Chat logic is in char_widget.dart
we will be using Gemini model : gemini-1.0-pro
in the initState let's initialise the model, for this, we will need to import in pubspec.yaml
create variable for model and chat session
We have created a chat session with some context and a prompt
The chat conversation can be displayed in the list, modify listviewbuilder to show the chat messages between AI and user
When the user types a message _sendChatMessage is called

Last updated