gemini_flutter 0.1.0+1 copy "gemini_flutter: ^0.1.0+1" to clipboard
gemini_flutter: ^0.1.0+1 copied to clipboard

Discover the ultimate Flutter package for seamless integration with Gemini APIs in your Flutter projects – simplifying API usage like never before!

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:gemini_flutter/gemini_flutter.dart';

import 'image.dart';

void main() {
  GeminiHandler().initialize(apiKey: "API_KEY");
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Gemini Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String textData = "";
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("Gemini Demo"),
      ),
      body: Center(
        child: ListView(
          padding: const EdgeInsets.symmetric(horizontal: 10),
          children: <Widget>[
            const SizedBox(
              height: 20,
            ),
            Column(
              children: [
                ElevatedButton(
                    onPressed: () async {
                      final response = await GeminiHandler()
                          .geminiPro(text: "Write a story about  mustafa");
                      textData = response
                              ?.candidates?.first.content?.parts?.first.text ??
                          "Failed to fetch data";
                      setState(() {});
                    },
                    child: const Text("Gemini Pro")),
                ElevatedButton(
                    onPressed: () async {
                      final response = await GeminiHandler().geminiProVision(
                          countTokens: true,
                          base64Format: imageBase64,
                          text: "I am blind can you describe me the image");
                      textData = response
                              ?.candidates?.first.content?.parts?.first.text ??
                          "Failed to fetch data";
                      setState(() {});
                    },
                    child: const Text("Gemini Pro Vision")),
              ],
            ),
            const SizedBox(
              height: 20,
            ),
            const Text(
              'Press the button to get the response from Gemini',
              textAlign: TextAlign.center,
              style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.blueAccent),
            ),
            const Text(
              'Tokens Used: ',
              textAlign: TextAlign.center,
              style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.blueAccent),
            ),
            const SizedBox(
              height: 20,
            ),
            Text(
              textData,
            ),
          ],
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
13
likes
0
pub points
63%
popularity

Publisher

verified publishertechypanther.com

Discover the ultimate Flutter package for seamless integration with Gemini APIs in your Flutter projects – simplifying API usage like never before!

Homepage

License

unknown (license)

Dependencies

connectivity_plus, dio, flutter, logger

More

Packages that depend on gemini_flutter