AI Flutter Code Generator with Gemini API | Build with Google AI

Google for Developers · Beginner ·🛠️ AI Tools & Apps ·2y ago

Key Takeaways

Building an AI-powered Flutter code generator with Gemini API

Full Transcript

In this video, we'll explore how you can build an AI power tool that help you write Flutter code. Let's go. Hey folks, welcome to Build with Google AI, where we explore how you can build practical solutions with Google AI technology. Building user interfaces with Flutter is pretty great. It's really nice to be able to design and build user experiences for an application and have it work across multiple platforms. Even so, there's a lot to handle with building out a new interface. By the time you've stepped out of your third or 23rd design review meeting, you're probably wondering how you could get some help visualizing different looks for your user interface. With that in mind, one of my colleagues from the Flutter team decided to apply AI to this problem and have it quickly generate Flutter theme code using a couple of keywords from that last design review meeting. The Flutter theme agent is a Visual Studio Code extension that uses Google's Gemini API to generate code for Flutter visual themes. Here's a quick demo of the project. The theme agent works alongside the Flutter developer tools, lets you quickly generate visual settings as part of a Flutter theme data object. Once you've loaded the Flutter a project in the theme agent, you can generate themes and components using the command palette. Flutter theme The theme agent lets you generate a whole theme data object, a button style, a text style, or a color scheme. In this application, I'm setting the color scheme using the default scheme function, and you can see how it looks in the interface on the right. It's definitely a color scheme, and it's easy to build with the seed color, but it's not very interesting. So, let's generate a new one. Here I have a new function for my generated color scheme, and I'll put in a comment to describe the colors I want. Hot pink dark mode. I'll select this text so the generator function uses this information to create a new color scheme. Now, I'll open the command palette and select the Theme Agent color scheme command. The command takes my text input and combines it with some additional instructions for generating a Flutter color scheme and sends that request to the Gemini API. The AI model generates a color scheme code based on the instructions, and the Theme Agent inserts it into my code file. After a little clean up, we can see what our freshly minted color scheme looks like in the app. This color scheme might not be your cup of tea, but that's okay. Being able to generate schemes with minimal input means you can try lots of different options and find something that works for you and your team. Now, most interface designers will tell you that you should not just ship a generated color scheme without thoroughly evaluating it for usability and accessibility, and they're absolutely right about that. However, at the early stages of development, this type of tool can help you quickly explore different approaches before you pick that perfect design direction and start building out the user experience. Later on, I'll show you how to modify this project to generate different Flutter code and work more smoothly with your workflow. Before we get into that, let's talk to the developer of this project and have them explain how it works. All right, I'm joined today by the key contributor to the Flutter Theme Agent project and member of the Flutter developer relations team, Khan Wen. Thanks for being here. Hey, Joe. Thanks for having me. Okay, so first question. Why would you go ahead and build this? I mean, user interface development is hard work, but does AI actually make it any easier? Yeah, I mean, I think so. As developers, we're always in a position where we're learning new things, right? New technologies, new APIs, and everything is always new, and it's always coming. And so, I think AI has a potential to accelerate sort of that learning process for developers. For example, say, you know, there's a new API that comes out, and you're like, well, we want to generate construct this object, and you can essentially ask AI to construct this object, and you don't necessarily have to go and dig up the API docs and go through code samples. You can sort of generate your own code sample using AI. In addition to that, for the ideation phase, for example, myself as a designer, I'm still learning, I'm still figuring things out, but I'm very guilty of spending, you know, an hour in a color picker trying to find this the perfect shade of yellow, just so I can have a theme that has, you know, some yellow in it. And in that case, right, AI can help you accelerate that process. Really, the shade of yellow that I pick does not matter, and I just want something on the screen that I can see and then build from and iterate from. So, AI could generate that code, and then for ideation purposes, if I have that color scheme in mind, I ask AI give me back the code, and then I can take it from there and just keep tweaking and and building on top of it. And of course, from the developer relations perspective, I'm really excited about how AI has the potential to teach even, you know, non-programmers how to code and and make it more accessible in that way. You don't have to know exactly how to write that code to tell the computer to do that thing. So, that's super exciting, I think, in terms of opening the door for non-programmers being able to learn to code. All right. So, next question. How does the Flutter theme agent actually work? Yeah, so it takes the user's text input, so the developer can leave a comment of, you know, what kind of theme they want to generate, and it packages that up with a few things. So, this is what we call the instructions. Um and so, the instructions includes things like a little bit of context on, you know, what a theme data is, um along with a summarized um API, right? Explaining what a theme data is along with what uh property values exist for a theme data, and a couple of examples like, you know, here's what a color scheme looks like, or here's what a text theme looks like. And so, packages that up, ships it off to the Gemini API, and then once it gets a response, it just plops that right into your code. Okay, so next question. If I want to extend the Flutter theme agent, how do I go about doing that? Yeah, so you can clone the repo and jump in and update the examples and the instructions that are there to essentially get results that are closer to what you want. If you have examples of a great Flutter theme that you really like, you could dump that in there. Or say you have other specific themes that you want. So, component themes are a big thing with Flutter themes. You could also add that in there as well. And to take it a step further, you could just completely scrap the whole theme thing and replace it with any widget that you often, you know, use or would use often in your code. So, it can generate those widgets instead of a theme data. All right, so last question. From what you've explained, you're not actually building an AI model from scratch here, you're just using an existing one. So, does this really count as AI development? I mean, it does to me. I think so. At the end of the day, I mean, I think AI is just another tool that's in a developer's toolbox, right? You reach for it when you need it, and helps you get the job done. And I mean, if you think about it, it's like a hammer. To build a house, you don't necessarily need to build your own hammer. You can just go to the store, buy a hammer, and then use that to to do whatever you need to do. Um Um, can build a model. I mean, that's always an option, but if you don't need to, you don't really have to. At the end of the day, I really just hope that developers can feel more empowered to build AI-powered tools and apps like this one. And I mean, it's another tool in the toolbox, like I said. And so, ultimately, it hopefully helps you to build cool stuff and change the world. All right. So, thanks so much for being here and telling me about the Flutter Theme Agent. Thank you for having me, Joe. It's coding time. Let's look at how you can extend the Flutter Theme Agent to create your own AI-powered coding features. Don't worry about taking notes. There's a detailed tutorial linked in the description. The simplest way to extend the Flutter Theme Agent is to modify the prompt instructions and code of the existing commands. Like this button style function. I'm going to show you how to create a new command using the color scheme class. To start, make a copy of one of these code files and give it a new name. I made a copy of the color scheme TS file and called it color scheme 2.ts. I'm changing the instructions for this updated command so I don't have to clean up the extra syntax every time I generate a new scheme. To do that, I'm adding this new instruction to the prompt to not include the color scheme code syntax. I'm also removing the color scheme object syntax from the examples, so it's just a list of colors. That's all I need to create a new command code. Now, let's plug that code into the rest of the extension. I need to update the extension TS file to import the new code file, then register the new command. Finally, I need to update the package.json file to declare that new command color scheme set. That's it. Now, I'll hop over to the debug environment and try it out. Now, I can generate colors and try them immediately without having to do any cleanup. Hot pink with teal. The prompt instructions for generating this code include a summary description of the color scheme API and a couple of examples. We recommend including between two and four code examples in your prompt with a variety of output. All right, you can see that my updated command only generated the list of colors, so I can visualize it right away. Let's see what this new color scheme looks like. Not bad. What I like about this feature is you can use it to quickly iterate and visualize ideas with your team and explore different approaches without having to spend hours or days writing prototype code. All right, let's wrap this up. And that's all the time I have to tell you about this AI-powered code generator project, Flutter Theme Agent. Thanks to my guest Khan Nguyen from the Flutter Developer Relations team for building and sharing this code project. Links to the code and a detailed tutorial on how to extend Flutter Theme Agent are in the description. If you get some new functionality working, let us know in the comments. Also, if you're interested in diving deeper into building developer tools for Flutter, Khan has another video on the Flutter channel that covers building Flutter dev tools extensions with Gemini AI. Link below. Thanks for watching. I hope this video helps you build your own AI agent for code generation and helps you and other developers be more creative, productive, and collaborative with your whole app development team. Keep learning. Keep building. Make something great. We'll see you again soon.

