<?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 Vishesh Dugar on Medium]]></title>
        <description><![CDATA[Stories by Vishesh Dugar on Medium]]></description>
        <link>https://medium.com/@dugarvishesh?source=rss-b977e7093eba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*w3IUYMoV8Db3Qtq7</url>
            <title>Stories by Vishesh Dugar on Medium</title>
            <link>https://medium.com/@dugarvishesh?source=rss-b977e7093eba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:22:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dugarvishesh/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[Jest Mocking Explained: When to Use .mock, mocked, and spyOn in Your Tests]]></title>
            <link>https://medium.com/@dugarvishesh/jest-mocking-explained-when-to-use-mock-mocked-and-spyon-in-your-tests-8af6371e23e0?source=rss-b977e7093eba------2</link>
            <guid isPermaLink="false">https://medium.com/p/8af6371e23e0</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Vishesh Dugar]]></dc:creator>
            <pubDate>Sun, 08 Jun 2025 10:00:28 GMT</pubDate>
            <atom:updated>2025-06-08T10:00:28.574Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jest Mocking Explained: When to Use .mock, mocked, and spyOn in Your Tests</h3><p>Mocking is one of the most important (and misunderstood) parts of writing tests. If you’ve found yourself googling <strong>“jest.spyOn vs jest.fn vs jest.mocked”</strong>, you’re not alone.</p><p>In this guide, we’ll simplify Jest’s mocking utilities — jest.fn(), .mock, jest.mocked(), and jest.spyOn()—and help you understand when and why to use each.</p><h3>🧪 What Are Mocks in Jest?</h3><p>Mocks are test doubles that simulate real functions or modules so you can:</p><ul><li>Control their behavior</li><li>Observe how they are called</li><li>Avoid hitting real APIs or databases</li><li>Keep your unit tests isolated</li></ul><h3>🔧 jest.fn() and .mock Explained</h3><p><strong>jest.fn()</strong> is used to create a dummy/mock function:</p><pre>const mockCallback = jest.fn();<br>mockCallback(&#39;hello&#39;);<br>expect(mockCallback).toHaveBeenCalledWith(&#39;hello&#39;);</pre><p>Each jest.fn() comes with a .mock property that tracks:</p><ul><li>Call count</li><li>Call arguments</li><li>Return values</li></ul><p>You can also:</p><ul><li>Set a return value: .mockReturnValue(val)</li><li>Replace the logic: .mockImplementation(fn)</li><li>Work with promises: .mockResolvedValue(promiseVal)</li></ul><h3>🧙 TypeScript Helpers: jest.mocked()</h3><p>In TypeScript, mocking modules can break typings. Use jest.mocked() to solve this.</p><pre>import { fetchUser } from &#39;./api&#39;;<br>import { mocked } from &#39;jest-mock&#39;;<br><br>jest.mock(&#39;./api&#39;);<br>const mockedFetchUser = mocked(fetchUser);<br>mockedFetchUser.mockResolvedValue({ id: &#39;abc&#39; });</pre><p>This makes sure your mocks are fully type-safe.</p><h3>🕵️ Spying with jest.spyOn()</h3><p>jest.spyOn() lets you track or override real method calls without replacing the object.</p><pre>const math = {<br>  add(a, b) {<br>    return a + b;<br>  }<br>};<br><br>const spy = jest.spyOn(math, &#39;add&#39;);<br>math.add(2, 3);<br>expect(spy).toHaveBeenCalledWith(2, 3);</pre><p>You can also override the implementation:</p><pre>spy.mockImplementation(() =&gt; 999);</pre><p>Restore it after the test:</p><pre>spy.mockRestore();</pre><h3>📌 When to Use What</h3><p>Scenario:</p><p>Use This Dummy callback for testing: jest.fn()</p><p>Spy on an existing method: jest.spyOn()</p><p>Mock a module in TypeScript: jest.mocked()</p><p>Full module replacement (e.g. axios): jest.mock()</p><h3>🔍 Real-World Example</h3><p>Imagine this module:</p><pre>// userService.ts<br>import { apiClient } from &#39;./apiClient&#39;;<br><br>export function getUser(id: string) {<br>  return apiClient.get(`/users/${id}`);<br>}</pre><p>Test it like this:</p><pre>// userService.test.ts<br>import { getUser } from &#39;./userService&#39;;<br>import { apiClient } from &#39;./apiClient&#39;;<br>import { mocked } from &#39;jest-mock&#39;;<br><br>jest.mock(&#39;./apiClient&#39;);<br>const mockedClient = mocked(apiClient, true);<br>test(&#39;fetches user&#39;, async () =&gt; {<br>  mockedClient.get.mockResolvedValue({ data: { id: &#39;123&#39; } });<br>  const result = await getUser(&#39;123&#39;);<br>  expect(mockedClient.get).toHaveBeenCalledWith(&#39;/users/123&#39;);<br>});</pre><h3>⚠️ Common Mistakes &amp; Best Practices</h3><h3>Mistake: Forgetting to restore spies</h3><pre>jest.spyOn(obj, &#39;method&#39;); // But never restore</pre><p>Fix:</p><pre>const spy = jest.spyOn(obj, &#39;method&#39;);<br>afterEach(() =&gt; spy.mockRestore());</pre><h3>Always clear your mocks</h3><pre>afterEach(() =&gt; {<br>  jest.clearAllMocks();    // Clears call history<br>  jest.resetAllMocks();    // Clears calls + implementation<br>  jest.restoreAllMocks();  // Fully restores original behavior<br>});</pre><h3>❓ FAQ: Jest Mocking</h3><h3>What’s the difference between jest.fn() and jest.spyOn()?</h3><ul><li>jest.fn() creates a new mock function.</li><li>jest.spyOn() wraps and optionally overrides an existing function.</li></ul><h3>When do I use jest.mocked()?</h3><p>Whenever you’re mocking a module in <strong>TypeScript</strong> and want <strong>type safety and IntelliSense</strong>.</p><h3>Can I use jest.spyOn() to mock third-party modules?</h3><p>Not usually — jest.mock() is better for full module mocking. Use spyOn() for specific class or object methods.</p><h3>✅ Quick Decision Checklist</h3><ul><li>Need a mock callback? → jest.fn()</li><li>Spy on a real method? → jest.spyOn()</li><li>TypeScript + mocked import? → jest.mocked()</li><li>Mock full module? → jest.mock()</li></ul><h3>🧾 Summary</h3><p>Here’s your cheat sheet:</p><ul><li><strong>jest.fn()</strong> – Standalone mock function</li><li><strong>.mock</strong> – Tracks metadata</li><li><strong>jest.mocked()</strong> – Type-safe mocking in TypeScript</li><li><strong>jest.spyOn()</strong> – Observe or override existing methods</li></ul><p>Master these four, and you’ll be writing cleaner, more reliable Jest tests in no time. ✅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8af6371e23e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intents and Entities: A Chatbot in Flutter]]></title>
            <link>https://medium.com/@dugarvishesh/intents-and-entities-a-chatbot-in-flutter-bfd6fa3df037?source=rss-b977e7093eba------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfd6fa3df037</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[dialogflow]]></category>
            <category><![CDATA[ngrok]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Vishesh Dugar]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 15:50:56 GMT</pubDate>
            <atom:updated>2022-07-19T15:50:56.015Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cypUGttPjCoT3YeurwX7fg.png" /></figure><p>This article builds up from my previous articles <a href="https://medium.com/@dugarvishesh/make-a-chatbot-in-flutter-with-dialogflow-46b7e26cb70a">Make a Chatbot in Flutter with Dialogflow</a> and <a href="https://medium.com/@dugarvishesh/creating-a-node-js-backend-for-your-flutter-application-296745494785">Creating a Node.js backend for your Flutter App</a>. It is recommended to go through them first.</p><p>Cool, with that over with, Let’s talk about what we are going to do today. As you may have realised, simply training the chatbot on an intent’s user input and giving output is not fun, it doesn’t really give us the freedom to customise the interaction. In short, there is no utility in the basic setup. Well, today we going to use the <strong>Fulfilment </strong>feature to make a Webhook to our backend which allows us to do a whole lot more. So, here is what we are going to do:</p><ul><li>Configure Firebase</li><li>Train our Chatbot to search for <em>Entities </em>in the user input</li><li>Setup the Webhook</li></ul><blockquote>Consider the scenario: the user is looking for new clothes and there are designers making said clothes. The user needs to find the perfect designer for his needs. Our chatbot will query the designer collection and return a match with user input’s keywords.</blockquote><p>Head over to Firebase console and make a new project. Enable Cloud Firestore.</p><p>Now, make a Firestore collection similar to the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJZtXwh8phTY0pr44DqO9w.png" /><figcaption>Designer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ba9e2OMC_4hWfUh7GWe7xw.png" /><figcaption>Not a Designer</figcaption></figure><p>Now in the Firebase console <em>project home</em> page -&gt; Open Project Settings -&gt; Service Account -&gt; Generate private key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cir8GvN_ynfpROVxOsApDA.png" /><figcaption>Firebase Admin SDK</figcaption></figure><p>Store this key somewhere <strong>safe</strong> for now, we’ll need it.</p><p>Now, head over to your Flutter project and add the following dependencies in your pubspec.yaml :</p><pre>dependencies:<br>    bubble: ^1.2.1<br>    dialog_flowtter: ^0.3.3</pre><p>The code for chatbot UI doesn’t change and is <em>as is</em> from my previous article.</p><p>Thats it! We have configured Firebase. Let’s train the chatbot now.</p><p>Head over to <a href="https://dialogflow.cloud.google.com/">Dialogflow</a> (make sure you follow the steps mentioned in my previous article) and make a new agent.</p><blockquote>Before we go any further, What are Entities?<br><strong><em>Entities </em></strong>can be defined as the type of information you want to extract from user input. Dialogflow already has many preconfigured entities but we will be making a custom entity for this article.</blockquote><p>Now head over to <em>Entities</em><strong> </strong>and make an entity called <em>clothes</em>. You can use the below example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXl2xb9xFVC9IVwBOtr4Vw.png" /><figcaption>Entity</figcaption></figure><p>Now, head back to intents and make a <em>clothes_intent. </em>See the example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Huk_uhook5SokFbRBgpH6g.png" /><figcaption>Intents</figcaption></figure><p>You should see the appropriate items highlight on their own. if not, you can manually do so and classify the word as an entity. After this, head over to <em>Fulfilment </em>and enable <strong>Webhook</strong>. We’ll fill the URL here a bit later. Let’s make the Node.js backend now.</p><p>First run this in the root directory of the server:</p><pre>npm init -y<br>npm i body-parser firebase-admin express</pre><p>Now remember the JSON file i told you to keep safe before? We’ll <em>require </em>it now. This is the code snippet for the Webhook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2dc0e7c0dabeca499d66f7661a27cc6/href">https://medium.com/media/c2dc0e7c0dabeca499d66f7661a27cc6/href</a></iframe><p>Here, first we initialise the firebase admin using the service account JSON file we downloaded earlier. Then we make a which takes a tag as input and returns all the Firebase Users which have that particular tag. For this, we query the collection we made earlier.</p><p>Then we use express.js to initialise our server app and define an endpoint for the Webhook. Here, we extract the <em>Entitiy </em>given to us from the Dialogflow request i.e <em>tags.</em> Then we call the function we defined above and send the result as <em>response </em>to the Webhook call.</p><p>For generating a public URL, you can either deploy your backend or use <strong>ngrok</strong> to make a temporary public URL like we did in the previous article. Below is the result of the conversation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*h1UpAL8sGKN2Ax2R7uGncQ.jpeg" /><figcaption>Output</figcaption></figure><blockquote>Some Possible Issues:<br>1. JSON configuration files aren’t available.<br>2. ngrok authentication yaml file isn’t available/visible in the system</blockquote><p>Another reminder of the fact that this article builds up from my previous articles <a href="https://medium.com/@dugarvishesh/make-a-chatbot-in-flutter-with-dialogflow-46b7e26cb70a">Make a Chatbot in Flutter with Dialogflow</a> and <a href="https://medium.com/@dugarvishesh/creating-a-node-js-backend-for-your-flutter-application-296745494785">Creating a Node.js backend for your Flutter App</a>. It is recommended to go through them first.</p><blockquote>This article is based on one of my recent Hackathon submissions: Go to this <a href="https://devpost.com/software/code-glamour">Devpost page</a> to find the project as well as the Github repository.</blockquote><p>If you found this article helpful and educating, please hit the clap button and also share with your friends.<br>You can keep in touch with me via <a href="https://www.linkedin.com/in/vishesh-dugar-8464341b7/">LinkedIn</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfd6fa3df037" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Node.js backend for your Flutter Application]]></title>
            <link>https://medium.com/@dugarvishesh/creating-a-node-js-backend-for-your-flutter-application-296745494785?source=rss-b977e7093eba------2</link>
            <guid isPermaLink="false">https://medium.com/p/296745494785</guid>
            <category><![CDATA[ngrok]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Vishesh Dugar]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 14:59:27 GMT</pubDate>
            <atom:updated>2022-08-10T20:25:33.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lykUg7-md6glPaxogIo_0Q.png" /></figure><p>We know that Node.js is a very popular backend choice and is used by a large variety of companies for their products. At the same time Flutter is a cross-platform framework that lets you develop for Android, iOS, Web, Windows, macOS, and Linux. In this article, we are going to create a functioning Node.js backend for a Flutter application.</p><p>We are going to need a couple of things before we get started:</p><ul><li>Configure <strong>Vysor</strong> on both your PC and Mobile.</li><li>Configure <strong>ngrok </strong>on your PC.</li></ul><p><em>What is </em><strong><em>ngrok</em></strong><em>?</em></p><p>It’s a service that lets you make your localhost URL temporarily accessible to the Web. It does so by creating a Public URL and forwarding all requests made to this URL to the localhost. So, why do we need this?</p><p>Suppose you are using a real device for this application, which needs several resources like mic, camera, etc that the emulators cannot provide. Now, there are going to be <strong>two </strong><em>localhosts. </em>One for the mobile device and one for the PC. Obviously, if you want to utilise the backend resources you cannot ping the <em>localhost</em> of your Mobile device. There are two solutions for this problem:</p><ul><li>Deploy your backend to get a public URL.</li><li>Use <a href="https://ngrok.com/"><strong>ngrok</strong></a></li></ul><p>While testing, it may be undesirable to incur expenses associated with cloud. Therefore, ngrok is especially useful when the Application is in the development phase. Now let’s start!</p><p>Let us make the backend first. Open your code editor, and in this project directory make two subfolders: app and server</p><p>Inside server, Run npm init -y to initialise npm and skip the questionnaire. Install express.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eC3zvMe3g0xH8q8Ne4H0VA.png" /><figcaption>Server code</figcaption></figure><p>Then open your <em>Terminal</em>, and run ngrok http 3000. If you have configured ngrok correctly and saved the auth token as instructed you will see something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OVehGrFGFbOhGmU9yneHw.png" /><figcaption>ngrok</figcaption></figure><p>Now let’s initialise our Flutter application inside app. Run flutter pub add http. Now let’s make the UI.</p><blockquote>All the code is contained in the GitHub Repo linked at the end of this Article.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7DmrYtfPjR3cEt4Ws0RbvQ.png" /><figcaption>Flutter App</figcaption></figure><p>Now, enter anything inside the TextFormField and <strong>Send </strong>the request. Your Terminal should indicate an 200:OK request and your UI should change accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVWxPoGQaQquIGPUAkj-ww.png" /><figcaption>ngrok (received request)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e5A4Mi7Cq8sDiS6rwemsTA.png" /><figcaption>Flutter App (received response)</figcaption></figure><p>And that’s it!! You have successfully made a Node.js backend for your Flutter App. Next, we are going to make a full-fledged blog application using this basic setup.</p><blockquote>Code: <a href="https://github.com/Calladrus2001/medium-dugarvishesh">GitHub Repo</a></blockquote><p>If you found this article helpful and educating, please hit the clap button and also share with your friends.<br>You can keep in touch with me via <a href="https://www.linkedin.com/in/vishesh-dugar-8464341b7/">LinkedIn</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=296745494785" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a Chatbot in Flutter with DialogFlow]]></title>
            <link>https://medium.com/@dugarvishesh/make-a-chatbot-in-flutter-with-dialogflow-46b7e26cb70a?source=rss-b977e7093eba------2</link>
            <guid isPermaLink="false">https://medium.com/p/46b7e26cb70a</guid>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[dialogflow]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Vishesh Dugar]]></dc:creator>
            <pubDate>Mon, 27 Jun 2022 09:45:48 GMT</pubDate>
            <atom:updated>2022-06-27T09:45:48.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVQipFhMxs7tvEP1pvVjsQ.png" /></figure><p><strong>Chatbots</strong> are all the rage right now on all customer-centric ecommerce websites and apps. Its a preconception that making a Chatbot requires a deep understanding of <em>NLP</em> fundamentals. But i am here to tell you that you absolutely don’t need that much experience. You can make a chatbot in <em>Flutter</em> using <strong>DialogFlow</strong> in less time than one <em>Money Heist</em> Episode.</p><p>So, What exactly are we going to do ? I have divided the process into three broad stages:</p><ul><li>Set up <em>DialogFlow </em>in <strong>Google Cloud console</strong>.</li><li>Training the Chatbot Agent on DialogFlow.</li><li>Setting up the Flutter Application.</li></ul><p>First, head to your Google Cloud console and make a new Project (You can skip this stage if you have already configured a Project).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhTVOR6yRxiyZL06A9uabQ.png" /><figcaption>Making a New Project in GCP Console</figcaption></figure><p>Now head to Navigation menu -&gt; APIs and Services -&gt; Enabled APIs and Services. Enter search query <em>DialogFlow </em>here and Enable the API.</p><p>Then in the APIs and Services Menu -&gt; Credentials -&gt; Create Credentials and select <strong>Service Account.</strong></p><ul><li>Enter Service Account name.</li><li>Select <strong>Dialogflow API Admin </strong>in <em>Roles </em>option.</li><li>Click Done.</li></ul><p>Now, click on the <em>Edit Service Account </em>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOgMVXv7E2jVsEX-l9yT5g.png" /></figure><p>Go to <em>Keys -&gt; Add Key -&gt; Create New key -&gt; JSON</em>. After this, the key will download automatically. It’s important that you keep this <strong>Safe</strong>.</p><p>Now, go to <a href="https://dialogflow.cloud.google.com/">https://dialogflow.cloud.google.com</a> and create a new agent and enter the required information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vqrg2MFPwHUS5WyqAW5zHw.png" /></figure><p>Now, lets explore what we have here. We are greeted with 2 <em>default intents.</em></p><ul><li><strong>Default Welcome Intent : </strong>This intent greets users and is typically used as a conversation starter.</li><li><strong>Default Fallback Intent: </strong>This intent comes into play whenever User gives an input that is not understood by the chatbot.</li></ul><p>Now, let’s see how we are going to train out chatbot using these intents. Tap <em>Create Intent </em>and assign a name to it. For this tutorial we are going to work with:</p><ul><li><strong>Training Phrases: </strong>Input given by the User.</li><li><strong>Responses: </strong>Output given by the Chatbot.</li></ul><p>Let’s add some <em>Training Phrases </em>and <em>Responses </em>to our intent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbxSV6cZYXfnVLlWUfIdXQ.png" /><figcaption>Training Phrases</figcaption></figure><blockquote>Ignore the yellow highlight on 2022 for now, We will discuss the concept of <strong>Entities</strong><em> </em>in forthcoming parts of this tutorial.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHw_6kPdxUlcQgiuDb5VPA.png" /><figcaption>Responses</figcaption></figure><p>Then click on <em>Save. </em>There we go! Our agent is trained now, Let’s test it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgFYZ8IRU7jCfPMuXdKwBQ.png" /></figure><p>Great! Our <em>DialogFlow </em>agent is ready, Lets make a Flutter App to put it to use.</p><p>Create a New <em>Flutter </em>Project and include the following plugins in the pubspec.yaml :</p><pre>dependencies:    <br>    dialog_flowtter: ^0.3.3<br>    bubble: ^1.2.1</pre><blockquote>In the past we used <strong>flutter_dialogflow </strong>plugin, but it’s dependent on an older version of <strong>http </strong>package. Since several popular plugins are dependent on newer versions of <strong>http</strong> package, It creates version conflict and prevents app from building successfully.</blockquote><p>Now, Remember that JSON file that we downloaded from GCP ? We are going to use it now.</p><pre>assets:<br>  - assets/name_of_that_key.json</pre><p>Now, lets get to the real nitty-gritty part : The Code. Firstly, main.dart</p><pre>import &#39;package:bubble/bubble.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:dialog_flowtter/dialog_flowtter.dart&#39;;<br><br>void main<em>() {<br>  </em>runApp<em>(</em>const MyApp<em>())</em>;<br><em>}<br><br></em>class MyApp extends StatelessWidget <em>{<br>  </em>const MyApp<em>({</em>Key? key<em>}) </em>: super<em>(</em>key: key<em>)</em>;<br><br>  @override<br>  Widget build<em>(</em>BuildContext context<em>) {<br>    </em>return MaterialApp<em>(<br>      </em>debugShowCheckedModeBanner: false,<br>      title: &#39;Flutter Demo&#39;,<br>      home: ChatBot<em>()</em>,<br>    <em>)</em>;<br>  <em>}<br>}</em></pre><p>Then, we’ll make the class for ChatBot :</p><pre>class ChatBot extends StatefulWidget <em>{<br>  </em>const ChatBot<em>({</em>Key? key<em>}) </em>: super<em>(</em>key: key<em>)</em>;<br><br>  @override<br>  State<em>&lt;</em>ChatBot<em>&gt; </em>createState<em>() </em>=&gt; _ChatBotState<em>()</em>;<br><em>}<br><br></em>class _ChatBotState extends State<em>&lt;</em>ChatBot<em>&gt; {<br>  </em>Color clr1 = Colors.<em>blue</em>;<br>  late DialogFlowtter instance;<br>  final messageController = new TextEditingController<em>()</em>;<br>  Future<em>&lt;</em>void<em>&gt; </em>getInstance<em>() </em>async <em>{<br>    </em>instance = await DialogFlowtter.<em>fromFile(<br>        </em>path: &quot;assets/name_of_your_key.json&quot;,<br>        sessionId: &quot;any_random_string_will_do&quot;<em>)</em>;<br>  <em>}<br><br>  </em>@override<br>  void initState<em>() {<br>    </em>getInstance<em>()</em>;<br>    super.initState<em>()</em>;<br>  <em>}<br><br>  </em>@override<br>  void dispose<em>() {<br>    </em>instance.dispose<em>()</em>;<br>    super.dispose<em>()</em>;<br>  <em>}<br><br>  </em>List<em>&lt;</em>Map<em>&gt; </em>messsages = <em>[]</em>;<br><br>  Future<em>&lt;</em>void<em>&gt; </em>getResponse<em>() </em>async <em>{<br>    </em>DetectIntentResponse response = await instance.detectIntent<em>(<br>      </em>queryInput: QueryInput<em>(</em>text: TextInput<em>(</em>text: messageController.text<em>))</em>,<br>    <em>)</em>;<br>    String? textResponse = response.text;<br>    print<em>(</em>textResponse<em>)</em>;<br>    setState<em>(() {<br>      </em>messsages.insert<em>(</em>0, <em>{</em>&quot;data&quot;: 0, &quot;message&quot;: textResponse<em>})</em>;<br>    <em>})</em>;<br>  <em>}<br><br>  </em>@override<br>  Widget build<em>(</em>BuildContext context<em>) {<br>    </em>return Scaffold<em>(<br>      </em>body: Padding<em>(<br>        </em>padding: const EdgeInsets.symmetric<em>(</em>horizontal: 8.0, vertical: 10<em>)</em>,<br>        child: Column<em>(<br>          </em>children: <em>[</em><br>            Flexible<em>(<br>                </em>child: ListView.builder<em>(<br>                    </em>reverse: true,<br>                    itemCount: messsages.length,<br>                    itemBuilder: <em>(</em>context, index<em>) </em>=&gt; chat<em>(<br>                        </em>messsages<em>[</em>index<em>][</em>&quot;message&quot;<em>]</em>.toString<em>()</em>,<br>                        messsages<em>[</em>index<em>][</em>&quot;data&quot;<em>])))</em>,<br>            Container<em>(<br>              </em>child: ListTile<em>(<br>                </em>title: Container<em>(<br>                  </em>padding: EdgeInsets.only<em>(</em>left: 10<em>)</em>,<br>                  decoration: BoxDecoration<em>(<br>                      </em>color: Color<em>(</em>0xffF2F4F6<em>)</em>,<br>                      borderRadius: BorderRadius.all<em>(</em>Radius.circular<em>(</em>15<em>)))</em>,<br>                  child: TextFormField<em>(<br>                    </em>controller: messageController,<br>                    decoration: InputDecoration<em>(<br>                        </em>hintText: &quot;Send Message&quot;,<br>                        border: InputBorder.<em>none</em>,<br>                        focusedBorder: InputBorder.<em>none</em>,<br>                        enabledBorder: InputBorder.<em>none</em>,<br>                        errorBorder: InputBorder.<em>none</em>,<br>                        disabledBorder: InputBorder.<em>none)</em>,<br>                    cursorColor: clr1,<br>                  <em>)</em>,<br>                <em>)</em>,<br>                trailing: GestureDetector<em>(<br>                  </em>child: Icon<em>(</em>Icons.<em>send_outlined</em>, color: clr1<em>)</em>,<br>                  onTap: <em>() {<br>                    </em>getResponse<em>()</em>;<br>                    setState<em>(() {<br>                      </em>messsages.insert<em>(<br>                          </em>0, <em>{</em>&quot;data&quot;: 1, &quot;message&quot;: messageController.text<em>})</em>;<br>                    <em>})</em>;<br>                    messageController.clear<em>()</em>;<br>                  <em>}</em>,<br>                <em>)</em>,<br>              <em>)</em>,<br>            <em>)</em>,<br>            SizedBox<em>(</em>height: 10<em>)</em>,<br>          <em>]</em>,<br>        <em>)</em>,<br>      <em>)</em>,<br>    <em>)</em>;<br>  <em>}<br><br>  </em>Widget chat<em>(</em>String message, int data<em>) {<br>    </em>return Container<em>(<br>      </em>padding: EdgeInsets.only<em>(</em>left: 20, right: 20<em>)</em>,<br>      child: Row<em>(<br>        </em>mainAxisAlignment:<br>            data == 1 ? MainAxisAlignment.end : MainAxisAlignment.start,<br>        children: <em>[<br>          </em>data == 0<br>              ? Container<em>(<br>                  </em>height: 60,<br>                  width: 60,<br>                  child: CircleAvatar<em>(<br>                    </em>backgroundColor: clr1,<br>                    child: Text<em>(</em>&quot;Bot&quot;, style: TextStyle<em>(</em>color: Colors.<em>white))</em>,<br>                  <em>)</em>,<br>                <em>)<br>              </em>: Container<em>()</em>,<br>          Padding<em>(<br>            </em>padding: EdgeInsets.all<em>(</em>10.0<em>)</em>,<br>            child: Bubble<em>(<br>                </em>borderWidth: data == 0 ? 1 : 0,<br>                borderColor: clr1,<br>                radius: Radius.circular<em>(</em>15.0<em>)</em>,<br>                color: data == 0 ? Colors.<em>white </em>: clr1,<br>                elevation: 0.0,<br>                child: Padding<em>(<br>                  </em>padding: EdgeInsets.all<em>(</em>2.0<em>)</em>,<br>                  child: Row<em>(<br>                    </em>mainAxisSize: MainAxisSize.min,<br>                    children: <em>&lt;</em>Widget<em>&gt;[<br>                      </em>SizedBox<em>(<br>                        </em>width: 10.0,<br>                      <em>)</em>,<br>                      Flexible<em>(<br>                          </em>child: Container<em>(<br>                        </em>constraints: BoxConstraints<em>(</em>maxWidth: 200<em>)</em>,<br>                        child: Text<em>(<br>                          </em>message,<br>                          style: data == 0<br>                              ? TextStyle<em>(<br>                                  </em>color: clr1, fontWeight: FontWeight.<em>bold)<br>                              </em>: TextStyle<em>(<br>                                  </em>color: Colors.<em>white</em>,<br>                                  fontWeight: FontWeight.<em>bold)</em>,<br>                        <em>)</em>,<br>                      <em>))<br>                    ]</em>,<br>                  <em>)</em>,<br>                <em>))</em>,<br>          <em>)</em>,<br>          data == 1<br>              ? Container<em>(<br>                  </em>child: CircleAvatar<em>(<br>                    </em>minRadius: 30,<br>                    child: CircleAvatar<em>(<br>                      </em>minRadius: 29,<br>                      backgroundColor: Colors.<em>white</em>,<br>                      child: Text<em>(</em>&quot;You&quot;, style: TextStyle<em>(</em>color: clr1<em>))</em>,<br>                    <em>)</em>,<br>                    backgroundColor: clr1,<br>                  <em>)</em>,<br>                <em>)<br>              </em>: Container<em>()</em>,<br>        <em>]</em>,<br>      <em>)</em>,<br>    <em>)</em>;<br>  <em>}<br>}</em></pre><p>And once we run this, we get the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3kndSBoAeHpjJqYhMQm5cA.png" /></figure><p>We have successfully made a <strong>Chatbot </strong>in <strong>DialogFlow</strong> and incorporated it in <strong>Flutter</strong>. Now, see if you did this before that <em>Money Heist </em>episode ended.</p><blockquote>Some possible issues:<br>1. You may have forgotten to place the JSON file asset in pubspec.<br>2. You may not have granted DialogFlow API Admin permission to the Service Account.</blockquote><p>If you found this article helpful and educating, please hit the clap button and also share with your friends.<br>You can keep in touch with me via <a href="https://www.linkedin.com/in/vishesh-dugar-8464341b7/">LinkedIn</a> .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46b7e26cb70a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>