// Define tool input schema @Schema() abstractclass $WeatherRequest{ @Field(description: 'The city name') Stringget city; }
void main() async { // Initialize Genkit and register the Google AI plugin final ai = Genkit(plugins: [googleAI()]);
// Define a tool the model can invoke to fetch live data ai.defineTool( name: 'fetchWeather', description: 'Retrieves the current weather forecast for a given city', inputSchema: WeatherRequest.$schema, fn: (request, _) async => request.city.toLowerCase() == 'seattle' ? 'Rainy' : 'Sunny', );
// Construct a strongly-typed, observable flow final tripPlannerFlow = ai.defineFlow( name: 'planTrip', inputSchema: TripRequest.$schema, outputSchema: .string(), fn: (request, _) async { // Generate content using the model and tool final response = await ai.generate( model: googleAI.gemini('gemini-3.1-pro-preview'), prompt: 'Build a ${request.days}-day travel itinerary for ${request.destination}. ' 'Make sure to check the weather forecast first to suggest appropriate activities.', toolNames: ['fetchWeather'], ); return response.text; }, );
// Run the flow final itinerary = await tripPlannerFlow( TripRequest(destination: 'Seattle', days: 3) ); print(itinerary); }
// Backend securely proxies requests to the model void main() async { final geminiApi = googleAI(); final targetModel = geminiApi.model('gemini-3.1-flash-lite-preview'); final router = Router() ..post( '/api/gemini-model', shelfHandler( targetModel, // Insert custom authorization logic here contextProvider: (req) async => {'customAuth': true}, ), ); await io.serve(router.call, 'localhost', 8080); }
在您的 Flutter 應用程式中,使用遠端模型而不是直接模型外掛程式,傳遞伺服器所需的任何標頭。這可以避免公開您的 API 金鑰,並讓您對請求授權有更多控制權。
1 2 3 4 5 6 7 8 9 10
import'package:genkit/genkit.dart';
// Flutter app communicates with the proxy server final ai = Genkit(); final secureModel = ai.defineRemoteModel( name: 'secureModel', url: 'https://api.yourdomain.com/api/gemini-model', headers: (context) => {'Authorization': 'Bearer ${fetchSessionToken()}'}, ); final response = await ai.generate(model: secureModel, prompt: 'Write me a poem.');
強大的 AI 開發工具
構建高品質的 AI 應用程式需要徹底的測試和持續迭代才能獲得可靠的結果。為此,Genkit 提供了強大的本機開發人員 UI。
您可以透過使用 Genkit CLI 運行您的應用程式來啟動開發人員 UI:
1
genkit start -- dart run bin/server.dart
以下是開發人員 UI 中測試更進階版本的旅遊規劃器流程:
顯示正在運行流程的 Genkit 開發人員 UI
AI 編程輔助
為了在使用 Genkit Dart 搭配 Antigravity、Gemini CLI 或 Claude Code 等 AI 編碼工具時獲得最佳體驗,請安裝 Genkit Dart agent skill。這將使您的 AI 助理具備準確編寫和偵錯 AI 功能的知識。
我們很高興地宣布,Dart 專案將在 Google Summer of Code 2026 中第七次指導貢獻者!
Google Summer of Code (GSoC) 計劃的重點是將來自世界各地的學生開發人員帶入開源軟體開發。Google 贊助學生在夏季與指導性開源組織合作進行為期 12 週(或更長時間)的程式設計專案。在過去的 21 年中,超過 22,000 名貢獻者參與了 Google Summer of Code。
開始建構! (Antigravity) - Google 新的 AI 賦能 IDE 是一個主力。相比之下,如果您要求任何流行的 LLM(Gemini、ChatGPT 等)「寫一本書」,它們只能輸出那麼多。當您向 Antigravity 提出這樣一個複雜的任務時,它首先會制定一個計畫,然後循序漸進地執行該計畫中的每個任務。您一路引導它。我將所有黃金提示放入 Antigravity,並引導它將它們建構到應用程式中。
當您深入了解我們今年的計劃時,請記住,這份發展藍圖——一如既往——是我們對未來的抱負策略。與任何其他發展藍圖一樣,計劃在一年中往往會發生變化和調整,因此如果在此過程中發生一些變化,請不要感到驚訝。雖然它主要反映了我們 Google 團隊正在專注的工作,但事實是 Flutterverse 現在比任何一家公司都要大得多。
> dart pub cache gc Found 3 active projects: * /home/yourusername/projects/pub * /home/yourusername/projects/pub-dev * /home/yourusername/projects/pana All other projects will need to run `dart pub get` again to work correctly. Will recover 2 GB. Are you sure you want to continue? (y/N)? y Deleting unused cache entries... (4.5s) >
然而,這些數位感測器的可靠性取決於它們所處的環境。這就是為什麼我們必須將信任建立在 CI 系統中。在真正可重現的工作流程中,CI 是唯一重要的現實版本;它是缺乏人類直覺的代理程式的最終仲裁者。如果變更未能通過自動化閘門,它實際上就不存在。透過將 CI 視為高訊號回饋迴路,我們消除了手動驗證的人為瓶頸,並將其替換為可重現的閘門。這種絕對的真相來源使我們能夠更負責任地擴展——使代理程式能夠快速失敗、迭代,並最終成功,而不會損害專案的完整性或團隊的安心。
我們還宣布了 Flutter AI 工具包 v1.0,現已準備好用於您的生產工作負載。Flutter AI 工具包是一組與 AI 相關的 Widget,可以輕鬆地為您的 Flutter 應用程式添加生成式 AI 功能。自我們上次 Beta 版本發布以來,AI 工具包已遷移到 Firebase AI Logic SDK,並在此過程中添加了新功能,包括用於代理工作流程的多輪函數呼叫、插入自訂語音轉文字翻譯器的能力,以及將 LLM 回應轉化為 Widget 的完整支援。
談到新工具,Google 推出了 Antigravity,這是一種新的 IDE 體驗,旨在透過 AI 提升開發人員工作流程。我們正在與 Google 的各團隊合作,讓 Flutter 開發在 Google AI 可用的所有方面都成為世界一流的體驗。觀看 Observable 直播 以了解更多資訊。
過去幾年,我測試了很多 AI 工具,等待一些真正能節省 Flutter 開發者時間的東西,而不是僅僅轉移時間花費的地方。直到 Google 的新代理 IDE Antigravity 出現,才讓我看到了轉機。它彌合了原始模型能力和實際工程實用性之間的差距。我終於看到所有圍繞 LLM 的基礎設施和工具協同工作,以消除摩擦,而不是增加摩擦。