Original Description

Build an AI-powered tool to help you write Flutter code with the Google Gemini API. Introducing the Flutter Theme Agent, a tool that generates user interface ThemeData code for Flutter development. Learn how to extend the Flutter Theme Agent to work with your own workflow, watch a demo of the project, and meet the builders of the system. Resources: Tutorial → https://goo.gle/49eZPHA Code → https://goo.gle/3PBQXoC Check out Google AI Studio → https://goo.gle/GoogleAIStudio Check out the Flutter YouTube channel → https://goo.gle/3VAwsfL Use generated code with caution → https://goo.gle/generative-code Chapters: 0:00 - Demo 3:30 - Overview with the builders 8:12 - Extending the project 10:34 - Wrap up Watch more Build with Google AI → https://goo.gle/BuildwithGoogleAI Subscribe to Google for Developers → https://goo.gle/developers #BuildwithGoogleAI #AI #Google Speaker: Joe Fernandez Products Mentioned: Gemini API, Flutter Use generated code with caution: https://goo.gle/generative-code
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Google for Developers · Google for Developers · 0 of 60

← Previous Next →
1 Developer Journey - Sunnyvale DSC Summit ‘19
Developer Journey - Sunnyvale DSC Summit ‘19
Google for Developers
2 How Google is working with students - Sunnyvale DSC Summit ‘19
How Google is working with students - Sunnyvale DSC Summit ‘19
Google for Developers
3 Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Google for Developers
4 The Solution Challenge  - Sunnyvale DSC Summit ‘19
The Solution Challenge - Sunnyvale DSC Summit ‘19
Google for Developers
5 Firebase - Sunnyvale DSC Summit ‘19
Firebase - Sunnyvale DSC Summit ‘19
Google for Developers
6 Cloud Hero - Sunnyvale DSC Summit ‘19
Cloud Hero - Sunnyvale DSC Summit ‘19
Google for Developers
7 Panel discussion  - Sunnyvale DSC Summit ‘19
Panel discussion - Sunnyvale DSC Summit ‘19
Google for Developers
8 The art of negotiation - Sunnyvale DSC Summit ‘19
The art of negotiation - Sunnyvale DSC Summit ‘19
Google for Developers
9 Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Google for Developers
10 Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Google for Developers
11 [DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
[DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
Google for Developers
12 Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Google for Developers
13 Why Podcast.app chose a .app domain name
Why Podcast.app chose a .app domain name
Google for Developers
14 Machine Learning Bootcamp Jakarta 2019
Machine Learning Bootcamp Jakarta 2019
Google for Developers
15 Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Google for Developers
16 [DEPRECATING]  Importance of community (Assistant on Air)
[DEPRECATING] Importance of community (Assistant on Air)
Google for Developers
17 Why the Flutter team switched from .io to a .dev domain name
Why the Flutter team switched from .io to a .dev domain name
Google for Developers
18 3 website-building tips from .dev creators
3 website-building tips from .dev creators
Google for Developers
19 Why NimbleDroid chose a .app domain name
Why NimbleDroid chose a .app domain name
Google for Developers
20 Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Google for Developers
21 Google for Games Developer Summit: A free, digital experience for game developers
Google for Games Developer Summit: A free, digital experience for game developers
Google for Developers
22 Inspecting Home Graph (Assistant for Developers Pro Tips)
Inspecting Home Graph (Assistant for Developers Pro Tips)
Google for Developers
23 Google for Games Developer Summit Keynote
Google for Games Developer Summit Keynote
Google for Developers
24 Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Google for Developers
25 Empowering game developers with Stadia R&D (Google Games Dev Summit)
Empowering game developers with Stadia R&D (Google Games Dev Summit)
Google for Developers
26 Supercharging discoverability with Stadia (Google Games Dev Summit)
Supercharging discoverability with Stadia (Google Games Dev Summit)
Google for Developers
27 Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Google for Developers
28 Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Google for Developers
29 Live Captioning in Google Slides
Live Captioning in Google Slides
Google for Developers
30 [DEPRECATING]  User engagement for the Google Assistant
[DEPRECATING] User engagement for the Google Assistant
Google for Developers
31 TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
Google for Developers
32 Top 5 from the TensorFlow Dev Summit 2020
Top 5 from the TensorFlow Dev Summit 2020
Google for Developers
33 Developer Student Clubs 2019 Turkey Leads Summit
Developer Student Clubs 2019 Turkey Leads Summit
Google for Developers
34 Building simpler payment experiences | Google Pay Plugin for Magento 2
Building simpler payment experiences | Google Pay Plugin for Magento 2
Google for Developers
35 Become A Developer Student Club Lead
Become A Developer Student Club Lead
Google for Developers
36 Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Google for Developers
37 Test suite for Smart Home (Assistant for Developers Pro Tips)
Test suite for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
38 Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google for Developers
39 How to use error logs (Assistant for Developers Pro Tips)
How to use error logs (Assistant for Developers Pro Tips)
Google for Developers
40 Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Google for Developers
41 WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
Google for Developers
42 Offline handling for Smart Home (Assistant for Developers Pro Tips)
Offline handling for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
43 Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Google for Developers
44 Machine Learning Foundations: Ep #1 - What is ML?
Machine Learning Foundations: Ep #1 - What is ML?
Google for Developers
45 Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Google for Developers
46 Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Google for Developers
47 Machine Learning Foundations: Ep #3 - Convolutions and pooling
Machine Learning Foundations: Ep #3 - Convolutions and pooling
Google for Developers
48 Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Google for Developers
49 Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Google for Developers
50 Google Developers ML Summit
Google Developers ML Summit
Google for Developers
51 Real-world image classification using convolutional neural networks | Machine Learning Foundations
Real-world image classification using convolutional neural networks | Machine Learning Foundations
Google for Developers
52 Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Google for Developers
53 Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Google for Developers
54 Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Google for Developers
55 Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Google for Developers
56 Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Google for Developers
57 Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Google for Developers
58 Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Google for Developers
59 Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Google for Developers
60 AR Realism with the ARCore Depth API
AR Realism with the ARCore Depth API
Google for Developers

Related Reads

Chapters (4)

Demo
3:30 Overview with the builders
8:12 Extending the project
10:34 Wrap up
Up next
Exploring NotebookLM in Unexpected Ways 🤯 | Hidden AI Use Cases You Should Try
Pavithra’s Podcast
Watch →