machine with Flutter at the moment, you can use FirebaseStudio (https://studio.firebase.google.com), an entirely web-based workspace for full-stack application development, complete with the latest generative AI from Gemini, and full-fidelity app previews, powered by cloud emulators. 14
A simple input field A "Generate" button A text area for output Create a new file called generate_text.dart and copy and paste following: import 'package:flutter/material.dart'; class GenerateTextPage extends StatefulWidget { const GenerateTextPage({super.key}); } @override _GenerateTextPageState createState() => _GenerateTextPageState(); class _GenerateTextPageState extends State<GenerateTextPage> { final TextEditingController _inputController = TextEditingController(); String _outputText = ''; 20
add import statement like: import 'generate_text.dart'; find home key in build function and point it to load GenerateTextPage ... home: const GenerateTextPage(), ... It should load some UI like below: 25
in Firebase". It is a client sdk for Flutter Apps. When working in production environment. You should definitely use firebase_ai . However for quick prototyping, we can use google_generative_ai package. It is unsafe and for prototyping only. 27
AI Dart SDK: dependencies: google_generative_ai: ^0.4.7 It has been depricated. But We will use it for prototyping only. Then do flutter pub get in the UI or from Terminal, run: flutter pub get 28
statement: import 'package:google_generative_ai/google_generative_ai.dart'; Create a field in GenerateTextPage and initilize it in initSatate() function: final apiKey = "YOUR_API_KEY"; var _model; @override void initState() { super.initState(); _model = GenerativeModel( model: "gemini-2.5-pro-preview-05-06", apiKey: apiKey, ); } 29
below, also add async keyword to the function signature void _generateOutput() async { final response = await _model.generateContent([ Content.text(_inputController.text) ]); print(response.text); } setState(() { _outputText = response.text; }); Display this output in your UI for a basic AI experience. 30
pubspec.yaml file as below: dependencies: google_generative_ai: ^0.4.7 image_picker: 1.0.4 Then do flutter pub get in the UI or from Terminal, run: flutter pub get 34
final _formKey = GlobalKey<FormState>(); // Image file File? _selectedImage; // Class level array for item types final List<String> _itemTypes = ['Fashion', 'Toys', 'Electronics', 'Books', 'Home', 'Sports', "Fruits"]; // List of additional features tags final List<String> _additionalFeatures = []; // Controller for the tag input field 36
(placeholder) void _pickLocation() async { // In a real implementation, this would integrate with Google Places API // For now, just show a placeholder dialog void _selectLocation(String location) { setState(() { _formData['location'] = location; _locationController.text = location; }); Navigator.of(context).pop(); } 39
from additional features void _removeTag(String tag) { setState(() { _additionalFeatures.remove(tag); _formData['additionalFeatures'] = _additionalFeatures; }); } // Method to submit the form 42
AddProductPage ui. add import statement like: import 'add_product.dart'; find home key in build function and point it to load AddProductPage ... home: const AddProductPage(), ... Re launch and it should show the Add Product UI. 72
statement: import 'package:google_generative_ai/google_generative_ai.dart'; Create a field in AddProductPage and initilize it in initSatate() function: final apiKey = "YOUR_API_KEY"; var _model; @override void initState() { super.initState(); _model = GenerativeModel( model: "gemini-2.5-pro-preview-05-06", apiKey: apiKey, ); } 75
models to return specific formats and specific schemas, we use GenerationConfig() to define what kind of out put we are expecting. Not only define the response structure but also what kind of type of properties we are expecting. final List<String> _itemTypes = ['Fashion', 'Toys', 'Electronics', 'Books', 'Home', 'Sports', "Fruits"]; ... _model = GenerativeModel( model: "gemini-2.5-pro-preview-05-06", apiKey: apiKey, generationConfig: GenerationConfig( responseMimeType: "application/json", responseSchema: Schema.object( properties: { "title" : Schema.string(), "description" : Schema.string(), "type" : Schema.enumString( enumValues: _itemTypes, description: "The type of the item" 76
to UI like below: ... ElevatedButton( onPressed: generateAIContent, child: const Text( 'Generate AI Content', ), ), ... and a function at bottom of the file: void generateAIContent() { } 79
listing this item for sale at online market. Its location is ${LOCATION}. Its price is ${PRICE} pkr. Help me write a appealing title, 10 lines of description, type and features of this item. The tone should be natural. 80
so when button pressed, send input to Gemini: void generateAIContent() async { if (_selectedImage == null) return; String prompt = "I'm listing this item for sale at online market"; if (_formData["location"] != null && _formData["location"].isNotEmpty) { prompt = "$prompt. Its location is ${_formData["location"]}."; } if (_priceController.text.isNotEmpty) { prompt = "$prompt. Its price is ${_priceController.text} pkr."; } prompt = "$prompt. Help me write a appealing title, 10 lines of description, type and features of this item." 81
to the generateAIContent() function at the bottom: final content = Content.multi( [ TextPart(prompt), DataPart("image/png", _selectedImage!.readAsBytesSync()) ] ); var response = await _model.generateContent([content]); We are testing the Gemini multi-modality. It understands text as well as photos. 83
(_selectedImage == null) return; String prompt = "I'm listing this item for sale at online market"; if (_formData["location"] != null && _formData["location"].isNotEmpty) { prompt = "$prompt. Its location is ${_formData["location"]}."; } if (_priceController.text.isNotEmpty) { prompt = "$prompt. Its price is ${_priceController.text} pkr."; } 86
lines of description, type and features of this item." " The tone should be natural."; print("gemini prompt is $prompt"); final content = Content.multi( [ TextPart(prompt), DataPart("image/png", _selectedImage!.readAsBytesSync()) ] ); var response = await _model.generateContent([content]); print("gemini response is ${response.text}"); var responseJson = jsonDecode(response.text); _titleController.text = responseJson["title"] ?? ""; 87
if (responseJson["features"] != null && responseJson["features"].isNotEmpty ) { _additionalFeatures.clear(); for (String feature in responseJson["features"]) { _additionalFeatures.add(feature); } } setState(() {}); } Result: A smart product form that auto-generates compelling title, descriptions, types and features. 88
a basic Flutter app Built a smart UI with an input field, generate button, and output area Integrated the Gemini API using the google_generative_ai package Used text and image prompts to generate contextual product data Built a dynamic product form that leverages AI for smart content generation 90
content generation Gemini enables working with text, images, and structured JSON Flutter is a powerful toolkit for building intelligent mobile UIs Schema-guided generation helps ensure predictable, structured outputs 91
with Flutter Gemini API – Explore Google’s generative AI Firebase AI Flutter package – Official Firebase AI plugin for Flutter google_generative_ai package – Generative AI for prototyping Firebase Studio – A no-setup, web-based IDE with AI tools BuildwAI GitHub - The source code of this workshop. GDGLahore - Pakistan's Largest Developer Community Adil Soomro - Founder Imagitor, Houzi Co Founder BooleanBites Ltd. 92
cases Add chat or voice capabilities to your AI assistant Use AI to generate summaries, recommendations, or user insights Switch to firebase_ai for secure and scalable production apps Thank you for following along. 93