Apply AI
Gemini in Flutter
Wiring Google's Gemini models into Flutter through the REST API.
- Problem
- Flutter teams want generative AI without adopting a heavy, fast-moving SDK.
- Decision
- Integrated the Gemini REST API directly in Flutter and documented the pattern for the community.
- Result
- A practical guide and demo for Flutter developers.
- Flutter
- Dart
- Gemini
- REST
Sometimes the right call is to skip the SDK. Talking to Gemini over its REST API keeps a Flutter app light and the dependency surface small, which matters when the model side changes every month.
The shape is a plain HTTPS POST:
final res = await http.post( Uri.parse( "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$apiKey", ), headers: {"Content-Type": "application/json"}, body: jsonEncode({ "contents": [ { "parts": [ {"text": prompt}, ], }, ], }),);From there it is ordinary Dart: decode the response, handle errors, and render the result into the UI. I wrote the full version up for developers who want the pattern, not a black box.