<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amala P.P. on Medium]]></title>
        <description><![CDATA[Stories by Amala P.P. on Medium]]></description>
        <link>https://medium.com/@amalappaulson?source=rss-80a2ca946ed8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2fWSFMyoYKlMKyKslB4Srg.jpeg</url>
            <title>Stories by Amala P.P. on Medium</title>
            <link>https://medium.com/@amalappaulson?source=rss-80a2ca946ed8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:09:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amalappaulson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Implementing Dynamic Island in Flutter with Native Code]]></title>
            <link>https://medium.com/@amalappaulson/implementing-dynamic-island-in-flutter-with-native-code-ae25ea9090f1?source=rss-80a2ca946ed8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae25ea9090f1</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dynamic-island]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Amala P.P.]]></dc:creator>
            <pubDate>Tue, 13 Aug 2024 08:10:16 GMT</pubDate>
            <atom:updated>2024-08-13T08:10:16.333Z</atom:updated>
            <content:encoded><![CDATA[<p>With the release of the iPhone 14 Pro models, Apple introduced the “Dynamic Island” — a novel approach to blending hardware and software for interactive notifications and activities. This pill-shaped cutout dynamically adapts to display relevant information, enhancing user engagement.</p><p>Flutter, known for its cross-platform capabilities, allows developers to build applications for both iOS and Android from a single codebase. However, certain platform-specific features, like the Dynamic Island, require a deep dive into native code integration.</p><p>In this article, we’ll explore how to implement a Dynamic Island-like feature in Flutter by integrating native iOS code. We’ll delve into the architecture, required tools, and step-by-step guidance to achieve this functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvCDyiman6-JXTl1mFoqGw.jpeg" /></figure><h3>Understanding Dynamic Island</h3><p>Before diving into the implementation, it’s crucial to understand what the Dynamic Island is and how it functions.</p><p>Dynamic Island is an interactive area at the top of the iPhone 14 Pro’s display. It expands, contracts, and shows different animations based on system alerts or user interactions. For instance, when you receive a call, the island expands to display the caller’s information. Similarly, playing music, using Face ID, or connecting AirPods trigger specific animations and displays.</p><p>Implementing such dynamic behaviors requires leveraging the latest iOS APIs, particularly those introduced in iOS 16.1, like the <a href="https://developer.apple.com/documentation/activitykit">Live Activities</a> framework.</p><h4>Prerequisites</h4><p>To follow along with this tutorial, ensure you have the following:</p><ul><li><strong>Flutter SDK</strong>: Installed and configured. Download Flutter</li><li><strong>Xcode</strong>: Version 14.1 or later. <a href="https://developer.apple.com/xcode/">Download Xcode</a></li><li><strong>macOS</strong>: Since we’re dealing with iOS native code, macOS is required.</li><li><strong>Basic Knowledge</strong>: Familiarity with Flutter, Dart, Swift, and iOS development.</li></ul><h4>Creating the Native iOS Component</h4><p>To implement Dynamic Island functionalities, we’ll utilize the <a href="https://developer.apple.com/documentation/activitykit">ActivityKit</a> framework, which enables Live Activities.</p><ol><li><strong>Enable the Required Capabilities</strong></li></ol><p>In Xcode:</p><ul><li>Select the <strong>Runner</strong> project.</li><li>Navigate to the <strong>Signing &amp; Capabilities</strong> tab.</li><li>Click on <strong>+ Capability</strong>.</li><li>Add <strong>Background Modes</strong> and select <strong>Remote notifications</strong>.</li><li>Add <strong>Push Notifications</strong></li></ul><p><strong>2. Create a Swift File for Live Activities</strong></p><p>In the <strong>Runner</strong> target:</p><ul><li>Right-click on the <strong>Runner</strong> folder.</li><li>Select <strong>New File</strong> &gt; <strong>Swift File</strong>.</li><li>Name it LiveActivitiesManager.swift.</li></ul><p><strong>3. Implementing LiveActivitiesManager</strong></p><p>Here’s a basic implementation to manage Live Activities:</p><pre> import Foundation<br>import ActivityKit<br>import UIKit<br><br>@available(iOS 16.1, *)<br>struct MusicAttributes: ActivityAttributes {<br>    public struct ContentState: Codable, Hashable {<br>        var songName: String<br>        var artistName: String<br>    }<br><br>    var albumName: String<br>}<br><br>@available(iOS 16.1, *)<br>class LiveActivitiesManager {<br>    static let shared = LiveActivitiesManager()<br>    var activity: Activity&lt;MusicAttributes&gt;?<br><br>    func startMusicActivity(songName: String, artistName: String, albumName: String) {<br>        let attributes = MusicAttributes(albumName: albumName)<br>        let initialContentState = MusicAttributes.ContentState(songName: songName, artistName: artistName)<br>        let activityContent = ActivityContent(state: initialContentState, staleDate: nil)<br><br>        do {<br>            activity = try Activity&lt;MusicAttributes&gt;.request(attributes: attributes, content: activityContent)<br>            print(&quot;Started Live Activity with ID: \(activity?.id ?? &quot;N/A&quot;)&quot;)<br>        } catch {<br>            print(&quot;Error starting Live Activity: \(error.localizedDescription)&quot;)<br>        }<br>    }<br><br>    func updateMusicActivity(songName: String, artistName: String) {<br>        Task {<br>            let updatedContentState = MusicAttributes.ContentState(songName: songName, artistName: artistName)<br>            let activityContent = ActivityContent(state: updatedContentState, staleDate: nil)<br><br>            await activity?.update(activityContent)<br>            print(&quot;Updated Live Activity&quot;)<br>        }<br>    }<br><br>    func endMusicActivity() {<br>        Task {<br>            await activity?.end(dismissalPolicy: .immediate)<br>            print(&quot;Ended Live Activity&quot;)<br>        }<br>    }<br>}</pre><p><strong>Explanation:</strong></p><ul><li><strong>MusicAttributes</strong>: Defines the structure of the Live Activity, including its dynamic content.</li><li><strong>LiveActivitiesManager</strong>: Manages starting, updating, and ending the Live Activity.</li></ul><p>4. <strong>Handling iOS Version Compatibility</strong></p><p>Since ActivityKit is available from iOS 16.1 onwards, ensure that you handle compatibility:</p><pre>import Flutter<br><br>class AppDelegate: FlutterAppDelegate {<br>    override func application(<br>        _ application: UIApplication,<br>        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?<br>    ) -&gt; Bool {<br>        if #available(iOS 16.1, *) {<br>            // Initialize LiveActivitiesManager or other setup<br>        } else {<br>            // Handle devices with iOS versions below 16.1<br>            print(&quot;Live Activities not supported on this iOS version.&quot;)<br>        }<br>        return super.application(application, didFinishLaunchingWithOptions: launchOptions)<br>    }<br>}</pre><h4>Integrating Native Code with Flutter</h4><p>To communicate between Flutter and the native iOS code, we’ll use Method Channels.</p><ol><li><strong>Setting Up the Method Channel in iOS</strong></li></ol><p>In AppDelegate.swift, add the following:</p><pre>import Flutter<br>import UIKit<br><br>@UIApplicationMain<br>@objc class AppDelegate: FlutterAppDelegate {<br>    override func application(<br>        _ application: UIApplication,<br>        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?<br>    ) -&gt; Bool {<br>        let controller = window?.rootViewController as! FlutterViewController<br>        let liveActivitiesChannel = FlutterMethodChannel(name: &quot;com.example.dynamic_island/live_activities&quot;,<br>                                                         binaryMessenger: controller.binaryMessenger)<br><br>        if #available(iOS 16.1, *) {<br>            liveActivitiesChannel.setMethodCallHandler { [weak self] (call, result) in<br>                guard let self = self else { return }<br>                switch call.method {<br>                case &quot;startMusicActivity&quot;:<br>                    if let args = call.arguments as? [String: String],<br>                       let songName = args[&quot;songName&quot;],<br>                       let artistName = args[&quot;artistName&quot;],<br>                       let albumName = args[&quot;albumName&quot;] {<br>                        LiveActivitiesManager.shared.startMusicActivity(songName: songName, artistName: artistName, albumName: albumName)<br>                        result(&quot;Started&quot;)<br>                    } else {<br>                        result(FlutterError(code: &quot;INVALID_ARGUMENTS&quot;, message: &quot;Missing arguments&quot;, details: nil))<br>                    }<br>                case &quot;updateMusicActivity&quot;:<br>                    if let args = call.arguments as? [String: String],<br>                       let songName = args[&quot;songName&quot;],<br>                       let artistName = args[&quot;artistName&quot;] {<br>                        LiveActivitiesManager.shared.updateMusicActivity(songName: songName, artistName: artistName)<br>                        result(&quot;Updated&quot;)<br>                    } else {<br>                        result(FlutterError(code: &quot;INVALID_ARGUMENTS&quot;, message: &quot;Missing arguments&quot;, details: nil))<br>                    }<br>                case &quot;endMusicActivity&quot;:<br>                    LiveActivitiesManager.shared.endMusicActivity()<br>                    result(&quot;Ended&quot;)<br>                default:<br>                    result(FlutterMethodNotImplemented)<br>                }<br>            }<br>        } else {<br>            print(&quot;Live Activities not supported on this iOS version.&quot;)<br>        }<br><br>        GeneratedPluginRegistrant.register(with: self)<br>        return super.application(application, didFinishLaunchingWithOptions: launchOptions)<br>    }<br>}</pre><p><strong>Explanation:</strong></p><ul><li><strong>liveActivitiesChannel</strong>: A method channel named com.example.dynamic_island/live_activities.</li><li><strong>Method Handlers</strong>: For startMusicActivity, updateMusicActivity, and endMusicActivity.</li><li><strong>Argument Extraction</strong>: Retrieves parameters from Flutter to pass to the native functions.</li></ul><p>2. <strong>Setting Up the Method Channel in Flutter</strong></p><p>In Flutter, we’ll create a service to communicate with the native code.</p><ul><li><strong>Create a New Dart File : </strong>Create lib/live_activities_service.dart with the following content:</li></ul><pre>import &#39;package:flutter/services.dart&#39;;<br><br>class LiveActivitiesService {<br>  static const _channel = MethodChannel(&#39;com.example.dynamic_island/live_activities&#39;);<br><br>  static Future&lt;void&gt; startMusicActivity({<br>    required String songName,<br>    required String artistName,<br>    required String albumName,<br>  }) async {<br>    try {<br>      await _channel.invokeMethod(&#39;startMusicActivity&#39;, {<br>        &#39;songName&#39;: songName,<br>        &#39;artistName&#39;: artistName,<br>        &#39;albumName&#39;: albumName,<br>      });<br>    } on PlatformException catch (e) {<br>      print(&#39;Failed to start Live Activity: ${e.message}&#39;);<br>    }<br>  }<br><br>  static Future&lt;void&gt; updateMusicActivity({<br>    required String songName,<br>    required String artistName,<br>  }) async {<br>    try {<br>      await _channel.invokeMethod(&#39;updateMusicActivity&#39;, {<br>        &#39;songName&#39;: songName,<br>        &#39;artistName&#39;: artistName,<br>      });<br>    } on PlatformException catch (e) {<br>      print(&#39;Failed to update Live Activity: ${e.message}&#39;);<br>    }<br>  }<br><br>  static Future&lt;void&gt; endMusicActivity() async {<br>    try {<br>      await _channel.invokeMethod(&#39;endMusicActivity&#39;);<br>    } on PlatformException catch (e) {<br>      print(&#39;Failed to end Live Activity: ${e.message}&#39;);<br>    }<br>  }<br>}</pre><h4>Triggering Dynamic Island from Flutter</h4><p>With the method channel set up, we can now create a simple UI in Flutter to start, update, and end the Live Activity.</p><ol><li><strong>Update </strong><strong>lib/main.dart : </strong>Replace its content with:</li></ol><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;live_activities_service.dart&#39;;<br><br>void main() {<br>  runApp(MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Dynamic Island Demo&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      home: HomePage(),<br>    );<br>  }<br>}<br><br>class HomePage extends StatefulWidget {<br>  @override<br>  _HomePageState createState() =&gt; _HomePageState();<br>}<br><br>class _HomePageState extends State&lt;HomePage&gt; {<br>  final TextEditingController _songController = TextEditingController();<br>  final TextEditingController _artistController = TextEditingController();<br>  final TextEditingController _albumController = TextEditingController();<br><br>  @override<br>  void dispose() {<br>    _songController.dispose();<br>    _artistController.dispose();<br>    _albumController.dispose();<br>    super.dispose();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Dynamic Island Demo&#39;),<br>      ),<br>      body: Padding(<br>        padding: const EdgeInsets.all(16.0),<br>        child: Column(<br>          children: [<br>            TextField(<br>              controller: _songController,<br>              decoration: InputDecoration(labelText: &#39;Song Name&#39;),<br>            ),<br>            TextField(<br>              controller: _artistController,<br>              decoration: InputDecoration(labelText: &#39;Artist Name&#39;),<br>            ),<br>            TextField(<br>              controller: _albumController,<br>              decoration: InputDecoration(labelText: &#39;Album Name&#39;),<br>            ),<br>            SizedBox(height: 20),<br>            Row(<br>              mainAxisAlignment: MainAxisAlignment.spaceEvenly,<br>              children: [<br>                ElevatedButton(<br>                  onPressed: () {<br>                    LiveActivitiesService.startMusicActivity(<br>                      songName: _songController.text,<br>                      artistName: _artistController.text,<br>                      albumName: _albumController.text,<br>                    );<br>                  },<br>                  child: Text(&#39;Start&#39;),<br>                ),<br>                ElevatedButton(<br>                  onPressed: () {<br>                    LiveActivitiesService.updateMusicActivity(<br>                      songName: _songController.text,<br>                      artistName: _artistController.text,<br>                    );<br>                  },<br>                  child: Text(&#39;Update&#39;),<br>                ),<br>                ElevatedButton(<br>                  onPressed: () {<br>                    LiveActivitiesService.endMusicActivity();<br>                  },<br>                  child: Text(&#39;End&#39;),<br>                ),<br>              ],<br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Integrating platform-specific features like the Dynamic Island into Flutter applications enhances user experience on targeted devices. Through method channels, Flutter allows seamless communication with native code, enabling the use of cutting-edge platform functionalities.</p><p>While the above implementation provides a foundational approach, developers can expand upon it by adding richer animations, handling more activity types, and ensuring comprehensive error handling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae25ea9090f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Gemini AI and Speech to text Integration using Bloc in Flutter]]></title>
            <link>https://medium.com/@amalappaulson/google-gemini-ai-and-speech-to-text-integration-using-bloc-in-flutter-1b3778acd387?source=rss-80a2ca946ed8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b3778acd387</guid>
            <dc:creator><![CDATA[Amala P.P.]]></dc:creator>
            <pubDate>Tue, 11 Jun 2024 06:54:45 GMT</pubDate>
            <atom:updated>2024-06-11T06:54:45.652Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Flutter devs, level up your game! Build apps with natural conversations, creative text formats, and complex query understanding. It’s all thanks to Google Gemini AI. </strong>Gemini AI seamlessly plugs into your Flutter projects, unlocking a universe of conversational UIs, creative content generation, and deep user understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPfMzEperRU-7JigsipzPA.jpeg" /></figure><ol><li><strong>Chat Naturally — Feels like talking to a friend!</strong></li></ol><p>Imagine chatbots or virtual assistants in your app that can have back-and-forth conversations that are smooth and natural.</p><p><strong>2. Get Creative: Write Unique Content in Different Formats</strong></p><p>Unleash your app’s creative potential by using Gemini AI to generate different kinds of text content:</p><ul><li>Poems, code snippets, scripts, musical pieces</li><li>Emails, letters, product descriptions, social media post.</li></ul><p><strong>3. Understand Users Better: Responds to Complex Questions</strong></p><ul><li>Gemini AI goes beyond simple keyword matching. It can analyze the intent and context behind user queries.</li></ul><p>By incorporating these functionalities, Gemini AI can make your Flutter apps more engaging, informative, and user-friendly.</p><p>Let’s dive into building a Flutter app powered by the magic of Gemini AI. Here’s a breakdown with a bit more personality:</p><h4><strong>Essential prerequisites:</strong></h4><p><strong>1.Flutter project set up:</strong> This provides the foundation for building your mobile app using the Flutter framework.</p><p><strong>2.Active Google account:</strong> You’ll need a Google account to access Google AI Studio, where you’ll obtain the API key for Gemini AI.</p><h4><strong>Google AI Studio project linked to your account:</strong></h4><p>A Google AI Studio project acts as a workspace for managing your AI projects and resources. Linking it to your account allows you to create and access the API key for Gemini AI within that project.</p><h4><strong>I. Snag a Secret Key:</strong></h4><p>First things first, we need a special key to unlock Gemini AI’s superpowers. Think of it like a VIP pass for your app to chat with Gemini.</p><ol><li><strong>Head to Google AI Studio:</strong> Visit https://cloud.google.com/generative-ai-studio in your web browser.</li><li><strong>Sign in with your Google Account:</strong> Make sure you’re signed in to the Google account you want to associate with your Gemini AI project.</li><li><strong>Get API Key (Optional):</strong> You might see a prompt to “Get API Key in Google AI Studio.” If so, click on that button.</li><li><strong>Access API Keys:</strong> In the left-hand sidebar menu, navigate to the section labeled “Get API Key” or “API Keys” (depending on the version of AI Studio you’re using).</li><li><strong>Create a New Key (if needed):</strong> If you don’t already have an API key, click on the “Create API Key” button.</li><li><strong>Follow on-screen instructions:</strong> Google AI Studio will guide you through the process of creating a new API key. This might involve naming your key and granting it specific permissions.</li><li><strong>Copy Your API Key:</strong> Once the API key is created, be sure to copy it securely. You’ll need it later when you integrate Gemini AI into your Flutter app.</li></ol><p><strong>Important:</strong> Treat your API key with care. It grants access to your Gemini AI project, so avoid sharing it publicly or hardcoding it in your code. Consider using environment variables to store the key securely.</p><h4><strong>II. Install the Flutter package for Gemini AI</strong></h4><ol><li><strong>Open your pubspec.yaml file:</strong> This file is located at the root of your Flutter project. It defines the dependencies your project uses.</li><li><strong>Add the dependency:</strong> Under the dependencies section in your pubspec.yaml file, add the following line:</li></ol><pre>YAML<br>dependencies:<br>  google_generative_ai: ^latest<br>speech_to_text: ^latest</pre><p>The ^latest indicates that you want to use the latest stable version of the package.</p><p>3. <strong>Run flutter pub get</strong></p><p>Now you’ve successfully installed the Flutter package that allows you to integrate Gemini AI into your app!</p><p>4. <strong>Added Permissions.</strong></p><p>Add necessary permission in <em>Info.plist</em> file, and <em>AndroidManifest.xml</em> file</p><h4><strong>III. Import and Initialise Gemini and speech to text in BloC</strong></h4><ol><li><strong>Import the required packages in the bloc.</strong></li></ol><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:google_generative_ai/google_generative_ai.dart&#39;;<br>import &#39;package:speech_to_text/speech_recognition_result.dart&#39;;</pre><p>2. <strong>In the bloc logic first create instance for GenerativeModel with your API key and Speechtotext</strong></p><pre>//Gemini ai<br>  late final ChatSession _chat = GenerativeModel(<br>          model: &#39;gemini-pro&#39;,<br>          apiKey: _apiKey)<br>      .startChat();<br> // speech  to text<br>  SpeechToText _speechToText = SpeechToText();<br>  bool _speechEnabled = false;</pre><h4><strong>IV. The BLoC manages sending messages to Gemini AI and handling the streamed response for chat interactions.</strong></h4><ol><li>An event gets fired up, letting the BLoC know the user has a question for Gemini AI.</li></ol><pre>const factory HomeScreenEvent.addHistory({<br>    required String text,<br>  }) = _AddHistoryET;</pre><p>2. In the bloc logic it manages user input, sends it to Gemini AI for processing, and updates the UI with the response while handling potential errors.</p><p>i. The query you asked will be sent to the bloc and saved in the list to be displayed in the chat.</p><pre>var updated = state.history.toList();<br>updated.add(Content(&#39;user&#39;, [TextPart(event.text)]));   // Add  user message to list<br>emit(state.copyWith(history: updated,textfieldString: &#39;&#39;)); // emit updated list to show in the chat</pre><p>ii. Sending the message to Gemini AI in stream</p><pre>var response = _chat.sendMessageStream(Content.text(event.text),);</pre><p>iii. Response from Gemini:</p><p>Gemini AI doesn’t send the entire response at once. Instead, it sends it as a “stream” of information. This means the response is broken down into smaller parts, and each part is sent one after another. To make sense of the response, the code uses a list called “Parts.” This list acts like a container where each individual part of the response (text, code, etc.) is collected as it arrives from Gemini AI.Once all the parts are received in the list, the code can then assemble them to form the complete response from Gemini AI.</p><pre>await for (var item in response) {<br>          log(‘ response  ${item.text}&#39;);<br>          var text = item.text;   <br>          if (text == null) {<br>            emit(state.copyWith(isError: true,));// if the response from the Ai is empty then an error state  will triggered.<br>            return;<br>          } else {<br>            parts.add(TextPart(text)); //  each item in the response added to the Parts list.<br>          }<br>        }<br>        updated.insert(<br>          state.history.length,<br>          Content(<br>            &#39;model&#39;,<br>            parts,<br>          ),<br>        ); // here the response added in the history list which shows in the  chat UI</pre><h4><strong>V. Speech to text Conversion in the Bloc.</strong></h4><p>i. Handles speech recognition initialization within a BLoC and updates the UI accordingly</p><pre> on&lt;_InitSpeechET&gt;((event, emit) async {<br>      _speechEnabled = await _speechToText.initialize(); // initialising  speech to text<br>      emit(state.copyWith(speechEnabled: _speechEnabled));<br>    });</pre><p>ii. Start a speech recognition session and convert it in to text.</p><pre>await _speechToText.listen(<br>        pauseFor: const Duration(seconds: 2), // The speech recognition automatically stops listening after 2 seconds of silence from the user.<br>        onResult: (result) =&gt;<br>            _onSpeechResult(result, emit, event.historyLength), // This is the callback that the SpeechToText plugin calls when the platform returns recognized words.<br>      );</pre><p>iii. This is the callback that the SpeechToText plugin calls where the platform returns recognized words.</p><pre>if (_speechToText.isListening) {<br>      lastWords = result.recognizedWords; //If listening is active assign he recognized words<br>      write(&#39;while listening : $lastWords&#39;);<br>      add(HomeScreenEvent.updateTextFeild(updatedText: lastWords));<br>    }<br>    if (result.finalResult) {<br>      write(&#39;when finalResult is ${result.finalResult}&#39;);<br>      add(HomeScreenEvent.addHistory(// once final result become true then it  trigger the event for Gemini<br>          text: result.recognizedWords, historyLength: historyLength));<br>    }</pre><p>VI. Supply this data in ListView UI</p><p>With the history list containing all the user’s messages and Gemini AI’s responses, we can now populate the chat window to display the entire conversation for the user.</p><pre>ListView.separated(<br>                padding: const EdgeInsets.fromLTRB(15, 0, 15, 90),<br>                controller: _scrollController,<br>                reverse: true,<br>                itemBuilder: (context, index) {<br>                  var content = history.reversed.toList()[index];<br>                  var text = content.parts<br>                      .whereType&lt;TextPart&gt;()<br>                      .map&lt;String&gt;((e) =&gt; e.text)<br>                      .join(&#39;&#39;);<br>                  write(&#39;inside listview : $text&#39;);<br>                  write(&#39;content role inside lisview : ${content.role}&#39;);<br>                  return MessageTile(<br>                      sendByMe: content.role == &#39;user&#39;, message: text);<br>                },<br>                separatorBuilder: (context, index) {<br>                  return const SizedBox(<br>                    height: 15,<br>                  );<br>                },<br>                itemCount: history.length),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*E0pt9s4ehF5xoOnDpi7kdA.gif" /></figure><p>Converting speech to text and send to gemini AI to get response..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b3778acd387" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>