gemini_widgets 0.0.2 copy "gemini_widgets: ^0.0.2" to clipboard
gemini_widgets: ^0.0.2 copied to clipboard

A unique Flutter package that provides declarative AI widgets. Easily generate text and images using Google's Gemini API with minimal boilerplate.

Gemini Widgets #

pub package License: MIT

A unique Flutter package that provides declarative AI widgets. Harness the power of Google's Gemini AI with easy-to-use Flutter widgets that handle loading, errors, and success states for you.

Why Gemini Widgets? #

Traditional AI integration in Flutter requires manual state management, handling FutureBuilders or StreamBuilders, and writing boilerplate code for API calls. gemini_widgets abstracts all of that away.

  • Declarative & Simple: Just add a widget to your tree.
  • State-Managed: Automatically handles loading, error, and success UI through builders.
  • Minimal Code: Go from prompt to UI in just a few lines.
  • Flexible: Customize the UI for each state (loading, error, success) with builder functions.

Features #

  • GenerativeText: Generate text from a prompt.
  • GenerativeImage: Generate an image from a prompt.
  • VisionText: Generate text by analyzing an image and a prompt.

Getting Started #

1. Installation #

Add this to your package's pubspec.yaml file:

yaml dependencies: gemini_widgets: ^0.0.1 # Replace with the latest version

Then, install it by running:

sh flutter pub get

2. Initialization #

Before using any widgets, you must initialize the package with your Google AI API key. You can get a key from Google AI Studio.

It's best to do this in your main.dart file before unApp.

`dart import 'package:flutter/material.dart'; import 'package:gemini_widgets/gemini_widgets.dart';

void main() async { // IMPORTANT: You must initialize the package with your API key. GeminiWidgets.initialize(apiKey: 'YOUR_GEMINI_API_KEY');

runApp(const MyApp()); } `

Usage #

GenerativeText #

Display text generated from a prompt.

`dart import 'package:flutter/material.dart'; import 'package:gemini_widgets/gemini_widgets.dart';

class MyTextGenerator extends StatelessWidget { const MyTextGenerator({super.key});

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Text Generation')), body: Padding( padding: const EdgeInsets.all(16.0), child: GenerativeText( prompt: "Write a short, fun poem about Flutter.", loadingBuilder: (context) => const Center(child: CircularProgressIndicator()), successBuilder: (context, text) => Text(text ?? "No result"), errorBuilder: (context, error) => Text("An error occurred: An item with the specified name E:\Projects\package\gemini_widgets\lib\src\widgets already exists. An item with the specified name E:\Projects\package\gemini_widgets\lib\src already exists. An item with the specified name E:\Projects\package\gemini_widgets\lib already exists. An item with the specified name E:\Projects\package\gemini_widgets already exists. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'."), ), ), ); } } `

GenerativeImage #

Display an image generated from a prompt.

`dart import 'package:flutter/material.dart'; import 'package:gemini_widgets/gemini_widgets.dart';

class MyImageGenerator extends StatelessWidget { const MyImageGenerator({super.key});

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Image Generation')), body: Center( child: GenerativeImage( prompt: "A futuristic, sleek Flutter logo, neon blue on a dark background.", loadingBuilder: (context) => const CircularProgressIndicator(), successBuilder: (context, image) => image, errorBuilder: (context, error) => Text("Error: An item with the specified name E:\Projects\package\gemini_widgets\lib\src\widgets already exists. An item with the specified name E:\Projects\package\gemini_widgets\lib\src already exists. An item with the specified name E:\Projects\package\gemini_widgets\lib already exists. An item with the specified name E:\Projects\package\gemini_widgets already exists. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'."), ), ), ); } } `

VisionText #

Generate text based on an image and a prompt.

`dart import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:gemini_widgets/gemini_widgets.dart';

class MyVisionAnalyzer extends StatefulWidget { const MyVisionAnalyzer({super.key});

@override State

class _MyVisionAnalyzerState extends State

@override void initState() { super.initState(); _loadImage(); }

Future

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Image Analysis')), body: SingleChildScrollView( padding: const EdgeInsets.all(16.0), child: Column( children: [ if (_imageData != null) ...[ Image.memory(_imageData!), const SizedBox(height: 20), VisionText( prompt: "Describe what is in this image in a single sentence.", imageBytes: _imageData!, loadingBuilder: (context) => const CircularProgressIndicator(), successBuilder: (context, text) => Text(text ?? "No description."), errorBuilder: (context, error) => Text("Error: An item with the specified name E:\Projects\package\gemini_widgets\lib\src\widgets already exists. An item with the specified name E:\Projects\package\gemini_widgets\lib\src already exists. An item with the specified name E:\Projects\package\gemini_widgets\lib already exists. An item with the specified name E:\Projects\package\gemini_widgets already exists. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'. A parameter cannot be found that matches parameter name 'Chord'."), ), ] else const Center(child: CircularProgressIndicator()), ], ), ), ); } } `

Important Notes #

  • API Key Security: Never expose your API key in public repositories. It's recommended to load it from a secure location or environment variables.
  • API Costs: Be aware that using the Gemini API may incur costs based on your usage.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

1
likes
0
points
175
downloads

Publisher

unverified uploader

Weekly Downloads

A unique Flutter package that provides declarative AI widgets. Easily generate text and images using Google's Gemini API with minimal boilerplate.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http

More

Packages that depend on gemini_widgets