<?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"><channel><title><![CDATA[Gulshan Yadav]]></title><description><![CDATA[I am a full-stack developer. Currently, I am a student tinkering around to find the things I love to do. Currently, getting my hands dirty with each and every stuff which can help me grow.]]></description><link>https://gulshan.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 12:17:50 GMT</lastBuildDate><atom:link href="https://gulshan.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[An overview to WASM]]></title><description><![CDATA[Hey there,
I'm glad to see you here.
In today's article, we will take a look into the concepts of web assembly And, I will walk you through the initial setup for configuring your working environment for web assembly development.
Before starting, Let ...]]></description><link>https://gulshan.dev/an-overview-to-wasm</link><guid isPermaLink="true">https://gulshan.dev/an-overview-to-wasm</guid><category><![CDATA[Web Development]]></category><category><![CDATA[C++]]></category><category><![CDATA[Rust]]></category><category><![CDATA[.NET]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Wed, 24 Nov 2021 07:49:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1637740051921/8CQ6waDBD.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey there,</p>
<p>I'm glad to see you here.</p>
<p>In today's article, we will take a look into the concepts of <code>web assembly</code> And, I will walk you through the initial setup for configuring your working environment for <code>web assembly</code> development.</p>
<p>Before starting, Let me answer some of the questions.</p>
<h3 id="heading-what-is-web-assemblywhat-is-web-assembly"><strong><a class="post-section-overview" href="#what-is-web-assembly">What is Web Assembly?</a></strong></h3>
<p>WebAssembly is a new type of code that can be run in modern browsers, which brings new features and significant improvements to performance.</p>
<p>Well, it's not intended to write the whole assembly code by hand. 
It is designed to be an effective compilation target for source languages like C/C++, rust, etc.</p>
<h3 id="heading-why-web-assemblywhy-web-assembly"><strong><a class="post-section-overview" href="#why-web-assembly">Why Web Assembly?</a></strong></h3>
<p>Web assembly allows developers to run code written in several programming languages on the web, at near-native speeds while leveraging hardware capabilities that are common to most platforms.</p>
<p>A web platform has two parts:</p>
<ul>
<li>A virtual machine (VM) that runs the Web app’s code. e.g. the JavaScript code that powers your apps.</li>
<li>A set of <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API">Web APIs</a> that the Web app can call to control web browser/device functionality and make things happen. (<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model">DOM</a>, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model">CSSOM</a>, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API">WebGL</a>, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API">IndexedDB</a>, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API">Web Audio API</a>, etc.).</li>
</ul>
<p>Hmm, but why to even use web Assembly? All this stuff seems unnecessary. JavaScript works well when developing for the web.</p>
<p>Yeah. JavaScript is great, and 90% of the time, you don't even have to think about developing in web Assembly.</p>
<p>But when while developing a performance-intensive web application, JavaScript alone wouldn't be a good choice.</p>
<blockquote>
<blockquote>
<p>Performance intensive web app examples, 3D games, Virtual and Augmented Reality, computer vision, image/video editing, and serveral other domains that demand native performance.</p>
</blockquote>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1637739496684/pNRzxGwQG.gif" alt="exploding_head.gif" /></p>
<h3 id="heading-will-it-replace-javascriptwill-it-replace-javascript"><strong><a class="post-section-overview" href="#will-it-replace-javascript">Will it replace JavaScript?</a></strong></h3>
<p><strong>Hell No!</strong></p>
<p>It is built to complement and work alongside JavaScript, allowing web developers to take of both.</p>
<blockquote>
<blockquote>
<ul>
<li><p>JavaScript is a high-level language, flexible and expressive enough to write code. It also has a huge ecosystem that provides powerful frameworks, libraries, etc.</p>
</li>
<li><p>WebAssembly is a low-level assembly-like language. And it has a compact binary format that runs with near-native performance.</p>
</li>
</ul>
</blockquote>
</blockquote>
<p>With Web Assembly in the browser, the virtual machine that we talked about earlier will now load and run two types of code — JavaScript and WebAssembly.</p>
<h3 id="heading-right-now-you-must-be-thinking-how-do-both-languages-work-together"><strong>Right now, you must be thinking, how do both languages work together?</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1637739480938/eJOMYi1fa.gif" alt="monocle.gif" /></p>
<p>Yeah JavaScript Web Assembly API wraps the web Assembly code into the JavaScript function that can be called normally. </p>
<p>And yeah, Web Assembly can also import and call the normal JavaScript function "synchronously".</p>
<blockquote>
<p>Wanna know more? <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly">WebAssembly - JavaScript | MDN</a></p>
</blockquote>
<p>Now that we are clear why, how, what is Web Assembly. Let's dig into</p>
<h3 id="heading-key-concepts-of-web-assemblykey-concepts-of-web-assembly"><strong><a class="post-section-overview" href="#key-concepts-of-web-assembly">Key Concepts of Web Assembly</a></strong></h3>
<p>The JavaScript API provides developers with the ability to create <code>modules</code>, <code>memories</code>, <code>tables</code>, and <code>instances</code>.</p>
<p><strong>By the way, what are these?</strong></p>
<blockquote>
<p>Modules</p>
<blockquote>
<p>It represents a WebAssembly library that has been compiled by the browser into executable machine code. And that's pretty much it.</p>
<p>Nothing Special.</p>
</blockquote>
<p>Memory</p>
<blockquote>
<p>It is an ArrayBuffer that contains the linear array of bytes read and are written by the low-level memory instruction.</p>
<p><em>This is a kind of technical definition of memory. That's it. Nothing much to worry about.</em></p>
<p>If you're familiar with C++, imagine this as a Vector. Which is also known as a resizable array. That's it!</p>
</blockquote>
<p>Table</p>
<blockquote>
<p>It's a resizable array too, but it stores the references. </p>
<p><strong>References of what??</strong></p>
<blockquote>
<p>JS Functions, etc. For safety and portability reasons.</p>
</blockquote>
</blockquote>
<p>Instance</p>
<blockquote>
<p>It's a module that is paired with all the states, including Memory, table, and set of imported values.</p>
</blockquote>
</blockquote>
<p>These were some definitions or concepts in the sense which are required when dealing with WASM.</p>
<p>On the side-note, Since JavaScript has complete control over how Web Assembly code is downloaded. compiled and run. </p>
<p>JS Developers could even think of WebAssembly as just a JavaScript feature for efficiently generating high-performance functions.</p>
<hr />
<p>Above we talked about the raw primitives that WebAssembly adds to the Web platform: a binary format for code and APIs for loading and running this binary code.</p>
<p>In my next article on WASM, I will walk you through using WASM in your application.</p>
<p>Excited to learn?</p>
<p>Feel free to sign up for my <a target="_blank" href="https://blog.bufferoverflow.me">newsletter</a>. I'm not regular currently for writing articles due to my pathetic timetable. But I will try to publish new Articles Every Week from now.</p>
<p>Cya, Happy Learning 😄
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1637739452967/ruyN6xUQu.gif" alt="bye.gif" /></p>
]]></content:encoded></item><item><title><![CDATA[Flutter Provider: Zero to Hero]]></title><description><![CDATA[Hey, it's Gulshan Yadav,
I'm back with another article on Flutter.
So, what are we going to learn today?
In this article, I’ll cover state management through Provider in Flutter.
But before starting out, I want to answer some basic questions,
What is...]]></description><link>https://gulshan.dev/flutter-provider-zero-to-hero</link><guid isPermaLink="true">https://gulshan.dev/flutter-provider-zero-to-hero</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Flutter SDK]]></category><category><![CDATA[Android]]></category><category><![CDATA[iOS]]></category><category><![CDATA[Windows]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Mon, 01 Nov 2021 14:48:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1635778021391/FqWo114IK.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey, it's <a target="_blank" href="https://www.linkedin.com/in/yadavgulshan/"><strong>Gulshan Yadav</strong></a>,<br />
I'm back with another article on Flutter.</p>
<h3 id="so-what-are-we-going-to-learn-today">So, what are we going to learn today?</h3>
<p>In this article, I’ll cover state management through Provider in Flutter.</p>
<p>But before starting out, I want to answer some basic questions,</p>
<h3 id="what-is-state-management-in-the-first-place">What is State-Management in the First Place?</h3>
<p>According to Wikipedia, </p>
<blockquote>
<p><strong><em>State management</em></strong> refers to the management of the state of one or more user interface controls such as text fields, OK buttons, radio buttons, etc. in a graphical user interface.<br /></p>
</blockquote>
<p>By the way, this definition gave me loose motion. 🥴</p>
<p>Let me give you my definition of State Management using an example,</p>
<p>Think of our classic counter application,
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635769695921/x_ZZYTuXS.png" alt="Counter App" /></p>
<p>You see there’s an Add button and Text at the center stating the number of times you performed a click event on the <strong>ADD</strong> button.<br /></p>
<h3 id="but-how-is-this-even-related-to-state-management">But how is this even related to state management?</h3>
<p>Well, Here changing the value of the text at the center according to the value stored in the variable is State-Management!<br /></p>
<p>Now head back to our Wikipedia Definition, After this example, I think you’re pretty much clear about, <strong>What is State-Management?</strong><br /></p>
<p>As our application is already updating the U.I. according to the value inside the variable.<br />
In light of this, we can conclude that our counter application already manages the state.<br /></p>
<p>You guessed it right!<br /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635775503206/MLJDWihah.png" alt="image.png" /></p>
<p><strong>SetState</strong> is managing our state in this case!</p>
<pre><code><span class="hljs-attribute">Gangadhar</span> hi Shaktimaan hai 👀
</code></pre><p>Let's implement the provider in our application now.<br /> </p>
<h3 id="step-1-create-a-flutter-application">Step 1: Create a flutter application.</h3>
<h3 id="step-2-add-provider-into-your-pubspecyaml-file">Step 2: Add <code>provider</code> into your pubspec.yaml file.</h3>
<h3 id="step-3-wrap-your-material-app-with-multiprovider">Step 3: Wrap your Material app with <code>MultiProvider</code>.</h3>
<blockquote>
<p><strong>What does it do?</strong></p>
<blockquote>
<p>Well, this will act as a tunnel for your application.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635769771957/13xrWJ94P.png" alt="Provider Diagram" /></p>
</blockquote>
</blockquote>
<p>Something like this. This diagram depicts that every method declared inside a class which extends the <code>ChangeNotifier</code> will go through the tunnel named Provider or any state management package. </p>
<h3 id="but-why-is-this-even-needed">But why is this even needed?</h3>
<blockquote>
<p>Using a state management package like Provider or any other makes your code more readable. Imagine using <code>setstate</code> everywhere. That would work too. But in this case, you will be irritated when developing a massive project.</p>
</blockquote>
<h3 id="why-use-a-provider">Why use a provider?</h3>
<blockquote>
<p>You can use any state management package you want. It doesn't matter at all. The concepts are the same in all cases. When using bloc, riverpod, getx, or anything. The concept explained above is the same.</p>
</blockquote>
<p><strong>Let's get back to our steps,</strong></p>
<h3 id="step-4-create-a-class-that-extends-the-changenotifier">Step 4: Create a class that extends the changeNotifier</h3>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CounterNotifier</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ChangeNotifier</span> </span>{}
</code></pre><blockquote>
<p><strong>What’s the task of this class?</strong></p>
<blockquote>
<p>Here we will declare all the methods that we want to use in our application. </p>
<p>Since we’re building a counter application using flutter, 
we will be adding the <code>increment</code> and <code>decrement</code> methods to control the centered text.<br /></p>
<blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635775616314/t8dH-YAZh.png" alt="Counter" /></p>
</blockquote>
</blockquote>
</blockquote>
<h3 id="step-5-define-the-methods">Step 5: Define the methods</h3>
<p>Let's Go! 💪</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CounterNotifier</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ChangeNotifier</span> </span>{
  <span class="hljs-built_in">int</span> counter = <span class="hljs-number">0</span>;

  <span class="hljs-keyword">void</span> increment() {
    counter++;
    notifyListeners();
  }

  <span class="hljs-keyword">void</span> decrement() {
    <span class="hljs-keyword">if</span> (counter &gt; <span class="hljs-number">0</span>) {
      counter--;
      notifyListeners();
    }
  }

  <span class="hljs-keyword">get</span> count =&gt; counter;
}
</code></pre><p>Hmm, looking at the code, I guess you have understood everything going on. But still, let me explain too 😅 ( That’s why I’m writing this blog naa ).<br /><br />
The first thing inside our class is our variable that will be used by our widget to update its state.
<br /><br />
The next two methods are also simple to understand. But there's something important inside those.
<br />
<code>notifyListeners()</code> method!<br /></p>
<p>Using this method, we are telling our widget,<br />
<strong>Hey you widget, the value inside this variable is updated. <br />Update the U.I. Man!!!</strong>
<br /><br />
<strong>Hmm, Now how to set our widget to listen to these changes??</strong><br /></p>
<blockquote>
<p><strong>Good Question!</strong> We need to use a consumer widget to do so.<br /></p>
<blockquote>
<p>Like this,</p>
<pre><code>Consumer&lt;CounterNotifier&gt;(
              builder: (context, watch, child) {
                <span class="hljs-keyword">return</span> Text(
                  watch.counter.toString(),
                  style: Theme.<span class="hljs-keyword">of</span>(context).textTheme.headline4,
                );
              },
            )
</code></pre></blockquote>
</blockquote>
<p>In the above example, I’m calling the <code>consumer</code> widget directing our <code>CounterNotifier</code> class which we defined.
<br />
<br />
To listen to our damn variable, we have used the watch variable.
<br /><br />
<strong>Now what??</strong><br />
Hey there’s more, we want to trigger the values too, right?<br />
For this we will use a button, In this case, we’re using floating buttons.<br /></p>
<p>Here's the usage,</p>
<pre><code><span class="hljs-attribute">floatingActionButton</span>: Row(
        <span class="hljs-attribute">mainAxisAlignment</span>: MainAxisAlignment.end,
        <span class="hljs-attribute">children</span>: &lt;Widget&gt;[
          FloatingActionButton(
            <span class="hljs-attribute">onPressed</span>: () =&gt; provider.increment(),
            <span class="hljs-attribute">tooltip</span>: <span class="hljs-string">'Increment'</span>,
            <span class="hljs-attribute">child</span>: const Icon(Icons.add),
          ),
          const SizedBox(<span class="hljs-attribute">width</span>: <span class="hljs-number">10</span>),
          FloatingActionButton(
            <span class="hljs-attribute">onPressed</span>: () {
              if (provider.counter &gt; <span class="hljs-number">0</span>) {
                provider.decrement();
              } else {
                ScaffoldMessenger.of(context).showSnackBar(
                  const SnackBar(
                    <span class="hljs-attribute">content</span>: Text(<span class="hljs-string">'Counter is already 0'</span>),
                  ),
                );
              }
            },
            <span class="hljs-attribute">tooltip</span>: <span class="hljs-string">'Decrement'</span>,
            <span class="hljs-attribute">child</span>: const Icon(Icons.remove),
          ),
</code></pre><h3 id="hey-but-what-is-that-provider">Hey but, what is that <code>provider</code>?</h3>
<blockquote>
<p>Umm, I made an alias. Here,</p>
<pre><code><span class="hljs-attr">provider</span> = Provider.of&lt;CounterNotifier&gt;(context, listen=<span class="hljs-literal">false</span>)<span class="hljs-comment">;</span>
</code></pre><p>Here’s the structure of our code,</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635776037837/I0fioy4Sb.png" alt="Project structure" /></p>
<p>And here’s the output,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1635776011870/Kb74VrjcP.png" alt="Output" /></p>
<p>Are you interested in seeing the code?<br />
There you go,
<a target="_blank" href="https://github.com/YadavGulshan/Blog-Projects/tree/master/provider_example">Source Code</a></p>
<p>Thanks for reading, I'll see you in my next article.<br />
Until then, Happy Coding!<br /></p>
<p>Cheers 😊</p>
<hr />
<p>If you have any doubts, do join my <a target="_blank" href="https://t.me/bufferoverflowdotme">Telegram Group</a> to clear them.</p>
]]></content:encoded></item><item><title><![CDATA[React: Zero to hero]]></title><description><![CDATA[Introduction 🤭
Hey Guys, It's Gulshan again with another article.
In this article, we will be going through some basics of react and its file structure.
It is the chapter 1 of my react series. I hope you'll love to learn by following my articles. 
W...]]></description><link>https://gulshan.dev/react-zero-to-hero</link><guid isPermaLink="true">https://gulshan.dev/react-zero-to-hero</guid><category><![CDATA[React]]></category><category><![CDATA[React Native]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[spa]]></category><category><![CDATA[responsive]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Mon, 18 Oct 2021 11:18:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1634555240664/aY0p1dCp8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="introductionintroduction"><a class="post-section-overview" href="#introduction">Introduction</a> 🤭</h3>
<p>Hey Guys, It's <strong>Gulshan</strong> again with another article.</p>
<p>In this article, we will be going through some basics of react and its file structure.</p>
<p>It is the chapter 1 of my react series. I hope you'll love to learn by following my articles. </p>
<h3 id="why-would-you-use-reactwhy-react"><a class="post-section-overview" href="#why-react">Why would you use react?</a> 🤔</h3>
<ul>
<li>It structures the "view" layer of your application</li>
<li>You can reuse the components you wrote.</li>
<li>Uses JSX</li>
<li>One can build interactive UIs with virtual DOM</li>
</ul>
<blockquote>
<p>If you aren't familiar with these words JSX, DOM, etc.</p>
<blockquote>
<p>Don't worry, I'll explain them.</p>
<blockquote>
<p>Please wait until I write an article on DOM or head over to <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model">MDN DOCS</a>.</p>
</blockquote>
</blockquote>
</blockquote>
<h3 id="what-are-the-prerequisitesprerequisites"><a class="post-section-overview" href="#prerequisites">What are the prerequisites?</a> 😳</h3>
<blockquote>
<ul>
<li>Basic HTML, CSS and JavaScript<blockquote>
<p>Some of the core JavaScript concepts required are,</p>
<ul>
<li>Understanding of DOM</li>
<li>Data types and all those basic things</li>
<li>Promises and asynchronous programming</li>
<li>Array Methods like forEach() and Map()</li>
<li>How to make an HTTP request.</li>
</ul>
</blockquote>
</li>
</ul>
<blockquote>
<p>Note: <br />
<em>These aren't compulsory if you have previous experience in some programming language. You can relate those stuff with my upcoming blogs on react and Vanilla JavaScript.</em></p>
</blockquote>
</blockquote>
<h3 id="what-we-will-coverwhat-we-will-cover"><a class="post-section-overview" href="#what-we-will-cover">What we will cover?</a> 🧐</h3>
<blockquote>
<ul>
<li>We will understand the file structure of our react application.</li>
<li>We will also have a look at JSX, which seems a bit daunting. <br /></li>
<li>But I got you covered.<br />
I'll walk you through the basics of JSX, And will try my best to make you comfortable using JSX in react.</li>
</ul>
</blockquote>
<h4 id="for-those-who-dont-know-what-jsx-iswhat-is-jsx">For those who don't know <em><a class="post-section-overview" href="#what-is-jsx">what JSX is?</a></em></h4>
<blockquote>
<ul>
<li>Well, JSX is the templating language for react. It is an extension of JavaScript and is like a templating language but with the powers of JavaScript.</li>
</ul>
<p>Tip:</p>
<blockquote>
<p>Learning JSX will make you a better JavaScript developer.</p>
</blockquote>
</blockquote>
<p><strong>Ready to learn?</strong></p>
<h4 id="lets-get-started"><em>Let's get started,🔥</em></h4>
<p>We need a react project.<br />
For that, head over to your terminals and <a class="post-section-overview" href="#create-a-react-app">create a react app</a> by,</p>
<pre><code>npx <span class="hljs-keyword">create</span>-react-app my-app
</code></pre><p>It will create a react application with typescript files instead of JavaScript files.</p>
<blockquote>
<blockquote>
<ul>
<li>For those who don't have Node Js installed.<br /> 
Head over to <a target="_blank" href="https://nodejs.org/en/download/">Nodejs site</a> and install it.
And re-run the above command to create a react app.</li>
</ul>
</blockquote>
</blockquote>
<p>After the above procedure, you will have a project file structure like this,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633870517590/k0rv-jgKf.png" alt="react project structure" /></p>
<p>Now run,
<code>npm start</code> for running our react app.</p>
<p>Here's how it will look like,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633869864446/I9x7LblRj.png" alt="react app" /></p>
<p>Let's understand the file structure of our react application.</p>
<ul>
<li>The <code>package.json</code> file has the list of dependencies required.<blockquote>
<p>These are used by your react application</p>
</blockquote>
</li>
<li><p>The <code>package-lock.json</code> file has the version and other details of installed packages.</p>
</li>
<li><p>Open the <code>public</code> folder. This folder is a kind of gateway to our application. Right now, we don't have to deal with this folder.</p>
</li>
</ul>
<p>Umm, I want you to open the <code>index.html</code> file inside the <code>public</code> folder which you opened.</p>
<p>On line number 31, you see there's a <code>div</code> tag with id <code>root</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633871125186/7iAUFLB4j.png" alt="image.png" /></p>
<p>In another folder named <code>src</code>, you'll find an <code>index.js</code> file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633871218452/2OrLp2Vrt.png" alt="image.png" />
on line number 11, it says to get the element in the document ( i.e. our <code>public/index.html</code> ) with id <code>root</code> and run this script on it.</p>
<p>In our case, it is inserting our app into that <code>div</code>.</p>
<p>Where's the code of the app?</p>
<p>You will find the code of our current application inside the <code>app.js</code> file of the current directory.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633871483341/9SonPQn6V.png" alt="image.png" /></p>
<p>You see, this file is imported into the <code>index.js</code> file using <code>import App from './App';</code>.<br /> 
And its function <code>App</code> is called in the index file.</p>
<p>Now we have learned about the file structure and how this react app works. 
Let's open the <code>public/index.html</code> to customize the title of our application.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633871823801/4QvoofdD5.png" alt="image.png" /></p>
<p>While working with react, you don't have to save your file and restart the server to check the changes.<br />
The NPM engine does that for you.<br />
After all,<br /></p>
<p><strong>Let's answer some important questions,</strong></p>
<h4 id="what-does-it-mean">What does it mean? 😶</h4>
<p>If you're here, you have an idea about what is react. But then also in simple terms, </p>
<blockquote>
<ul>
<li>React is a library for building User interfaces.</li>
<li>React runs on the client browser as a SPA(Single Page Application).</li>
</ul>
<blockquote>
<p>By the way, what is SPA? What does it mean?</p>
<blockquote>
<p>For example, check <code>youtube.com</code> When you open that site on your desktop, it will load once. Then whatever you do with youtube, you won't see a loading indicator on the tab section of your browser.<br /><br />
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633872422589/llKWrlKz4.png" alt="Youtube tab" /></p>
</blockquote>
</blockquote>
</blockquote>
<p>Now open the <code>src/App.js</code> and check what's happening under the hood.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633874088614/bFAFZeFqB.png" alt="image.png" />
Looking at the code, it looks like the function <code>App</code> returns an HTML component. But it's not.
<br />
It looks like HTML. But when you check, you will find that HTML tags have the class attribute named <code>className</code> not <code>class</code>. 
<br />
This is JSX, not our good old HTML 🥺.</p>
<p>Now replace the code inside the <code>src/app.js</code> with the code shown in the image below,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633874710219/RfPIzrhF_.png" alt="image.png" /></p>
<p>I want to show you something, press <code>f12</code> or <code>ctrl + shift + I</code> on your keyboard,</p>
<p>You see, the website content has the boilerplate which we saw in file <code>public/index.html</code> and our <code>hello WOrld</code> between our <code>div</code> tag of id <code>root</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633934335961/7iNE3mwfw.png" alt="image.png" /></p>
<h3 id="okay-what-else-can-we-do-with-reactwhat-we-can-do-with-react">Okay, <a class="post-section-overview" href="#what-we-can-do-with-react">What else can we do with react?</a> 😁</h3>
<blockquote>
<p>As we are writing JSX code, we can use javascript inside our HTML body ( can say, for now )</p>
<blockquote>
<p>Something like,</p>
</blockquote>
</blockquote>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> username = <span class="hljs-string">"Gulshan"</span>;
  <span class="hljs-keyword">const</span> isConfirmed = <span class="hljs-literal">false</span>;
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"heading"</span>&gt;</span>{isConfirmed ? "Hello" + username : "Please login"}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre><p>Here in this code, I have used the ternary operator for writing this conditional element.</p>
<p>It is one of the advantages of react.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633935001765/DnuSys4a4.png" alt="image.png" /></p>
<p><strong>Let's build our component in react.😈</strong><br />
Head over to your src folder and create another folder named <code>components</code>. Here we will store our various <code>JSX</code> component files.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633935230608/pxqnIFWfy.png" alt="image.png" />
Ohh, by the way, you can have a JSX or js extension of your file. It won't make much difference, but it will allow your code editor to identify that this file is a react file. And this will help your editor to provide suggestions and formatting of code.</p>
<p>Else you have to tell your code editor, "Hey, this is a react file." which we don't want to do.</p>
<h4 id="suggestion">Suggestion 🤓:</h4>
<blockquote>
<p>If you're using VS CODE like me. Install the <code>ES7 React/Redux/GraphQL/React-Native snippets</code> extension. It will help you a lot and we will use it in the later section of this article.</p>
<p><a target="_blank" href="https://packagecontrol.io/packages/Sublime%20ES7%20React%20Redux%20ReactNative%20JS%20snippets">ES7 React/Redux/GraphQL/React-Native snippets for sublime</a></p>
<p><a target="_blank" href="https://vimawesome.com/plugin/vim-react-snippets-ours">For vim users</a></p>
</blockquote>
<hr />
<p>Now open our <code>src/components/header.jsx</code> file. Type <code>rafce</code>, It will create the boilerplate for our component.</p>
<pre><code><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">const</span> Header = <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>

        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Header
</code></pre><p>Replace the <code>div</code> element with <code>Header</code> in this file and add the title inside it.</p>
<pre><code><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">const</span> Header = <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Todo tracker<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span></span>
    )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Header
</code></pre><p>Press <code>ctrl+s</code> to save the changes, but there are no changes. Why?
You're supposed to import the required file into the main file. </p>
<p>In our case, the main file is <code>App.jsx</code> or <code>App.js</code>.</p>
<p>How to import our components?</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-keyword">Header</span> <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Header'</span>;
</code></pre><p>And now we have to embed it inside our code,</p>
<pre><code>&lt;<span class="hljs-keyword">Header</span> /&gt;
</code></pre><p> Add this line between our <code>div</code>.</p>
<p><code>index.jsx</code></p>
<pre><code><span class="hljs-keyword">import</span> Header <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Header'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Header</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre><p>And now save the code, and you can see the changes.</p>
<h3 id="how-to-use-the-components-in-react-like-a-function-or-how-to-pass-argumentshow-to-pass-argument-through-react-components"><a class="post-section-overview" href="#how-to-pass-argument-through-react-components">How to use the components in react like a function? Or how to pass arguments?</a> 🥶🧐</h3>
<blockquote>
<p><code>&lt;Header title="Gulshan" /&gt;</code>
<br /></p>
<h4 id="yeah-thats-it-but-hey-how-our-header-component-will-handle-this-argument">Yeah that's it. But hey how our header component will handle this argument?</h4>
<blockquote>
<p><code>src/components/header.jsx</code></p>
</blockquote>
</blockquote>
<pre><code><span class="hljs-keyword">const</span> Header = <span class="hljs-function">(<span class="hljs-params">argument</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello {argument.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span></span>
    )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Header
</code></pre><blockquote>
<blockquote>
<p>Write any word within the parenthesis and use it inside of your component.</p>
</blockquote>
</blockquote>
<h4 id="hey-wait-what-if-i-missed-to-pass-any-valuewhat-if-i-missed-to-pass-any-value-to-my-react-component"><a class="post-section-overview" href="#what-if-I-missed-to-pass-any-value-to-my-react-component">Hey, wait, what If I missed to pass any value?</a> 🤪</h4>
<blockquote>
<p>It will show nothing in the place of our component, or certain sections of our component will be empty.</p>
</blockquote>
<p>So for tackling this, we have <code>defaultProps</code>.</p>
<pre><code><span class="hljs-keyword">Header</span>.defaultProps = {
    title: "My title"
}
</code></pre><p>Add this at the end of your code inside the <code>header.jsx</code> file before that export .... line.</p>
<p>It will provide your component with a default property. That can be used when you didn't pass any value while using it.</p>
<h4 id="what-if-you-want-some-type-safetytype-safety"><a class="post-section-overview" href="#type-safety">What if you want some type safety?</a></h4>
<blockquote>
<blockquote>
<p>Type safety means a compiler will confirm the types such as <code>int</code>, <code>string</code>, <code>etc</code> While compiling your code. And it will throw an error if you tried to assign a variable with the value of wrong type.</p>
</blockquote>
<p>This is achieved using <code>propTypes</code> in JS.</p>
<blockquote>
<h4 id="how-to-use-ithow-implement-typesafety-in-react"><a class="post-section-overview" href="#how-implement-typesafety-in-react">How to use it?</a></h4>
<p>&gt;</p>
<pre><code><span class="hljs-comment">// Add this line below your code above the export stuff.</span>
Header.propTypes = {
    title: PropTypes.<span class="hljs-keyword">string</span>
}
</code></pre><blockquote>
<ul>
<li>This will ensure that you're passing a string or a variable of type <code>String</code>.</li>
<li>You can add <code>.isRequired</code> after the string key to ensure that your code is null safe.</li>
</ul>
</blockquote>
<h4 id="but-how-is-this-going-to-ensure-that-my-code-is-bug-free">But how is this going to ensure that my code is bug-free?</h4>
<p>We will receive an error message in the console tab of a browser if our rule/property does not meet the conditions.</p>
</blockquote>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633944627880/ydvkS0QiZ.png" alt="image.png" /></p>
<blockquote>
<p>If you don't want to define such properties, then you can use <code>TypeScript</code>. We will talk about this extension of JS in our later article.</p>
</blockquote>
<h4 id="how-to-use-css-inside-our-jsx-component-as-our-attributehow-to-use-css-inside-the-jsx-component"><a class="post-section-overview" href="#how-to-use-css-inside-the-jsx-component">How to use <code>CSS</code> inside our JSX component as our attribute?</a></h4>
<blockquote>
<p>Here's an example of it,</p>
</blockquote>
<pre><code><span class="hljs-comment">// argument is props, but I just used this as an example.</span>
<span class="hljs-keyword">const</span> Header = <span class="hljs-function">(<span class="hljs-params">argument</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span>
                <span class="hljs-attr">color:</span> '<span class="hljs-attr">blue</span>',
            }}&gt;</span>{argument.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span></span>
    )
}
</code></pre><blockquote>
<p>You have to write your CSS code inside the two curly braces.</p>
</blockquote>
<p>But we aren't done yet!</p>
<blockquote>
<p>Since we are using our typical JS code. We can declare our style inside a variable and use it as the value of the <code>style</code> attribute.</p>
</blockquote>
<p><code>Example:</code></p>
<pre><code><span class="hljs-keyword">import</span> PropTypes <span class="hljs-keyword">from</span> <span class="hljs-string">'prop-types'</span>

<span class="hljs-keyword">const</span> Header = <span class="hljs-function">(<span class="hljs-params">argument</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{HeaderStyle}</span>&gt;</span>{argument.title}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span></span>
    )
}

<span class="hljs-keyword">const</span> HeaderStyle = {
    <span class="hljs-attr">color</span>: <span class="hljs-string">'red'</span>,
}
Header.defaultProps = {
    <span class="hljs-attr">title</span>: <span class="hljs-string">"My Title"</span>
}

Header.propTypes = {
    <span class="hljs-attr">title</span>: PropTypes.string.isRequired
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Header
</code></pre><p>But we won't be doing this kind of stuff. <br />
Else, we will be using the index.css file for working with CSS in our React Application.</p>
<hr />
<p>Hmm, Looks like we're clear with the basics required. If any exists I'll cover it in my future article.<br /> Until then,<br /></p>
<p><strong>Happy Coding</strong>😊.</p>
<pre><code><span class="hljs-selector-tag">if</span> (youLikedThisArticle) {
    <span class="hljs-selector-tag">console</span><span class="hljs-selector-class">.log</span>(<span class="hljs-string">'Please smash the reaction buttons above.😊'</span>)
} <span class="hljs-selector-tag">else</span> {
 <span class="hljs-selector-tag">throw</span>(<span class="hljs-string">'Please write a comment below stating the issue. This would help me writing good articles for you. 😊'</span>);
}
</code></pre>]]></content:encoded></item><item><title><![CDATA[Hoisting in Javascript]]></title><description><![CDATA[Hey, you are back again!
In my previous articles, we have discussed some of the basic terminologies in JavaScript.
In this article, we'll be learning about hoisting in JavaScript.
So what is hoisting?

Hoisting refers to the process where the interpr...]]></description><link>https://gulshan.dev/hoisting-in-javascript</link><guid isPermaLink="true">https://gulshan.dev/hoisting-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Script]]></category><category><![CDATA[web scraping]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Mon, 13 Sep 2021 11:00:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1631530734862/lF8ccx_p_.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey, you are back again!<br /></p>
<p>In my previous articles, we have discussed some of the basic terminologies in JavaScript.</p>
<p>In this article, we'll be learning about <code>hoisting</code> in JavaScript.</p>
<h4 id="so-what-is-hoistingwhat-is-hoisting">So <a class="post-section-overview" href="#what-is-hoisting">what is <code>hoisting</code>?</a></h4>
<blockquote>
<p>Hoisting refers to the process where the interpreter allocates memory for a variable or function before its execution.<br /></p>
<p>In simple words, a variable or function can be used before it is declared.</p>
</blockquote>
<p>I hope you are clear till here.</p>
<p>Let's start with,</p>
<h4 id="variable-hoistingvariable-hoisting"><a class="post-section-overview" href="#variable-hoisting">Variable hoisting</a>.</h4>
<blockquote>
<p>As per the above definition, we can use a variable before declaring it.<br /></p>
</blockquote>
<p>So let's try it.</p>
<pre><code>
<span class="hljs-built_in">console</span>.log(Gulshan);

<span class="hljs-keyword">var</span> Gulshan = <span class="hljs-number">100</span>;
</code></pre><p>And that's it, run this code, and you will get an output of 100 without getting a <code>Reference error.</code></p>
<p><strong>Output:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631529643136/vs1gBiUTX.png" alt="Variable Hoisting" /></p>
<p>I hope you're clear till now.<br /></p>
<p>Let's understand function hoisting.<br /></p>
<p>If you understand the previous topic. i.e. <code>variable hoisting</code>.</p>
<p>I want you, to try it on your own now.</p>
<p>Nonetheless,</p>
<h4 id="function-hoistingfunction-hoisting"><a class="post-section-overview" href="#function-hoisting">Function hoisting</a>.</h4>
<blockquote>
<p>I want you to apply the above definition again.</p>
<blockquote>
<p>Function hoisting means that a function can be used before it is being executed.</p>
</blockquote>
</blockquote>
<p><em>Example code:</em></p>
<pre><code>
somefunction();

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">somefunction</span>(<span class="hljs-params"></span>)</span>{

 <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"hello"</span>);

}
</code></pre><p>Like the previous code, this piece of code will work too without any error.</p>
<p><strong>Output:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631530204131/5JldUuS-P.png" alt="Function Hoisting" /></p>
<p>You may ask, <strong>how all this works?</strong><br /></p>
<p>JavaScript interpreter defines all these variables and functions at the top of the program.</p>
<p><strong>Is it a good practice?</strong><br /></p>
<blockquote>
<p>Nope, this makes code confusing to read because you will find it harder to read the code when your code grows big in size.</p>
</blockquote>
<p>So you should declare your functions and variable at the top. </p>
<p>And hoisting doesn't add any performance benefits too. <br />
So it doesn't make any sense to use hoisting if you don't want to blow up your mind in fixing bugs.</p>
<h4 id="advantages-of-hoistingadvantages-of-hoisting"><a class="post-section-overview" href="#advantages-of-hoisting">Advantages of hoisting</a></h4>
<blockquote>
<p>Convenience?</p>
<blockquote>
<p>No .<br /></p>
</blockquote>
<p>It is convenient. Both to the reader of code as the coder. Not so much for variable hoisting, but function hoisting.<br /></p>
<p>This way, you can put the helper functions to the bottom of your code and the more abstract ones, which show your business logic at the top.</p>
</blockquote>
<h4 id="disadvantages-of-hoistingdisadvantages-of-hoisting"><a class="post-section-overview" href="#disadvantages-of-hoisting">Disadvantages of hoisting</a></h4>
<blockquote>
<p>You can access them before they are declared. In such a case, their value would be undefined though, as only declarations and not initializations are hoisted. <br />
Therefore it is generally considered a bad practice.</p>
</blockquote>
<hr />
<p>In my forthcoming article, I won't be covering all the basics. There are more great articles than mine.</p>
<p>You can find a ton of knowledge here,
<strong><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">MDN Docs</a></strong></p>
<p>In future articles, I'll be demonstrating to you how to write javascript programs.</p>
<p>I won't be touching web development as of now. We will be doing scripting, scraping, and many more using JavaScript (<strong>Advance mode</strong>)</p>
<hr />
<p>Until I come up with another article,<br /></p>
<p>Stay safe and happy coding.</p>
<p>Cya 😄</p>
]]></content:encoded></item><item><title><![CDATA[Basic grammar of JavaScript]]></title><description><![CDATA[Hey, beautiful people!👋
So you want to learn some basics of JavaScript?

So In this article, I'll be walking you through some basic grammar of JavaScript.
For starters, let's understand what are the use-cases of JavaScript.
JavaScript is a programmi...]]></description><link>https://gulshan.dev/basic-grammar-of-javascript</link><guid isPermaLink="true">https://gulshan.dev/basic-grammar-of-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Fri, 10 Sep 2021 18:23:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1631298186676/QtDnJjiVt.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey, beautiful people!👋</p>
<p>So you want to learn some basics of JavaScript?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631297228508/4fLxjUDnk.gif" alt="yes.gif" /></p>
<p>So In this article, I'll be walking you through some basic grammar of JavaScript.</p>
<p>For starters, let's understand what are the use-cases of JavaScript.</p>
<p>JavaScript is a programming language that is used to create dynamic web pages.</p>
<h3 id="what-are-dynamic-webpageswhat-are-dynamic-webpages"><a class="post-section-overview" href="#what-are-dynamic-webpages">what are dynamic webpages?</a></h3>
<blockquote>
<p>dynamic webpages are pages that are generated by the server.</p>
<p>for example, check youtube.com or facebook.com these are dynamic webpages.
But why are these are dynamic web pages?</p>
<blockquote>
<p>Becuase these pages are generated according to the data stored inside the server or database.
This is called server-side scripting.</p>
</blockquote>
</blockquote>
<h3 id="what-is-server-side-scriptingwhat-is-server-side-scripting"><a class="post-section-overview" href="#What-is-server-side-scripting">What is server side scripting?</a></h3>
<blockquote>
<p>In Simple terms, server-side scripting is the process of generating dynamic web pages.</p>
<blockquote>
<p>According to the wiki, </p>
</blockquote>
<p><em>Server-side scripting is a technique used in web development that involves employing scripts on a web server that produces a response customized for each user's (client's) request to the website. The alternative is for the web server itself to deliver a static web page.</em></p>
</blockquote>
<p>What this means is, the server-side script generates the webpages according to the data stored inside the database about the user.<br /></p>
<p>This information is used to generate web pages that are useful to the user.</p>
<p>This is it.</p>
<p>JavaScript shares most of its syntax with other programming languages like Java, C++, Python, etc.</p>
<hr />
<p>So if you are familiar with these programming languages, you can grasp the syntax of JavaScript with no issue.</p>
<p>If not, don't worry.<br />
I'll be explaining the syntax of JavaScript in detail.</p>
<hr />
<h3 id="javascript-is-case-sensitivejavascript-is-case-sensitive"><a class="post-section-overview" href="#JavaScript-is-case-Sensitive">JavaScript is case Sensitive</a></h3>
<blockquote>
<blockquote>
<p>So <code>var name = "John";</code> and <code>var Name = "John";</code> are two different variables.</p>
</blockquote>
</blockquote>
<p>So if you declared <code>name</code> and tried to access <code>Name</code>, it will throw an <code>Uncaught ReferenceError.</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631292860854/zt7ZiRTwI.png" alt="ReferenceError" /></p>
<p>Ahh, I didn't mention what is <code>console.log</code>?
You can use it to print the value of any variable or anything you want to print inside the console.</p>
<h3 id="what-is-a-consolewhat-is-a-console"><a class="post-section-overview" href="#What-is-a-console">What is a console?</a></h3>
<blockquote>
<p>A console is a part of the browser, used to check the output of the JavaScript code or debug the existing code and maybe for performing some nasty thing XD.</p>
<blockquote>
<p>To access the console, press <code>F12</code> on your keyboard.</p>
</blockquote>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631293137253/p0tFXthW_.png" alt="console" /></p>
<p>Here in the above image, I have declared a Variable. But how?</p>
<blockquote>
<p>In this example, I have used the <code>var</code> keyword.
But you can also use <code>let</code> or <code>const</code> keywords.</p>
<p>Using can also declare a variable without using any of the above keywords. (Yeah, a pythonic way)</p>
</blockquote>
<p>But there's a catch. <br />
An undeclared variable or a variable with no keywords will act as an undeclared global variable.</p>
<h3 id="whats-an-issue-with-undeclared-global-variablewhats-an-issue-with-undeclared-global-variable"><a class="post-section-overview" href="#What's-an-issue-with-undeclared-global-variable">What's an issue with undeclared global variable?</a></h3>
<p>To answer this question, Let's distinguish between a declared variable and an undeclared variable.</p>
<h4 id="declared-global-variabledeclared-global-variable"><a class="post-section-overview" href="#Declared-global-variable">Declared global variable</a></h4>
<blockquote>
<ul>
<li>Is a property of the default global object (window)</li>
<li>The property attributes cannot be changed.</li>
<li>Cannot be deleted using the delete operator.</li>
</ul>
</blockquote>
<h4 id="undeclared-global-variableundeclared-global-variable"><a class="post-section-overview" href="#Undeclared-global-variable">Undeclared global variable</a></h4>
<blockquote>
<ul>
<li>Is a property of the default global object (window).</li>
<li>The property attributes can be changed.</li>
<li>Can be deleted using the delete operator.</li>
</ul>
</blockquote>
<p>I know this is a bit confusing, <br /></p>
<blockquote>
<blockquote>
<p>In Simple terms, 
If you're declaring a variable with a keyword (<code>var</code>, <code>let</code>, <code>const</code>) inside a function, It is treated as a local variable.</p>
<p>But if you declared a variable without any keyword inside a function, it is treated as a global variable.</p>
</blockquote>
<p><strong>This is generally unsafe and should be avoided.</strong></p>
</blockquote>
<h4 id="lets-talk-more-about-the-declaration-in-javascript">Let's talk more about the declaration in JavaScript.</h4>
<p><strong>JavaScript has 3 types of declaration:</strong></p>
<h4 id="1-var">1. <code>var</code></h4>
<blockquote>
<p>The var statement declares a function-scoped or globally-scoped variable, optionally initializing it to a value. 
for example:</p>
</blockquote>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">x</span> <span class="hljs-string">=</span> <span class="hljs-number">1</span><span class="hljs-string">;</span>

<span class="hljs-string">if</span> <span class="hljs-string">(x</span> <span class="hljs-string">===</span> <span class="hljs-number">1</span><span class="hljs-string">)</span> {
  <span class="hljs-string">var</span> <span class="hljs-string">x</span> <span class="hljs-string">=</span> <span class="hljs-number">2</span><span class="hljs-string">;</span>

  <span class="hljs-string">console.log(x);</span>
  <span class="hljs-string">//</span> <span class="hljs-attr">expected output:</span> <span class="hljs-number">2</span>
}

<span class="hljs-string">console.log(x);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">expected output:</span> <span class="hljs-number">2</span>
</code></pre><blockquote>
<blockquote>
<p>You can say that the <code>var</code> declared variable is a globally-scoped variable. or a global variable.</p>
<h4 id="2-let">2. <code>let</code></h4>
<p>The let statement declares a block-scoped local variable, optionally initializing it to a value. 
for example:</p>
</blockquote>
</blockquote>
<pre><code><span class="hljs-string">let</span> <span class="hljs-string">x</span> <span class="hljs-string">=</span> <span class="hljs-number">1</span><span class="hljs-string">;</span>

<span class="hljs-string">if</span> <span class="hljs-string">(x</span> <span class="hljs-string">===</span> <span class="hljs-number">1</span><span class="hljs-string">)</span> {
  <span class="hljs-string">let</span> <span class="hljs-string">x</span> <span class="hljs-string">=</span> <span class="hljs-number">2</span><span class="hljs-string">;</span>

  <span class="hljs-string">console.log(x);</span>
  <span class="hljs-string">//</span> <span class="hljs-attr">expected output:</span> <span class="hljs-number">2</span>
}

<span class="hljs-string">console.log(x);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">expected output:</span> <span class="hljs-number">1</span>
</code></pre><blockquote>
<blockquote>
<p>Here, in this case, the life of a variable is limited to the block it is declared in.</p>
<h4 id="3-const">3. <code>const</code></h4>
<p>Constants are block-scoped, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment, and it can't be redeclared. 
For example:</p>
</blockquote>
</blockquote>
<pre><code><span class="hljs-keyword">const</span> <span class="hljs-built_in">number</span> = <span class="hljs-number">42</span>;

<span class="hljs-keyword">try</span> {
  <span class="hljs-built_in">number</span> = <span class="hljs-number">99</span>;
} <span class="hljs-keyword">catch</span> (err) {
  <span class="hljs-built_in">console</span>.log(err);
  <span class="hljs-comment">// expected output: TypeError: invalid assignment to const `number'</span>
  <span class="hljs-comment">// Note - error messages will vary depending on browser</span>
}

<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">number</span>);
<span class="hljs-comment">// expected output: 42</span>
</code></pre><blockquote>
<blockquote>
<p>Well, you guessed it right, a variable with type <code>const</code> is a constant variable. The value stored inside this variable cannot be changed.</p>
</blockquote>
</blockquote>
<h4 id="evaluating-variablesevaluating-variables"><a class="post-section-overview" href="#Evaluating-variables">Evaluating variables</a></h4>
<blockquote>
<p>A variable declared using keyword <code>var</code> or <code>let</code> with no assignment is undefined.</p>
<blockquote>
<p>So when you try reading the variables which you declared having value undefined, it will throw an error.</p>
</blockquote>
</blockquote>
<p>Obviously, what do you want from a variable which you declared without any value?</p>
<p><strong>what about a variable of type const?</strong></p>
<blockquote>
<p>JavaScript won't allow you to do so. It will throw an error when you try.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631295824674/Xbkmg4AyI.png" alt="declaring const variable with no value." /></p>
<p>Well, this undefined thing is not always a problem.</p>
<p>Imagine you're working on a project where you want to deal with some API.</p>
<p>Here, there can be a possibility that you're not able to get the data from the API.</p>
<p>So for dealing with this, you first store the data in a variable, and then you check if the data inside is undefined or not.</p>
<p>How do you do that?</p>
<p>Here's a simple example,</p>
<pre><code>var <span class="hljs-keyword">input</span>;
<span class="hljs-keyword">if</span> (input === undefined) {
  doThis();
} <span class="hljs-keyword">else</span> {
  doThat();
}
</code></pre><p>In this example, we are checking if the <code>input</code> variable is undefined or not.<br />
i.e. it is null or not.</p>
<p><strong>Since JavaScript is not null safe</strong>, a developer has to take care of that too.</p>
<hr />
<p>So this is it for now.<br />
In my future article, I'll be explaining the terms related to <code>hoisting</code> in JavaScript.</p>
<hr />
<p>Until then, stay safe and happy coding.
<br />
Cya 😊</p>
]]></content:encoded></item><item><title><![CDATA[How to use FutureBuilder Widget to create widgets based on the latest snapshot?]]></title><description><![CDATA[So you want to build a list of items in your application using some API efficiently
By Efficiently, I mean

When dealing with APIs, Your app or program can handle the latency or errors for you.


Dealing with situations like latency in fetching JSON ...]]></description><link>https://gulshan.dev/flutter-future-builder-and-list-view-explained</link><guid isPermaLink="true">https://gulshan.dev/flutter-future-builder-and-list-view-explained</guid><category><![CDATA[Flutter]]></category><category><![CDATA[ios app development]]></category><category><![CDATA[android app development]]></category><category><![CDATA[Linux]]></category><category><![CDATA[Windows]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Sat, 07 Aug 2021 15:25:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1628331574278/9EcRzISG7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>So you want to build a list of items in your application using some API efficiently</strong><br />
By Efficiently, I mean</p>
<blockquote>
<p>When dealing with APIs, Your app or program can handle the latency or errors for you.</p>
</blockquote>

Dealing with situations like latency in fetching JSON string or No Internet Connection in user's device,  may require you to write more lines of codes to handle such types of exceptions.<br />
<br />
Like for the latency issue, one can think of using Future delay to make your application wait for some time interval until your application is fetching the JSON string or whatsoever from the API.<br />
<br />
In case of a network connection issue, one can think of first making your application check that if Network connection can be established or not?<br />
<br />
If you find this interesting, then one can easily accomplish this by some lines of dart code. <br />
Umm, will share this in my future articles.<br />
<br />
<br />
So coming back to point, how can we use handle these kinds of exceptions?<br />
Here comes the Future Builder Widget into play.



<p>We will be building an application that looks like this,</p>
<p>Without having any issue, 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628347307895/cxf8ZGczwH.png" alt="ListView" /></p>
<p>When having some issue,
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628347440136/GBIhv0hmf.png" alt="issue" /></p>
<p>When having a null response,
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628347614029/ggHfDhasu.png" alt="Null response" /><br /></p>
<p>Let us say we are dealing with i/o operation, So what it suppose to do in that time interval can be defined by using <code>FutureBuilder</code> or <code>StreamBuilder</code>.</p>
<p>Let's see how <code>Future Builder</code> works and How to use it to display our <strong>list</strong> using the <code>ListView</code> Widget.</p>
<p>In our previous article, I have articulated the concept behind parsing a JSON string using <code>Random Person API</code>.<br />
Here, I will be using random User API for this Article.</p>
<p>You can also have a look on <a target="_blank" href="https://randomuser.me/">it</a><br />
<br />
Starting with the <code>main.dart</code> file, I have the following code,</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:jsonstuff/screens/homepage.dart'</span>;

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
  runApp(<span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">MyApp</span><span class="hljs-params">()</span>)</span>;
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">MyApp</span><span class="hljs-params">({Key? key})</span> : <span class="hljs-title">super</span><span class="hljs-params">(key: key)</span></span>;

  <span class="hljs-meta">@override</span>
  <span class="hljs-function">Widget <span class="hljs-title">build</span><span class="hljs-params">(BuildContext context)</span> </span>{
    <span class="hljs-keyword">return</span> MaterialApp(
      title: <span class="hljs-string">'Flutter Demo'</span>,
      themeMode: ThemeMode.system,
      theme: ThemeData(
        <span class="hljs-comment">// primarySwatch: Colors.purple,</span>
        brightness: Brightness.dark,
      ),
      home: <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">MyHomePage</span><span class="hljs-params">()</span>,
    )</span>;
  }
}
</code></pre><p>My <code>homepage.dart</code> file,</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/services.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:jsonstuff/models/person_model.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:jsonstuff/services/network_calls.dart'</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyHomePage</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatefulWidget</span> </span>{
  <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">MyHomePage</span><span class="hljs-params">({Key? key})</span> : <span class="hljs-title">super</span><span class="hljs-params">(key: key)</span></span>;

  <span class="hljs-meta">@override</span>
  <span class="hljs-function">_MyHomePageState <span class="hljs-title">createState</span><span class="hljs-params">()</span> </span>=&gt; _MyHomePageState();
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">_MyHomePageState</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">State</span>&lt;<span class="hljs-title">MyHomePage</span>&gt; </span>{
  <span class="hljs-keyword">final</span> NetworkService personData = NetworkService();
  <span class="hljs-meta">@override</span>
  <span class="hljs-function">Widget <span class="hljs-title">build</span><span class="hljs-params">(BuildContext context)</span> </span>{
    <span class="hljs-keyword">return</span> Scaffold(
      appBar: AppBar(
        title: <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Text</span><span class="hljs-params">(<span class="hljs-string">"Json Testing"</span>)</span>,
        backgroundColor: <span class="hljs-keyword">const</span> <span class="hljs-title">Color</span><span class="hljs-params">(<span class="hljs-number">0xFF6002ee</span>)</span>,
      ),
      body: <span class="hljs-title">SafeArea</span><span class="hljs-params">(
        child: FutureBuilder(
          future: personData.fetchPerson()</span>,
          builder: <span class="hljs-params">(BuildContext context,
              AsyncSnapshot&lt;List&lt;PersonModel&gt;&gt; snapshot)</span> </span>{
            <span class="hljs-keyword">if</span> (snapshot.hasData) {
              <span class="hljs-keyword">return</span> ListView.builder(
                itemCount: snapshot.data!.length,  <span class="hljs-comment">// </span>
                itemBuilder: (BuildContext context, <span class="hljs-keyword">int</span> index) {
                  <span class="hljs-keyword">var</span> currentPerson = snapshot.data![index];
                  <span class="hljs-keyword">return</span> InkWell(
                    onTap: () {
                      <span class="hljs-comment">// Whatever you want to accomplish.</span>
                    },
                    child: Padding(
                      padding: <span class="hljs-keyword">const</span> EdgeInsets.all(<span class="hljs-number">4.0</span>),
                      child: ListTile(
                        leading: CircleAvatar(
                          backgroundImage:
                              NetworkImage(currentPerson.picture.thumbnail),
                        ),
                        title: Text(currentPerson.name.toString()),
                        subtitle: Text(currentPerson.email),
                      ),
                    ),
                  );
                },
              );
            }
            <span class="hljs-keyword">if</span> (snapshot.hasError) {
              <span class="hljs-keyword">return</span> AlertDialog(
                title: <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Text</span><span class="hljs-params">(<span class="hljs-string">"Something Gone wrong :("</span>)</span>,
                actions: [
                  <span class="hljs-title">TextButton</span><span class="hljs-params">(
                    onPressed: ()</span> </span>{
                      SystemNavigator.pop();
                    },
                    child: <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Text</span><span class="hljs-params">(<span class="hljs-string">"Exit"</span>)</span>,
                  )
                ],
              )</span>;
            } <span class="hljs-keyword">else</span> {
              <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">LinearProgressIndicator</span><span class="hljs-params">()</span></span>;
            }
          },
        ),
      ),
    );
  }
}
</code></pre><p>Now we have a rough idea what is the use case of <code>FutureBuilder</code>, <br />
<strong>How it works?</strong><br /></p>
<blockquote>
<p>In <code>FutureBuilder</code> we have a required argument <code>builder</code>, that we need to implement with a Function having a Context and Async Snapshot of your defined class.
<br /></p>
</blockquote>
<p><strong>Do this means that our code will work without having the <code>Future</code> argument?</strong></p>
<blockquote>
<p>Yes, It will work but now we have to provide the data using <code>initstate</code>. Which we will discuss in our future articles.</p>
</blockquote>
<p><strong>What Future argument is doing in the code? What's its role?</strong></p>
<blockquote>
<p>It is performing the asynchronous computation to which this builder is connected.</p>
<p><strong>What is asynchronous?</strong></p>
<blockquote>
<p>Async Simply means occurring at the same time.
And Await means to wait. i.e. to wait for a certain operation to be completed.</p>
</blockquote>
<p>Just for a quick recap :)</p>
</blockquote>
<p>After reading all this you may have a rough idea that Future is creating the snapshots and Builder argument is passing it as an argument in some function.</p>
<p>As we saw here,</p>
<pre><code><span class="hljs-attribute">builder</span>: ((BuildContext context, AsyncSnapshot&lt;List&lt;PersonModel&gt;&gt; snapshot) {
        <span class="hljs-comment">// Body</span>
}
</code></pre><p>So now here comes an important part, 
If you did the flutter installation recently, that means you are probably using Flutter V2.x, which has been migrated to null safety.</p>
<p><strong>What is null safety?</strong></p>
<blockquote>
<p>As we are using this API, there could be cases when the server which serves this API would be down due to some technicality.</p>
<p>Or maybe the link provided by the API is broken, or you may have some typo in the link.</p>
<blockquote>
<p>So for handling these kinds of issues, Dart Provides a mechanism known as null safety.
But you can disable it if you are annoyed by those errors related to null safety in your code.</p>
</blockquote>
</blockquote>
<p>So we just need to define some cases like, If Something goes wrong, show this.<br />
Show loading indicator until the list has been created for your user.</p>
<p>I think we are done with <code>FutureBuilder</code>, Let's move on to ListView Builder.
<br /></p>
<pre><code> <span class="hljs-keyword">if</span> (snapshot.hasData) {
              <span class="hljs-keyword">return</span> ListView.builder(
                itemCount: snapshot.<span class="hljs-keyword">data</span>!.length,  <span class="hljs-comment">// </span>
                itemBuilder: (BuildContext context, int index) {
                  <span class="hljs-keyword">var</span> currentPerson = snapshot.<span class="hljs-keyword">data</span>![index];
                  <span class="hljs-keyword">return</span> InkWell(
                    onTap: () {
                      <span class="hljs-comment">// Whatever you want to accomplish.</span>
                    },
                    child: Padding(
                      padding: <span class="hljs-keyword">const</span> EdgeInsets.all(<span class="hljs-number">4.0</span>),
                      child: ListTile(
                        leading: CircleAvatar(
                          backgroundImage:
                              NetworkImage(currentPerson.picture.thumbnail),
                        ),
                        title: Text(currentPerson.name.toString()),
                        subtitle: Text(currentPerson.email),
                      ),
                    ),
                  );
                },
              );
            }
</code></pre><p>Now I feel that rest of the part will be very easy for you to understand.
<br />
But then also, leme give you a rough idea about <strong>what it is? and how it is working?</strong><br /></p>
<p>This part of our code is saying that,</p>
<p>if the snapshot has data and we haven't encountered any error, then return a <code>listView.Builder</code>.</p>
<p><code>ListView</code> have an argument <code>itemcount</code>. It stores the information, how many lists are supposed to be created.<br />
Therefore we passed <code>snapshot.data!.length</code>.</p>
<p><strong>What's that exclamation mark doing?</strong><br /></p>
<blockquote>
<p>It is just doing a null check. If it is null or not.</p>
<blockquote>
<p>One can specify question mark <code>?</code> too, but then you need to specify, what your program is supposed to do while having the value as <code>null</code>.</p>
</blockquote>
<p>I don't wanna do it right now. It's your homework. try it, It's awesome and good practice.</p>
</blockquote>
<p>Now I feel the rest of the code is self-explanatory, as we have discussed all the definitions above.</p>
<p>But I think you may have noticed that I have used <code>SystemNavigator.pop();</code> inside <code>snapshot.haserror</code> case.<br />
<strong>What is SystemNavigator.pop()?</strong></p>
<blockquote>
<p>Well, it is equivalent, You tapping the back button.</p>
</blockquote>
<hr />
<p>I think we are clear. If you have any queries or suggestions, then please don't hesitate to contact me through <a target="_blank" href="https//t.me/bufferoverflowdotme/">telegram</a> or drop a comment below :)</p>
<p>I'll be happy to hear from you.</p>
<p>Thank you,<br />
Stay home and keep learning<br />
Cya :)</p>
]]></content:encoded></item><item><title><![CDATA[An Interview with no last response.]]></title><description><![CDATA[Hey there,
All my gorgeous readers.
I'm Gulshan Yadav (Which you know already). I want to walk you through my experience of my interview as a Flutter Intern in a Dubai Based Firm. 
Hey but wait from where I got to know about this firm?


One of my fr...]]></description><link>https://gulshan.dev/an-interview-with-no-last-response</link><guid isPermaLink="true">https://gulshan.dev/an-interview-with-no-last-response</guid><category><![CDATA[interview]]></category><category><![CDATA[Flutter]]></category><category><![CDATA[Design]]></category><category><![CDATA[internships]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Fri, 06 Aug 2021 12:56:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1628254164997/HG5ZSrApk.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey there,<br />
All my gorgeous readers.</p>
<p>I'm Gulshan Yadav (Which you know already). I want to walk you through my experience of my interview as a Flutter Intern in a Dubai Based Firm. </p>
<p>Hey but wait from <strong>where I got to know about this firm?</strong></p>
<blockquote>
<blockquote>
<p>One of my friends from Flutter Mumbai shared that this company is looking for a Flutter intern, and they are ready to pay 30k INR to 80k INR depending on one's skills.</p>
</blockquote>
</blockquote>
<p>I was very nervous about that, should I apply for this internship role or not. Basically, I was not confident enough in my existing skill sets.<br /></p>
<p>I raised this doubt that <code>I don't have that kind of skill set may be, and my design skills were not that great</code>, Then one of the members from Flutter Mumbai asked me to believe in myself and go apply for that internship.</p>
<p>Here's what exactly he said to me,</p>
<blockquote>
<p>There's no loss in applying for an internship even if you have not got selected as an intern.<br />
If you don't even apply for an Internship you won't be able to figure, How much you are capable of?<br /></p>
<blockquote>
<p>Basically he was asking to go check your <code>Aukat</code>(ability). <br />
So this is where he motivated me to go start applying for internships.</p>
</blockquote>
</blockquote>
<p>Guess What?<br /></p>
<blockquote>
<p>This note from him actually made me to start applying for internships.<br /></p>
</blockquote>
<p>Firstly I applied for that lucrative looking internship, whose starting compensation starts from 30k INR.</p>
<p>They had a Google Form in which they asked some of the interesting questions, which were laborious for me to answer.</p>
<p>But I did answer those. <br />
Here are the questions and answers I gave,<br /></p>
<p><strong>Please list or describe any achievements and prizes?</strong></p>
<blockquote>
<p>To keep track of my investments, I wanted a wallet application so that I wouldn't have to log into those official applications, again and again, to see how my investments are doing.
Therefore I built an application for myself, which doesn't have any good looks. But it was my first application so I consider it a success because I learned a lot during the process.</p>
</blockquote>
<p><strong>If you have ever started a business, led an organization, or dedicated yourself to a major project, please describe the organization or project you started, your reason for starting it, and your role?</strong></p>
<blockquote>
<p>I started Buffer Overflow as a hobby project and spent some time learning and Building it.
I wanted to learn the end-to-end process of development and maintenance and also learned about System Design.</p>
</blockquote>
<p><strong>Tell us about a risk youʼve taken or a challenge you've faced. Tell us whether you failed or succeeded, how you behaved, and how you think this reflects your character.</strong></p>
<blockquote>
<p>I began investing early and learned how to invest in cryptocurrencies and other technological fields.
Even though I made a few poor choices, I ultimately gained valuable knowledge, which I consider more valuable than the returns I expected from my investments.</p>
<p>Since I haven't blown up all of my money on cryptocurrencies, this shows I know how to take calculated risks.</p>
</blockquote>
<p><strong>What do you want to accomplish in the next 10 years?</strong></p>
<blockquote>
<p>I want to become financially free, where I don't have to work for money. But rather money will work for me. And for achieving that goal, I am willing to give what it takes. 
I am learning every day, no matter how small that learning is, but I want that compounding effect in my life.</p>
</blockquote>
<p><strong>Tell us one thing about the world that you strongly believe is true, but that most people think is not true. If this belief shapes the way you live, tell us how.</strong></p>
<blockquote>
<p>I have a theory related to the ongoing Sars-Cov-2 virus. 
I recently came across some research about Permafrost Viruses. Permafrost stands for the soil that is bound by ice or the deep layers of Arctic soil. Research has shown some viable viruses in the permafrost in the Arctic region. 
Therefore, since we have no idea what the concrete source of COVID-19 is. Nonetheless, arctic cases have not been reported. 
It's just an assumption of mine when I came across this research. I'm not backing or citing any nation. But Since Everyone will disagree, I wanted to share my theory.</p>
</blockquote>
<p><strong>What questions do you spend the most time thinking about?</strong></p>
<blockquote>
<p>What will help me grow in my career? What is my passion?</p>
</blockquote>
<p><strong>Tell us why should we hire you? In 6 words</strong></p>
<blockquote>
<blockquote>
<p>I'm an Ambitious Flutter Developer.</p>
</blockquote>
</blockquote>
<p>So there were my answers to the questions asked in the Google Form.<br />
Then After this, I applied to many Institutions, through LinkedIn as a Flutter Intern.
But I was selected in none.</p>
<p>It was a Stressful experience, so I later reached out to the person who motivated me to start applying for internships. He simply said, <code>Don't think much, maybe they got the maximum number of interns or you don't have the right skills, So keep polishing your skills and be patient with the results.</code></p>
<p>So I kept working and learning.<br />
And later on, I got a message from the CEO of the Dubai-based company firm I applied for. </p>
<p>The moment he reached out to me and asked about my experience and my skills.<br />
I was cheerful and happy to share my experience and skills with him.
He asked me to choose between an interview test or showcasing a working application of mine.</p>
<p>So I opted for showcasing my application.</p>
<p>He asked me to wait until he asks his developer to check if I'm eligible for being a Flutter Intern in his company or not.</p>
<p>4Hrs passed, There was no response from his side. All those happiness has been over. And I was downhearted, Thinking that Maybe I'm not good enough to be an intern.<br /></p>
<p>But at Next day, I got a response from his side asking,<br /></p>
<pre><code>What compensation would you expect <span class="hljs-keyword">for</span> an internship?

how many hours per day would you be available?

How many days a week can you <span class="hljs-keyword">work</span>?

Thanks!
</code></pre><p>I responded that I would like to work for 5 Hrs per day and 5 days a week.<br /></p>
<p>Then he asked me how much compensation I anticipate?</p>
<blockquote>
<p>As the internship compensation starts from 30K - 80K INR as stated in the ads, I replied that I would expect around 30K INR.</p>
</blockquote>
<p>He said Thanks! and left the conversation.<br /><br /></p>
<p>But later, when I opened YT for checking that what should be my answer to that question?</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/WChxbBSlWnQ">https://youtu.be/WChxbBSlWnQ</a></div>
<p>After watching this video, I was like, <code>What the f*ck I did</code>.<br /></p>
<p>The person in the video says that this question is asked to generally eliminate you.</p>
<p>One should never say exact numbers in an interview question asking for expected salary or compensation.<br /><br /></p>
<p>I was anxious, If I will be eliminated.</p>
<p>After 2 Days, The CEO of that firm said,</p>
<pre><code>The design <span class="hljs-keyword">of</span> the <span class="hljs-keyword">login</span> screen <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> good enough.

We would <span class="hljs-keyword">like</span> <span class="hljs-keyword">to</span> <span class="hljs-keyword">check</span> the design <span class="hljs-keyword">of</span> the core part <span class="hljs-keyword">of</span> your application, 
So can you bypass the <span class="hljs-keyword">login</span> screen <span class="hljs-keyword">for</span> now?
</code></pre><p>I generously said <code>yes</code> And bypassed the login screen and asked him to check the design.<br /><br /></p>
<p>God knows If he even gave me a moment to check the design or maybe he asked me this question to state that I have been eliminated.<br /><br /></p>
<p>Because if he really had any software DEV with him, he would have easily bypassed the login screen by simply doing some changes in the code to check how my design looks from the inside.<br /></p>
<p>1 week passed with no response from his side and with a ton of emails, stating that <code>sorry you have been rejected from this and this company</code>. Keep working hard Bla Bla Bla...<br /></p>
<p>I didn't have any guilt or sadness due to those emails stating that I'm not good enough, Because I already know that I'm not good enough.<br /><br /></p>
<p>The only thing which aching me was the indirect rejection.<br /></p>
<p>After this happening or rejection, I learned and experienced something new.</p>
<p>I felt how terrible it feels falling from the fake highs.</p>
<p>I'm speaking about all those praising and lies.
<code>Oh my gosh, The design is very good, You are talented, You are this and this...</code></p>
<p>I came to know, that If you feel that your design is not good enough, Then <code>yes</code> It is not Good Enough.<br />
It needs more work to stand out.<br /></p>
<p>From this, I learned, That Never ever trust your Friends and Family regarding how your design looks like.
Because they don't have any idea about the design right?</p>
<p>And They also don't want to hurt you stating that you are not good enough. </p>
<p>So How can we find if our design needs some work? I mean, we are not god right, to know if this is the greatest design ever made or not.</p>
<p>I joined some courses to learn how to design better.
<br /><br />
I got to know about one really good question to ask friends and family members to get their valuable correct response, not the fake one.</p>
<p>It is,</p>
<pre><code>Please let me know <span class="hljs-keyword">if</span> you have any idea about the design of <span class="hljs-keyword">this</span> application?

Let say you are the designer of <span class="hljs-keyword">this</span> application, 
what would you <span class="hljs-keyword">do</span> to make it better?
</code></pre><p>And That's how one can easily find out if the design is good enough or not with some valuable suggestions.</p>
<p>To those of you who want to know what How my application looks like, which I shared with that CEO, </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628252117339/lYkZEwC28.gif" alt="app" /></p>
<p>After bypassing authentication.</p>
<p>I know it's too basic and It doesn't look great. And Probably showcasing this design for 30K INR doesn't make sense.<br /></p>
<p>So I'm working now on my designs and learning daily.</p>
<p>Here's what I'm working on right now,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628252350990/5laMRd4yL.png" alt="Portfolio" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628252393695/TUN79pPza.png" alt="Portfolio design 2" /></p>
<p>What are those?
<br />
These are the portfolio ideas, and I'm still figuring them out. How to make them better or How to design better.<br />
I even learned how to create logos, how to use Inkscape and other software.
<br />
And I'm looking forward to learning more so that I can be a better designer and no one will hesitate in paying 30K or more money for my work.<br /></p>
<hr />
<p>Thanks for reading :)<br />
Be optimistic and keep learning.</p>
]]></content:encoded></item><item><title><![CDATA[How to Generate Dart code for Parsing JSON in Flutter?]]></title><description><![CDATA[Let's check how to do automated JSON Serialization.
Here we will be using random person api for getting the JSON string.
How's it looks like?
Have a look,
[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@a...]]></description><link>https://gulshan.dev/flutter-json-serialization-generated</link><guid isPermaLink="true">https://gulshan.dev/flutter-json-serialization-generated</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Android]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[Windows]]></category><category><![CDATA[iOS]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Thu, 05 Aug 2021 12:33:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1628166165056/wzz9TZonES.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="lets-check-how-to-do-automated-json-serialization">Let's check how to do automated JSON Serialization.</h3>
<p>Here we will be using <a target="_blank" href="https://randomuser.me/api/">random person api</a> for getting the JSON string.<br />
How's it looks like?<br /></p>
<p>Have a look,</p>
<pre><code>[
  {
    <span class="hljs-attr">"id"</span>: <span class="hljs-number">1</span>,
    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Leanne Graham"</span>,
    <span class="hljs-attr">"username"</span>: <span class="hljs-string">"Bret"</span>,
    <span class="hljs-attr">"email"</span>: <span class="hljs-string">"Sincere@april.biz"</span>,
    <span class="hljs-attr">"address"</span>: {
      <span class="hljs-attr">"street"</span>: <span class="hljs-string">"Kulas Light"</span>,
      <span class="hljs-attr">"suite"</span>: <span class="hljs-string">"Apt. 556"</span>,
      <span class="hljs-attr">"city"</span>: <span class="hljs-string">"Gwenborough"</span>,
      <span class="hljs-attr">"zipcode"</span>: <span class="hljs-string">"92998-3874"</span>,
      <span class="hljs-attr">"geo"</span>: {
        <span class="hljs-attr">"lat"</span>: <span class="hljs-string">"-37.3159"</span>,
        <span class="hljs-attr">"lng"</span>: <span class="hljs-string">"81.1496"</span>
      }
    },
    <span class="hljs-attr">"phone"</span>: <span class="hljs-string">"1-770-736-8031 x56442"</span>,
    <span class="hljs-attr">"website"</span>: <span class="hljs-string">"hildegard.org"</span>,
    <span class="hljs-attr">"company"</span>: {
      <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Romaguera-Crona"</span>,
      <span class="hljs-attr">"catchPhrase"</span>: <span class="hljs-string">"Multi-layered client-server neural-net"</span>,
      <span class="hljs-attr">"bs"</span>: <span class="hljs-string">"harness real-time e-markets"</span>
    }
  }
]
</code></pre><p>First of all, it seems a bit complex right?<br />
But it's not.<br /></p>
<p>Let's say my flutter application need the username and email of the person, that's very easy right?<br />
We can use our manual JSON serialization to get the username and email of the person.<br />
But what if we need the address of the person?<br />
We can also use our manual JSON serialization to get the address of the person.<br />
But it will make our code messy and we don't want that.<br /></p>
<h4 id="here-comes-the-power-of-json-generated-serialization-in-flutter-to-the-rescue">Here comes the power of JSON Generated-Serialization in flutter to the rescue.</h4>
<p>Please refer to my previous <a target="_blank" href="https://blog.bufferoverflow.me/flutter-json-serialization-manual-serialization">article</a>. This article is in continuation with <a target="_blank" href="https://blog.bufferoverflow.me/flutter-json-serialization-manual-serialization">that</a> article.</p>
<h2 id="lets-do-it">Let's Do it.</h2>
<h3 id="step-1">Step 1:</h3>
<p><strong>Add Dependencies in pubsec.yaml file</strong><br /></p>
<blockquote>
<blockquote>
<p>Add <code>JSON_annotation: ^4.1.0</code> as dependencies.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627559911216/WR71B8CVZ.png" alt="JSON_annotation" /></p>
</blockquote>
<h3 id="step-2">Step 2:</h3>
<p><strong>Add <code>build_runner: ^2.0.6</code> under dev dependencies.<br /></strong></p>
<p><strong>Add <code>JSON_serializable: ^5.0.0</code> under dependencies.</strong></p>
<pre><code><span class="hljs-attribute">build_runner</span>: ^<span class="hljs-number">2</span>.<span class="hljs-number">0</span>.<span class="hljs-number">6</span>
<span class="hljs-attribute">JSON_serializable</span>: ^<span class="hljs-number">5</span>.<span class="hljs-number">0</span>.<span class="hljs-number">0</span>
</code></pre><blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627560718914/FY-9h2Xyr.png" alt="Dev Dependencies" /></p>
</blockquote>
<p>Here's how my dependencies and dev dependencies look like,</p>
<blockquote>
<blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627560783476/KQ7zuEeuq.png" alt="Pubsec.yaml" /></p>
</blockquote>
</blockquote>
<h3 id="step-3">Step 3:</h3>
<p><em>Create a folder named <code>model</code> inside the <code>lib</code> folder.</em><br />
It's not necessary but it's good to keep things organized.
<br /></p>
<h3 id="step-4">Step 4:</h3>
<p><em>Create a file named <code>person_model.dart</code> inside the <code>model</code> folder.</em><br />
Here we will be using the <code>JSON_serializable</code> package to convert the JSON string into a <code>Person</code> object.
<br /></p>
<p><br /></p>
<p><strong>import the <code>JSON_serializable</code> package.</strong><br /></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:JSON_annotation/JSON_annotation.dart'</span>;
</code></pre><p><strong>Create a part of our file.</strong></p>
<pre><code><span class="hljs-keyword">part</span> <span class="hljs-string">'your_filename.g.dart'</span>;
</code></pre><p>This allows the <code>User</code> class to access private members in
the generated file. The value for this is *.g.dart, where
the star denotes the source file name.
<br /></p>
<h3 id="step-5">Step 5:</h3>
<p><strong>Now add the following code.</strong><br /></p>
<pre><code><span class="hljs-meta">@JsonSerializable()</span>
</code></pre><p>Hey but what is this?<br /></p>
<blockquote>
<p>Basicaly, this annotation tells the Dart compiler to generate a class that can be serialized to JSON.</p>
</blockquote>
<p><br /></p>
<h3 id="step-6">Step 6:</h3>
<p><strong>Create a class named <code>PersonModel</code>.</strong><br />
or what ever you want.<br />
It's not necessary but it's good to keep things organized according to the JSON string.</p>
<p><br /></p>
<p>Now let's look back to our JSON string.</p>
<pre><code>[
  {
    <span class="hljs-attr">"id"</span>: <span class="hljs-number">1</span>,
    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Leanne Graham"</span>,
    <span class="hljs-attr">"username"</span>: <span class="hljs-string">"Bret"</span>,
    <span class="hljs-attr">"email"</span>: <span class="hljs-string">"Sincere@april.biz"</span>,
    <span class="hljs-attr">"address"</span>: {
      <span class="hljs-attr">"street"</span>: <span class="hljs-string">"Kulas Light"</span>,
      <span class="hljs-attr">"suite"</span>: <span class="hljs-string">"Apt. 556"</span>,
      <span class="hljs-attr">"city"</span>: <span class="hljs-string">"Gwenborough"</span>,
      <span class="hljs-attr">"zipcode"</span>: <span class="hljs-string">"92998-3874"</span>,
      <span class="hljs-attr">"geo"</span>: {
        <span class="hljs-attr">"lat"</span>: <span class="hljs-string">"-37.3159"</span>,
        <span class="hljs-attr">"lng"</span>: <span class="hljs-string">"81.1496"</span>
      }
    },
    <span class="hljs-attr">"phone"</span>: <span class="hljs-string">"1-770-736-8031 x56442"</span>,
    <span class="hljs-attr">"website"</span>: <span class="hljs-string">"hildegard.org"</span>,
    <span class="hljs-attr">"company"</span>: {
      <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Romaguera-Crona"</span>,
      <span class="hljs-attr">"catchPhrase"</span>: <span class="hljs-string">"Multi-layered client-server neural-net"</span>,
      <span class="hljs-attr">"bs"</span>: <span class="hljs-string">"harness real-time e-markets"</span>
    }
  }
]
</code></pre><p>Let's first decide what kind of information we need from the JSON string.</p>
<p>For this example, we need the name, username, email, and address.</p>
<p>Looking at the JSON string, we can see that the address is a JSON object.<br />
Hey but what is a json object?<br /></p>
<blockquote>
<p>A json object is a json array with a single element.<br />
for example:<br /></p>
</blockquote>
<pre><code>[
  {
    <span class="hljs-attr">"street"</span>: <span class="hljs-string">"Kulas Light"</span>,
    <span class="hljs-attr">"suite"</span>: <span class="hljs-string">"Apt. 556"</span>,
    <span class="hljs-attr">"city"</span>: <span class="hljs-string">"Gwenborough"</span>,
    <span class="hljs-attr">"zipcode"</span>: <span class="hljs-string">"92998-3874"</span>,
    <span class="hljs-attr">"geo"</span>: {
      <span class="hljs-attr">"lat"</span>: <span class="hljs-string">"-37.3159"</span>,
      <span class="hljs-attr">"lng"</span>: <span class="hljs-string">"81.1496"</span>
    }
  }
]
</code></pre><p>This is a JSON array with a single element.<br />
And <strong>what is a JSON array?</strong><br /></p>
<blockquote>
<p>A JSON array is a JSON object with an array as its value.<br /></p>
</blockquote>
<p>I think we are clear now.<br /></p>
<blockquote>
<p>If not then don't worry, you will get it soon, when you do the code.</p>
</blockquote>
<p><br /></p>
<h3 id="step-7">Step 7:</h3>
<p>We can declare the name, username, and email as strings since they do not contain any nested JSON objects.</p>
<p>here's how our code looks like,</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:json_annotation/json_annotation.dart'</span>;

<span class="hljs-keyword">part</span> <span class="hljs-string">'person_model.g.dart'</span>;

<span class="hljs-meta">@JsonSerializable</span>()
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PersonModel</span> </span>{
  <span class="hljs-built_in">String</span> name;
  <span class="hljs-built_in">String</span> username;
  <span class="hljs-built_in">String</span> email;
}
</code></pre><p><strong>But what about the address?</strong><br />
It's a JSON object with nested JSON objects.
Declare a new class named <code>AddressModel</code>.
This class will be used to store the address.</p>
<p>Create a new file named <code>address_model.dart</code>,
inside our model folder.</p>
<p>And perform the same steps as we did for <code>PersonModel</code>.</p>
<p>here's how our code looks like in the <code>address_model.dart</code> file,</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:json_annotation/json_annotation.dart'</span>;

<span class="hljs-keyword">part</span> <span class="hljs-string">'address_model.g.dart'</span>;

<span class="hljs-meta">@JsonSerializable</span>()
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AddressModel</span> </span>{
  <span class="hljs-built_in">String</span> street;
  <span class="hljs-built_in">String</span> suite;
  <span class="hljs-built_in">String</span> city;
  <span class="hljs-built_in">String</span> zipcode;
  <span class="hljs-comment">// GeoModel geo; // Your homework :)</span>

}
</code></pre><p>We are not done yet btw.</p>
<p>Both of our programs are incorrect.<br />
Why?<br /></p>
<blockquote>
<p>because we haven't initialized our constructors.</p>
</blockquote>
<p>How do we initialize our constructors? Or how do we even define a constructor?</p>
<p>But first of all, <strong>what is a constructor?</strong><br /></p>
<blockquote>
<p>A constructor is a function that is called when an object is created.</p>
<blockquote>
<p>You may refer to my previous article <a target="_blank" href="https://bufferoverflow.me/flutter-a-short-intro-to-oop">#Flutter: A short intro to OOP</a> for more details.</p>
</blockquote>
</blockquote>
<p>Let's create a constructor for our <code>PersonModel</code> class first.</p>
<p>Add this code inside the <code>PersonModel</code> class,</p>
<pre><code>PersonModel(<span class="hljs-keyword">this</span>.name, <span class="hljs-keyword">this</span>.username, <span class="hljs-keyword">this</span>.email);
</code></pre><p>And do the same for the <code>AddressModel</code> class.</p>
<p>Add this code inside the <code>AddressModel</code> class,</p>
<pre><code>AddressModel(<span class="hljs-keyword">this</span>.street, <span class="hljs-keyword">this</span>.suite, <span class="hljs-keyword">this</span>.city, <span class="hljs-keyword">this</span>.zipcode);
</code></pre><p>Hey Gulshan, what is this <code>this.</code>?</p>
<blockquote>
<p>It's a reference to the current object.</p>
<blockquote>
<p>It is used to access the properties of the current object.
i.e. <code>this.name</code> is equivalent to <code>name</code>.
I think now it's clear.</p>
</blockquote>
</blockquote>
<p>Let's Jump back into our <code>person_model.dart</code> file.<br /></p>
<p>Declare a new variable named <code>address</code> of type <code>AddressModel</code>. And do the changes in our constructor accordingly.</p>
<p>Our <code>PersonModel</code> would now look like this,</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PersonModel</span> </span>{
  String name;
  String username;
  String email;
  AddressModel address;
  PersonModel(<span class="hljs-keyword">this</span>.name, <span class="hljs-keyword">this</span>.username, <span class="hljs-keyword">this</span>.email, <span class="hljs-keyword">this</span>.address);
}
</code></pre><p>Add the following code inside our <code>PersonModel</code> class,</p>
<pre><code><span class="hljs-keyword">factory</span> PersonModel.fromJson(<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; json) =&gt; _$PersonModelFromJson(json);

<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; toJson() =&gt; _$PersonModelToJson(<span class="hljs-keyword">this</span>);
</code></pre><p>And add the following code inside our <code>AddressModel</code> class,</p>
<pre><code>
<span class="hljs-meta">@override</span>
<span class="hljs-built_in">String</span> toString() =&gt; <span class="hljs-string">'<span class="hljs-subst">${street}</span> <span class="hljs-subst">${suite}</span> <span class="hljs-subst">${city}</span> <span class="hljs-subst">${zipcode}</span>'</span>;

<span class="hljs-keyword">factory</span> PersonModel.fromJson(<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; json) =&gt; _$AddressModelFromJson(json);

<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; toJson() =&gt; _$AddressModelToJson(<span class="hljs-keyword">this</span>);
</code></pre><p><strong>What are those lines of code?</strong></p>
<p>Let's break them down.<br />
<strong>What is a factory?</strong><br /></p>
<blockquote>
<p>A factory is a function that creates an object.</p>
</blockquote>
<p>for now, this much info is enough.
You may research more about factories on the web.</p>
<p><strong>what is _$PersonModelFromJson?</strong><br /></p>
<blockquote>
<p>It's a private function.<br />
It's used to create an object from a json object.</p>
</blockquote>
<p><strong>Why am I seeing an error?</strong><br /></p>
<blockquote>
<p>It's because the files are not generated yet.</p>
</blockquote>
<p>And at the end that overrides part inside our <code>AddressModel</code> class,
is used to just return the string representation of the objects.
In our case, <code>street</code>, <code>suite</code>, <code>city</code>, <code>zipcode</code>.</p>
<p>Here's how our code looks like,</p>
<p>person_model.dart</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:json_annotation/json_annotation.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:your_appname/model/address_model.dart'</span>;

<span class="hljs-keyword">part</span> <span class="hljs-string">'person_model.g.dart'</span>;

<span class="hljs-meta">@JsonSerializable</span>()
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PersonModel</span> </span>{
  <span class="hljs-built_in">String</span> name;
  <span class="hljs-built_in">String</span> username;
  <span class="hljs-built_in">String</span> email;
  AddressModel address;
  PersonModel(<span class="hljs-keyword">this</span>.name, <span class="hljs-keyword">this</span>.username, <span class="hljs-keyword">this</span>.email, <span class="hljs-keyword">this</span>.address);

  <span class="hljs-keyword">factory</span> PersonModel.fromJson(<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; json) =&gt; _$PersonModelFromJson(json);
  <span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; toJson() =&gt; _$PersonModelToJson(<span class="hljs-keyword">this</span>);

}
</code></pre><p>address_model.dart</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:json_annotation/json_annotation.dart'</span>;

<span class="hljs-keyword">part</span> <span class="hljs-string">'address_model.g.dart'</span>;

<span class="hljs-meta">@JsonSerializable</span>()
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AddressModel</span> </span>{
  <span class="hljs-built_in">String</span> street;
  <span class="hljs-built_in">String</span> suite;
  <span class="hljs-built_in">String</span> city;
  <span class="hljs-built_in">String</span> zipcode;
  <span class="hljs-comment">// GeoModel geo; // Your homework :)</span>

  AddressModel(<span class="hljs-keyword">this</span>.street, <span class="hljs-keyword">this</span>.suite, <span class="hljs-keyword">this</span>.city, <span class="hljs-keyword">this</span>.zipcode);
  <span class="hljs-meta">@override</span>
  <span class="hljs-built_in">String</span> toString() =&gt; <span class="hljs-string">'<span class="hljs-subst">${street}</span> <span class="hljs-subst">${suite}</span> <span class="hljs-subst">${city}</span> <span class="hljs-subst">${zipcode}</span>'</span>;


  <span class="hljs-keyword">factory</span> AddressModel.fromJson(<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; json) =&gt; _$AddressModelFromJson(json);
  <span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; toJson() =&gt; _$AddressModelToJson(<span class="hljs-keyword">this</span>);
}
</code></pre><p>Let's now generate the files.</p>
<p>Open the terminal and type,</p>
<pre><code>flutter <span class="hljs-keyword">pub</span> run build_runner build
</code></pre><p>And wait for the files to be generated.</p>
<p>Here, you can look that the files are generated and all our errors are gone.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628165378396/S9VrVF0se.png" alt="File Structure" /></p>
<p>Ahh, if you are thinking that why my files appear red?<br />
It's git stuff. It just means that the files are not committed yet.
<br />
And the grey files are ignored files.</p>
<p>let's have a look inside our generated files.<br />
Hey look,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1628165608598/g2qB6LvLS.png" alt="generated file" /></p>
<p>That's what we wrote in our <a target="_blank" href="https://bufferoverflow.me/flutter-json-serialization-manual-serialization">manual Serialization</a> code.</p>
<p>The only thing we are left with is to use this parsed data in our application.</p>
<p>That can be achieved using <code>FutureBuilder</code>.
Currently, this article became a little bit more complicated, I feel.</p>
<p>So I will be posting about FutureBuilder in a future article.</p>
<hr />
<p>If you are frustrated about how these classes are getting the JSON string, 
then please refer to my previous article on <a target="_blank" href="https://bufferoverflow.me/flutter-json-serialization-manual-serialization">manual Serialization</a>.</p>
<hr />
<p>Until then you can refer to <a target="_blank" href="https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html">Flutter docs</a> for more details.<br />
Or you can also wait for me to write a blog post about this.</p>
<p>Maybe when you are done with this article, I already posted an article about the FutureBuilder.</p>
<p>So have a look at my <a target="_blank" href="https://blog.bufferoverflow.me">site</a>.</p>
<p>Thanks for reading.<br />
Happy Coding :)</p>
]]></content:encoded></item><item><title><![CDATA[Basic JSON String Parsing in Flutter.]]></title><description><![CDATA[When developing network-connected apps, it is most likely that it will need to use some good old JSON at some point. It is hard to imagine a mobile app that doesn't need to communicate with a web server or store structured data.

The guide looks at h...]]></description><link>https://gulshan.dev/flutter-json-serialization-manual-serialization</link><guid isPermaLink="true">https://gulshan.dev/flutter-json-serialization-manual-serialization</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Flutter Widgets]]></category><category><![CDATA[android app development]]></category><category><![CDATA[ios app development]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Thu, 29 Jul 2021 13:27:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1627564860701/8XZLao0hB.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>When developing network-connected apps, it is most likely that it will need to use some good old JSON at some point. It is hard to imagine a mobile app that doesn't need to communicate with a web server or store structured data.</p>
<blockquote>
<p>The guide looks at how to use JSON with Flutter. It explains how to select the right JSON solution for each scenario and why.</p>
</blockquote>
</blockquote>
<p>If you are here, for learning how to do JSON Serialization in Flutter, you are at the right place. I will be walking you through all the concepts related to JSON.</p>
<p>Excited to learn??</p>
<p>Let's Get started...</p>
<hr />
<p>We can perform JSON serialization manually or Automated Serialization using Code Generation in Flutter.</p>
<h3 id="hey-but-what-is-json">Hey but, what is JSON??</h3>
<p><strong>If you are a beginner, you will be wondering what the heck is JSON first of all?</strong></p>
<blockquote>
<blockquote>
<p>JSON stands for JavaScript Object Notation.
This doesn't mean you have to learn JavaScript or something, JSON is just a text-based format for representing data. It is fully independent of JavaScript.</p>
</blockquote>
</blockquote>
<p><strong>You may ask if it is used for representing data then, Why is JavaScript in the Full-form?</strong></p>
<blockquote>
<blockquote>
<p>Because it is using JavaScript object Syntax.</p>
</blockquote>
</blockquote>
<p><strong>JSON is used for transmitting data in web applications.</strong></p>
<p>For Example, You want some data from the server or you want to send some data on the server, here Json comes into play to help us.</p>
<p><strong>You may ask, how does JSON look like?</strong></p>
<pre><code>{
    <span class="hljs-attr">"College_Name"</span>: <span class="hljs-string">"No Name"</span>,
    <span class="hljs-attr">"place"</span>: <span class="hljs-string">"SomeWhere on planet Earth"</span>,
    <span class="hljs-attr">"formed"</span>: <span class="hljs-number">2052</span>,
    <span class="hljs-attr">"active"</span> : <span class="hljs-literal">true</span>,
    <span class="hljs-attr">"students"</span>:[
        {
            <span class="hljs-attr">"name"</span>: <span class="hljs-string">"name"</span>: {
              <span class="hljs-attr">"title"</span>: <span class="hljs-string">"Mr"</span>,
              <span class="hljs-attr">"first"</span>: <span class="hljs-string">"Gulshan"</span>,
              <span class="hljs-attr">"last"</span>: <span class="hljs-string">"Yadav"</span>
                },
            <span class="hljs-attr">"roll_no"</span>: <span class="hljs-number">32</span>,
            <span class="hljs-attr">"species"</span> : <span class="hljs-string">"human"</span>
        },
        {
            <span class="hljs-attr">"name"</span>: {
              <span class="hljs-attr">"title"</span>: <span class="hljs-string">"Mr"</span>,
              <span class="hljs-attr">"first"</span>: <span class="hljs-string">"Rahul"</span>,
              <span class="hljs-attr">"last"</span>: <span class="hljs-string">"Yadav"</span>
            },
            <span class="hljs-attr">"roll_no"</span>: <span class="hljs-number">69</span>,
            <span class="hljs-attr">"species"</span>: <span class="hljs-string">"Martian"</span>
        }
    ]
}
</code></pre><p>Now let's see how to manually parse this JSON string.
Let's say we have a program which shows the information about the students.
For starters, it shows some information about the college or school.
<br />
So my first step will be loading this JSON output from the source.
<br />
This could be anything, you can source your JSON file from the assets in the code or you may use any external API for that.</p>
<p>In this article, we will be learning how to do network calls to get the JSON data and how to parse it properly.<br /></p>
<p><strong>Step 1:</strong></p>
<pre><code><span class="hljs-keyword">import</span> ‘dart:convert’;
</code></pre><p>We need dart:convert so that we can use the <code>JsonDecode</code> function which will help us to map all our JSON into a variable.<br /></p>
<p><strong>Step 2:</strong></p>
<p>Now create a variable of type <code>const</code> to store the address from where our program will fetch the JSON string.</p>
<pre><code><span class="hljs-keyword">const</span>  myJsonSourceUrl = “https:<span class="hljs-comment">//mysourceofJson.com”; </span>
<span class="hljs-comment">// Don’t use it, I wrote it for explaining to you.</span>
</code></pre><p><strong>Step 3:</strong>
Create a class of any name of your choice.<br /></p>
<p>For Example: </p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NetworkService</span></span>{

}
</code></pre><p><strong>Step 4:</strong>
Declare a <code>async</code> function of type <code>Future</code> of any Name of your choice.
<br /></p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NetworkService</span></span>{
Future fetchMyApi() <span class="hljs-keyword">async</span> {
    http.Response response = <span class="hljs-keyword">await</span> http.<span class="hljs-keyword">get</span>(<span class="hljs-built_in">Uri</span>.parse(myJsonSourceUrl));
       }
}
</code></pre><p><br />
You may get an error message in your debug console, saying "hey man, idk what is this HTTP. Rectify the mistake."</p>
<p>So to fix it, </p>
<p>head over to your <code>pubsec.yaml</code> file and add <code>http: ^0.13.3</code> under the dependencies section.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627547897985/i3Rpr5d5u.png" alt="Dependencies" /></p>
<p>And then run <code>flutter pub get</code> in your terminal.<br />
But wait this will not fix your error.</p>
<p>import http inside your program like this,</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:http/http.dart'</span> <span class="hljs-keyword">as</span> http;
</code></pre><p>now you may see that your error got fixed.</p>
<blockquote>
<blockquote>
<p>Kudos!</p>
<p>If still your error not got fixed then re-run the command <code>flutter pub get</code> in your terminal and also check the <code>pubsec.lock</code> file to check if your dependencies or loaded or not.</p>
<p>My <code>pubsec.lock</code> file,</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627548227139/EW5HPtb3f.png" alt="image.png" /></p>
<blockquote>
<p>If still, you are facing any issue, then head over to our <a target="_blank" href="https://t.me/bufferoverflowdotme">Telegram channel</a> and throw some questions, I'll be happy to help you.</p>
</blockquote>
</blockquote>
<p><strong>Hey but what does that <code>Future</code> data type used for, and what it is?</strong></p>
<blockquote>
<p>It is an object that represents delayed computation.</p>
<blockquote>
<p>A <code>Future</code> is used to represent a potential value or error,
that will be available at some time in the future.</p>
</blockquote>
<p>There's more but, right now this much information is enough to get our job done :)</p>
</blockquote>
<p><strong>What are those <code>await</code> and <code>async</code>?</strong></p>
<blockquote>
<blockquote>
<p>"Async Simply means occurring at the same time.
And Await means to wait. i.e. to wait for a certain operation to over."</p>
</blockquote>
</blockquote>
<p><br />
Here our program is fetching the JSON string from the source, And then storing it inside a variable of type <code>http.Response</code>.
<br /></p>
<p><strong>Step 5:</strong>
<em>Check if the response is successful or not?</em></p>
<p>How do we do that?</p>
<blockquote>
<blockquote>
<p>It's simple but first of all, we need to know what is a successful response?<br />
A successful response is a response with a status code of 200.<br />
And a failed response is a response with a status code of anything other than 200.<br /></p>
</blockquote>
</blockquote>
<p>So now we have to just check if the status code is 200 or not.<br />
we can use our simple if-else loop or try-catch method.
<br />
For the sake of simplicity, we will be sticking with the if-else loop.</p>
<h5 id="but-how-to-check-the-status-codelessbrgreater">But how to check the status code?<br /></h5>
<blockquote>
<blockquote>
<p>Since we declared our variable of type http.Response, we can access the status code by using <code>response.statusCode</code>.</p>
</blockquote>
</blockquote>
<p>here's how our if-else loop will look like,<br /></p>
<pre><code> <span class="hljs-keyword">if</span> (response.statusCode == <span class="hljs-number">200</span>) {
      <span class="hljs-built_in">Map</span> CollegeData = jsonDecode(response.body);
      <span class="hljs-comment">// debugPrint(CollegeData.toString());</span>
      <span class="hljs-built_in">List</span>&lt;<span class="hljs-built_in">dynamic</span>&gt; College = CollegeData[<span class="hljs-string">"students"</span>];
      <span class="hljs-keyword">return</span> College.map((json) =&gt; students.fromJson(json)).toList();
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">throw</span> Exception(<span class="hljs-string">"Something gone wrong, <span class="hljs-subst">${response.statusCode}</span>"</span>);
    }
</code></pre><p>Let's break it down,<br /><br />
As we know the first line of our code checks if the status code is 200 or not.
if it is 200 then it will execute the next line of code.<br />
<br />
i.e. <code>Map myData = jsonDecode(response.body);</code><br />
<br />
This maps the json string into a variable of type <code>Map</code>.<br />
<br /></p>
<p>What is a <code>Map</code>?</p>
<blockquote>
<p>A <code>Map</code> is a collection of key-value pairs.<br /></p>
<blockquote>
<p>It is similar to a <code>dictionary</code> in python.<br />
It is also similar to a <code>hashmap</code> in java.<br />
It is also similar to a <code>hashtable</code> in c++.<br /></p>
</blockquote>
</blockquote>
<p><br />
Now we have to access the values of the <code>Map</code>.
And we can do that by using the <code>[]</code> operator.
<br />
<br /></p>
<p><br />
Here we are storing the value of the <code>students</code> key into a variable of type <code>List&lt;dynamic&gt;</code>.<br />
Then we are mapping the values of the <code>List&lt;dynamic&gt;</code> into a <code>List&lt;Student&gt;</code>.<br />
<br /></p>
<p><code>student_network_service.dart</code></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'dart:convert'</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">'package:http/http.dart'</span> <span class="hljs-keyword">as</span> http;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:network_request/model/student.dart'</span>;

<span class="hljs-keyword">const</span> <span class="hljs-built_in">String</span> randomPersonURL = <span class="hljs-string">"https://linktoapi.com"</span>; <span class="hljs-comment">// Just an example.</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentNetworkService</span> </span>{
  Future&lt;<span class="hljs-built_in">List</span>&lt;Students&gt;&gt; fetchStudents(<span class="hljs-built_in">int</span> amount) <span class="hljs-keyword">async</span> {
    http.Response response = <span class="hljs-keyword">await</span> http.<span class="hljs-keyword">get</span>(<span class="hljs-string">"<span class="hljs-subst">$randomPersonURL</span>?results=<span class="hljs-subst">$amount</span>"</span>);

    <span class="hljs-keyword">if</span> (response.statusCode == <span class="hljs-number">200</span>) {
      <span class="hljs-built_in">Map</span> peopleData = jsonDecode(response.body);
      <span class="hljs-built_in">List</span>&lt;<span class="hljs-built_in">dynamic</span>&gt; peoples = peopleData[<span class="hljs-string">"results"</span>];
      <span class="hljs-keyword">return</span> peoples.map((json) =&gt; Students.fromJson(json)).toList();
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">throw</span> Exception(<span class="hljs-string">"Something gone wrong, <span class="hljs-subst">${response.statusCode}</span>"</span>);
    }
  }
}
</code></pre><p>But wait where's the code for the <code>Student</code> class?
<br />
At this point, you might have a clear understanding of how manual JSON parsing works.</p>
<p>If not then, hang on. 
I will be explaining it in detail.
<br />
<strong>Step 6:</strong>
<br />
Now we have to create a class of type <code>Student</code>. But where?
<br />
Create a folder named <code>model</code> and put it inside the lib folder.
<br />
<br />
Create a file inside the model folder and name it as <code>student.dart</code>.</p>
<blockquote>
<blockquote>
<p>Note: Use lower came case for naming the file. To avoid any errors.<br />
Also, don't use any special characters in the file name.</p>
</blockquote>
</blockquote>
<p>Create a class named <code>student</code>. (As we have used student in our above code, we will use it here too.)<br />
What we want our code to do is to parse the JSON string, to get the student's information to show up in a list on the homepage.<br />
<br />
So our code will look like this,</p>
<p><code>model/student.dart</code></p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Students</span> </span>{
  <span class="hljs-built_in">String</span> name;
  <span class="hljs-built_in">String</span> rollNo;
  <span class="hljs-built_in">String</span> species;

  Students({<span class="hljs-keyword">this</span>.name, <span class="hljs-keyword">this</span>.rollNo, <span class="hljs-keyword">this</span>.species});

  Students.fromJson(<span class="hljs-built_in">Map</span>&lt;<span class="hljs-built_in">String</span>, <span class="hljs-built_in">dynamic</span>&gt; json)
      : name =
            <span class="hljs-string">"<span class="hljs-subst">${json[<span class="hljs-string">"name"</span>][<span class="hljs-string">"title"</span>]}</span> <span class="hljs-subst">${json[<span class="hljs-string">"name"</span>][<span class="hljs-string">"first"</span>]}</span> <span class="hljs-subst">${json[<span class="hljs-string">"name"</span>][<span class="hljs-string">"last"</span>]}</span>"</span>,
        rollNo = json[<span class="hljs-string">"roll_no"</span>],
        species = json[<span class="hljs-string">"species"</span>];
}
</code></pre><p>Have a look at the code. </p>
<p>First of all, we are creating a constructor.<br />
Then we are creating a method named <code>fromJson</code>.<br />
And inside the method, we are parsing the JSON string and storing the values in the variables.<br />
<br /></p>
<p>So that's it, we performed the manual JSON parsing.</p>
<p>Here's how we will use this class in our code,</p>
<p><code>homepage.dart</code></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:network_request/model/student.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:network_request/services/student_network_service.dart'</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HomeScreen</span> <span class="hljs-title">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-keyword">final</span> StudentNetworkService studentService = StudentNetworkService();

  <span class="hljs-meta">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> Scaffold(
      body: Container(
        child: SafeArea(
          child: FutureBuilder(
            future: studentService.fetchStudents(<span class="hljs-number">100</span>),
            <span class="hljs-comment">// 100 is the number of students to fetch, But you can change the fetchStudents function to </span>
            <span class="hljs-comment">// use the json file in your assets too.</span>
            builder:
                (BuildContext context, AsyncSnapshot&lt;List&lt;Students&gt;&gt; snapshot) {
              <span class="hljs-keyword">if</span> (snapshot.hasData) {
                <span class="hljs-keyword">return</span> Row(
                  children: &lt;Widget&gt;[
                    Expanded(
                      child: Container(
                        child: Card(
                          color: Colors.black.withOpacity(<span class="hljs-number">0.5</span>),
                          child: ListView.builder(
                              itemCount: snapshot.<span class="hljs-keyword">data</span>.length,
                              itemBuilder: (BuildContext context, int index) {
                                <span class="hljs-keyword">var</span> currentStudent = snapshot.<span class="hljs-keyword">data</span>[index];

                                <span class="hljs-keyword">return</span> ListTile(
                                  title: Text(currentStudent.name),
                                  leading: CircleAvatar(
                                      <span class="hljs-comment">// Left for you to do experiments.</span>

                                      <span class="hljs-comment">// backgroundImage:</span>
                                      <span class="hljs-comment">//     NetworkImage(currentStudent.),</span>
                                      ),
                                  subtitle:
                                      Text(<span class="hljs-string">"Roll no: <span class="hljs-subst">${currentStudent.rollNo}</span>"</span>),
                                );
                              }),
                        ),
                      ),
                    ),
                  ],
                );
              }

              <span class="hljs-keyword">if</span> (snapshot.hasError) {
                <span class="hljs-keyword">return</span> Center(
                    child: Icon(
                  Icons.error,
                  color: Colors.red,
                  size: <span class="hljs-number">82.0</span>,
                ));
              }

              <span class="hljs-keyword">return</span> Center(
                  child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: &lt;Widget&gt;[
                  CircularProgressIndicator(),
                  SizedBox(
                    height: <span class="hljs-number">20.0</span>,
                  ),
                  Text(<span class="hljs-string">"Loading at the moment, please hold on"</span>)
                ],
              ));
            },
          ),
        ),
      ),
    );
  }
}
</code></pre><p>Now let's see how we can do that using the <code>json_serializable</code> package to implement the same but by a single line of code.
Not a single line of code, but lesser than usual.
<br />
<br />
Our whole tedious task will be handled by the flutter engine.</p>
<p>Check this <a target="_blank" href="https://blog.bufferoverflow.me/flutter-json-serialization-generated">post</a>.</p>
<hr />
<p>Today we learned how to parse the JSON string and store the values in the variables in flutter.<br />
Our next post will guide you on how to generate the dart code so that it can be used to parse the JSON string with a working example.<br /></p>
<p>Reducing the possible errors and bugs.</p>
<p>Until then, Happy Coding :)</p>
]]></content:encoded></item><item><title><![CDATA[Is Linux the best operating system to choose?]]></title><description><![CDATA[The answer depends a lot more on you,

How you define your use case? 
What do you want your computer to do?
What are the things which are very important to you, and are they supported on Linux too?


Suppose you are a software developer and you want ...]]></description><link>https://gulshan.dev/is-linux-the-best-operating-system-to-choose</link><guid isPermaLink="true">https://gulshan.dev/is-linux-the-best-operating-system-to-choose</guid><category><![CDATA[Linux]]></category><category><![CDATA[linux for beginners]]></category><category><![CDATA[Windows]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Mon, 12 Jul 2021 09:00:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1626080299290/uZDcaHL6C.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The answer depends a lot more on you,</p>
<blockquote>
<p>How you define your use case? </p>
<p>What do you want your computer to do?</p>
<p>What are the things which are very important to you, and are they supported on Linux too?</p>
<hr />
</blockquote>
<p>Suppose you are a software developer and you want to utilize the full power of your computer.
Then Linux is for you!</p>
<p>Here's the thing, if you're a Microsoft developer you'll need a Windows system to do your job.</p>
<p>My aim for this article is to help a freshman to differentiate between Linux-based and Windows-based operating systems.  </p>
<p><strong>Do you like playing games?</strong></p>
<blockquote>
<p>If yes, and you are willing to pay for a steam subscription. Then yeah. You can play games on Linux-based OS. But if you are a person who likes to pirate games, then I'm sorry.</p>
</blockquote>
<p><strong>Do you like using Adobe apps?</strong></p>
<blockquote>
<p>There's a sad thing to know, that Adobe Apps doesn't have any support for Linux-based OS. It is only supported for Windows and Mac users.</p>
<p>But surely you can use the alternative application which is available.</p>
<p>Check <a target="_blank" href="https://itsfoss.com/adobe-alternatives-linux/">this</a> article to know more.</p>
</blockquote>
<p>Now let's check how Linux-based OS can help you?</p>
<h3 id="high-security">High security</h3>
<p>You can substantially reduce the risk of viruses and malware by installing and using Linux on your computer. The security aspect was considered when Linux was developed, making it less susceptible to viruses than Windows.</p>
<p>In most cases, users do not log in as the root (equivalent to the administrator user in Windows). As a result, programs cannot modify system settings and configuration unless the user is logged in as the root.
Since the downloaded file/malware will have limited privileges.</p>
<p>To further secure their systems, Linux users can install ClamAV antivirus software.</p>
<h3 id="open-source">Open Source</h3>
<p>Because Linux is part of the FOSS (Free and Open Source Software) category, it has its source code available to download.</p>
<p>Due to this, developers have access to the source code and can modify it like any other program, which is Difficult with proprietary software.</p>
<h3 id="customisation">Customisation</h3>
<p>With the large variety of wallpapers, icons, and panels to choose from, users can personalize the system to their liking. GNOME, KDE, etc just to name a few, can be selected as a desktop environment. </p>
<p>Many of the most popular web browsers can be run on Linux. The Linux philosophy encourages users to use a large number of small programs, each of which performs a particular task very well. These small programs can be combined to create puissant programs.</p>
<p>System administrators can automate routine maintenance and various other tasks using the Linux OS' robust command-line interface and shell scripts.</p>
<p>So, if you're contemplating a career in system administration, Linux is a adequate platform to start.</p>
<h3 id="support">Support</h3>
<p>Through various forums, the Linux community provides support for the operating system. Any questions posed in the forums will usually be answered quickly, as many enthusiastic volunteers are operating on the problem.</p>
<p>Additionally, businesses can choose paid support options for their critical applications and services, with companies like Red Hat and Novell offering 24*7 support.</p>
<hr />
<p>In sum, If you haven't tried Linux yet, give it a shot. You can dual-boot Windows and Linux simultaneously if you wish.<br />
There are many reasons to use a Linux-based OS, and I have just mentioned a few. You can do some research on the web to find plethora of reasons to use Linux, but I feel these are the key points that made me use it as my main OS.</p>
<hr />
<p>I'm Gulshan Yadav, <br />
In addition to being a student, I am a Technical Writer and also a designer<br />
If you like my <a target="_blank" href="https://blog.bufferoverflow.me">blogs</a> and articles, and you want to suggest something.<br />
Don't be shy to comment in the comment box below or Join our <a target="_blank" href="https://t.me/bufferOverflowdotme">telegram</a> group.</p>
<hr />
<p>I thank you for reading so far, and I wish you a wonderful day :)</p>
]]></content:encoded></item><item><title><![CDATA[#Flutter: Stateful | Animated Container | Future delay]]></title><description><![CDATA[Ahoy, my friends,
I hope you all are doing good.
Our today's topic to learn is about,

Stateful Widget

Animated Container

Future Delay


Hey, don't you think that these are some boring topics.
These are very much interesting topics to learn.
So Wha...]]></description><link>https://gulshan.dev/flutter-stateful-or-animated-container-or-future-delay</link><guid isPermaLink="true">https://gulshan.dev/flutter-stateful-or-animated-container-or-future-delay</guid><category><![CDATA[Flutter]]></category><category><![CDATA[android app development]]></category><category><![CDATA[iOS]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Tue, 15 Jun 2021 09:52:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431311787/5TuWmqrxa.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ahoy, my friends,
I hope you all are doing good.</p>
<p>Our today's topic to learn is about,</p>
<ul>
<li><p>Stateful Widget</p>
</li>
<li><p>Animated Container</p>
</li>
<li><p>Future Delay</p>
</li>
</ul>
<p>Hey, don't you think that these are some boring topics.<br />
These are very much interesting topics to learn.</p>
<p>So What are we waiting for?</p>
<p>Let's Get Started.</p>
<p>So,</p>
<p></p><h4>What is a Stateful Widget?</h4><br /><p></p>
<blockquote>
<p>A widget that has a mutable state.</p>
</blockquote>
<p></p><h4>Hey, but What is State?</h4><p></p>
<blockquote>
<p>The state is information that one can read synchronously when the widget is built and might change during the lifetime of the widget.</p>
</blockquote>
<p>Didn't Understand?</p>
<p>Will help you.<br />
Think about our previous post where we built a login page for our users.<br />
What if we can write Welcome and Username both after the user provides his username?<br />
<br />
Cool naa?</p>
<p>But this thing cannot be handled using the stateless widget.</p>
<p>So now we have to use the <code>Stateful Widget</code> for performing this task.</p>
<p>Ready?<br />
Jump in your code editors and let's change that <code>Stateless Widget</code> into the <code>Stateful Widget</code>.
<br />
<br />
But wait, How are we going to do that?
<br />
Click on the name of our stateless class, you will see a bulb icon, click on it!
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1623435226197/dAAITTNJi.png" alt="Suggestions" /></p>
<p>We will be talking about <code>Mixin</code> in our later articles.
<br />
So, now you created the <code>Stateful widget</code>.</p>
<p>Now create a variable of your choice inside here,<br />
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1623691918181/mEtAzToK4.png" alt="variable declaration in dart" />
<br /><br />
Oops, I haven't taught you what are variables</p>
<blockquote>
<p>In simple words variable is a place where a value is stored.<br />
For example, My name is <code>Gulshan</code> and I am a <code>Developer</code>. So here <code>Gulshan</code> is a variable and <code>Developer</code> is the value.<br /><br />
There are various types in a variable like I am male. And likewise, there are specific types of variables that will store numbers, characters, and so on. <br /><br />
Like <code>int</code> for storing integer values, <code>char</code> for storing characters, and <code>string</code> for storing strings.<br />
In dart you can simply use <code>var</code> as a type and dart will automatically select the type for your declared variable according to the given value.</p>
</blockquote>
<p>Getting back to our point, our variable <code>name</code> will store the username of the user.</p>
<p>Now add <code>$name</code> inside the <code>text widget</code>. Like this,</p>
<pre><code><span class="hljs-selector-tag">Text</span>(
                    <span class="hljs-string">"Welcome $name"</span>,
                    <span class="hljs-attribute">style</span>: TextStyle(
                      <span class="hljs-attribute">fontSize</span>: <span class="hljs-number">21.0</span>,
                      <span class="hljs-attribute">fontWeight</span>: FontWeight.bold,
                    ),
                  )
</code></pre><p>What it does is, It will check the variable for writing the value inside our text widget.<br />
Hey, but we are not done yet.</p>
<p>We need to modify our <code>text form field Widget</code> for storing the given value into our variable.</p>
<p>Here's how you can do this,</p>
<pre><code>TextFormField(
                          onChanged: (<span class="hljs-keyword">value</span>) {
                            <span class="hljs-type">name</span> = <span class="hljs-keyword">value</span>;
                          },
                          decoration: InputDecoration(
                            labelText: "Username or Email",
                            hintText: "you@yourmail.com",
                          ),
                        )
</code></pre><p>We discussed decoration in our previous article, but there's a change. I used the <code>onChanged</code> argument.<br />
<br />
What does it do?<br /></p>
<blockquote>
<p>It will perform certain tasks when the input inside our Field is changed.</p>
</blockquote>
<p><br />
Here it is assigning the value to our variable <code>name</code>. That is the username.<br /></p>
<p>Now you may try clicking the <code>F5</code> button or try running flutter run in your terminal to show the changes, or you may use the hot reload feature of flutter if you are running your flutter application while following this post.</p>
<p>But you may notice, it's not working.<br />
But it is working. The problem is, that it is not rebuilding the application or our page while we are making some changes.<br /></p>
<p>So, how to tell our application to rebuild the specific page while making some changes?<br /></p>
<blockquote>
<p>It's easy.</p>
</blockquote>
<p>We will use <code>setState</code> to inform the framework that the user made some changes.<br /></p>
<p>Its usage,
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1623682420850/FhFfYs_IB.png" alt="image.png" /></p>
<p>You may notice, that I wrapped the assigning task with our <code>setState</code> function.</p>
<p>Now do a hot reload or restart your flutter application and try doing some changes in the username field.<br />
<strong>walla!</strong>
<br />
You successfully learned about the Stateful widget and Setstate usage.</p>
<p></p><h4>Now let's learn about Containers in flutter</h4><br />
I won't bore you with the usual definition of containers in flutter.<br />
Imagine a Container or Box whichever you like.
What is its task??<br />To store something right?<br />It can be anything.
Here we will be using the <code>container widget</code> for building our own button, as we love to get our hands dirty right? <p></p>
<p>Enough talk, let's build our own button.<br />
Here's my code, please check the comments I added for better understanding,</p>
<pre><code><span class="hljs-selector-tag">Container</span>(
    <span class="hljs-attribute">width</span>: <span class="hljs-number">150</span>,
    <span class="hljs-attribute">height</span>: <span class="hljs-number">50</span>,
    <span class="hljs-attribute">alignment</span>: Alignment.center, <span class="hljs-comment">// for alligning the child in centre.</span>
    <span class="hljs-attribute">child</span>: Text(
      <span class="hljs-string">"Login"</span>,
      <span class="hljs-attribute">style</span>: TextStyle(
        <span class="hljs-attribute">color</span>: Colors.white, <span class="hljs-comment">//color of text, since it is black by default. Which looks ugly to me</span>
        <span class="hljs-attribute">fontSize</span>: <span class="hljs-number">18</span>, <span class="hljs-comment">// You may experiment with numbers :)</span>
        <span class="hljs-attribute">fontWeight</span>: FontWeight.bold, <span class="hljs-comment">// So that our login button looks a bit subtle.</span>
      ),
    ),
    <span class="hljs-attribute">decoration</span>: <span class="hljs-comment">// design time. </span>
    BoxDecoration(
      <span class="hljs-attribute">color</span>: Colors.purple, <span class="hljs-comment">// so that it will match with the default color of our application.</span>
      <span class="hljs-attribute">borderRadius</span>: BorderRadius.circular(<span class="hljs-number">10</span>), <span class="hljs-comment">// As the sharp edges of our button is looking a bit ugly.</span>

    ),
  )
</code></pre><p>But there's a problem, Our button can't perform the click operation.</p>
<p></p><h4>How to fix this issue?</h4><br />
We have two options, either we can use <code>GestureDetector</code> or <code>InkWell</code>.
<br />
Which one is best?<br /><p></p>
<blockquote>
<p>Both are best for their specific usage, but for now, we will be using <code>InkWell</code> since It can provide us a plethora of options to customize our button.</p>
</blockquote>
<p>So here we go, </p>
<pre><code><span class="hljs-selector-tag">InkWell</span>(
    <span class="hljs-attribute">child</span>: Container(
      <span class="hljs-attribute">width</span>: <span class="hljs-number">150</span>,
      <span class="hljs-attribute">height</span>: <span class="hljs-number">50</span>,
      <span class="hljs-attribute">alignment</span>: Alignment.center, 
      <span class="hljs-attribute">child</span>: Text(
        <span class="hljs-string">"Login"</span>,
        <span class="hljs-attribute">style</span>: TextStyle(
          <span class="hljs-attribute">color</span>: Colors
              .white, 
          <span class="hljs-attribute">fontSize</span>: <span class="hljs-number">18</span>,
          <span class="hljs-attribute">fontWeight</span>:
              FontWeight.bold,
        ),
      ),
      <span class="hljs-attribute">decoration</span>: 
          BoxDecoration(
        <span class="hljs-attribute">color</span>: Colors
            .purple,
        <span class="hljs-attribute">borderRadius</span>: BorderRadius.circular(
            <span class="hljs-number">10</span>), 
      ),
    ),
    <span class="hljs-attribute">onTap</span>: () {
      <span class="hljs-selector-tag">Navigator</span><span class="hljs-selector-class">.push</span>( <span class="hljs-comment">// routing our page to homepage</span>
        context,
        MaterialPageRoute(
          <span class="hljs-attribute">builder</span>: (context) =&gt; MyHomePage(<span class="hljs-attribute">title</span>: <span class="hljs-string">"Gulshan Yadav"</span>),
        ),
      );
    },
  )
</code></pre><p>Here's how it's going to look like,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1623691594573/sl9c2Pj8B.jpeg" alt="Login Page" /></p>
<p>Yaa, I know there's not so much of a difference we created.<br />
But at least you learned how to use a container to build your own button or whatever you want.</p>
<p>Let's dig deeper,</p>
<p><strong>What is Animated Container?</strong>
According to documentation, I read.</p>
<blockquote>
<p>The AnimatedContainer is a widget that will automatically animate between the old and new values of properties when they change using the provided curve and duration.</p>
<blockquote>
<p>I know you are having a hard time understanding this definition.<br />
Even I had one.</p>
</blockquote>
</blockquote>
<p>What this definition say is, It is a container that can animate from old value of properties to New values of properties.</p>
<blockquote>
<p>You can think of, like when you click our login button, the size of the button can be changed between some specific time duration. Or whatever you can imagine that you want to animate.</p>
</blockquote>
<p>Let's begin,</p>
<p>Create a variable named <code>changedButton</code> with the value <code>false</code>. It is a boolean variable.</p>
<blockquote>
<blockquote>
<p>A variable with the type bool means, it will only deal with true and false or 1 or 0's.</p>
</blockquote>
</blockquote>
<p>And let's use that variable in our code,</p>
<p>Now look at my code and do check the comments for better understanding,</p>
<pre><code><span class="hljs-string">InkWell(</span>
                  <span class="hljs-attr">child:</span> <span class="hljs-string">AnimatedContainer(</span>
                    <span class="hljs-attr">duration:</span> <span class="hljs-string">Duration(seconds:</span> <span class="hljs-number">1</span><span class="hljs-string">),</span> <span class="hljs-string">//</span> <span class="hljs-string">According</span> <span class="hljs-string">to</span> <span class="hljs-string">definition,</span> <span class="hljs-string">duration</span> <span class="hljs-string">is</span> <span class="hljs-string">the</span> 
                                      <span class="hljs-string">//</span> <span class="hljs-string">important</span> <span class="hljs-string">thing</span> <span class="hljs-string">to</span> <span class="hljs-string">consider</span> <span class="hljs-string">while</span> <span class="hljs-string">using</span> <span class="hljs-string">Animatied</span> <span class="hljs-string">container</span>
                    <span class="hljs-attr">width:</span> <span class="hljs-string">changedButton</span> <span class="hljs-string">?</span> <span class="hljs-attr">50 :</span> <span class="hljs-number">150</span><span class="hljs-string">,</span> <span class="hljs-string">//</span> <span class="hljs-string">If</span> <span class="hljs-string">changedButton</span> <span class="hljs-string">is</span> <span class="hljs-literal">true</span> <span class="hljs-string">then</span> <span class="hljs-string">change</span> 
                                                              <span class="hljs-string">//</span> <span class="hljs-string">the</span> <span class="hljs-string">width</span> <span class="hljs-string">to</span> <span class="hljs-number">50</span> <span class="hljs-string">else</span> <span class="hljs-number">150</span>

                    <span class="hljs-attr">height:</span> <span class="hljs-string">changedButton</span> <span class="hljs-string">?</span> <span class="hljs-attr">4 :</span> <span class="hljs-number">50</span><span class="hljs-string">,</span> <span class="hljs-string">//</span> <span class="hljs-string">Same</span> <span class="hljs-string">as</span> <span class="hljs-string">above</span>
                    <span class="hljs-attr">alignment:</span> <span class="hljs-string">Alignment.center,</span>
                    <span class="hljs-attr">child:</span> <span class="hljs-string">Text(</span>
                      <span class="hljs-string">"Login"</span><span class="hljs-string">,</span>
                      <span class="hljs-attr">style:</span> <span class="hljs-string">TextStyle(</span>
                        <span class="hljs-attr">color:</span> <span class="hljs-string">Colors.white,</span>
                        <span class="hljs-attr">fontSize:</span> <span class="hljs-number">18</span><span class="hljs-string">,</span>
                        <span class="hljs-attr">fontWeight:</span> <span class="hljs-string">FontWeight.bold,</span>
                      <span class="hljs-string">),</span>
                    <span class="hljs-string">),</span>
                    <span class="hljs-attr">decoration:</span> <span class="hljs-string">//</span> <span class="hljs-string">design</span> <span class="hljs-string">time.</span>
                        <span class="hljs-string">BoxDecoration(</span>
                      <span class="hljs-attr">color:</span> <span class="hljs-string">Colors.purple,</span>
                      <span class="hljs-attr">borderRadius:</span> <span class="hljs-string">BorderRadius.circular(10),</span>
                    <span class="hljs-string">),</span>
                  <span class="hljs-string">),</span>
                  <span class="hljs-attr">onTap:</span> <span class="hljs-string">()</span> {
                    <span class="hljs-string">setState(()</span> {
                      <span class="hljs-string">changedButton</span> <span class="hljs-string">=</span> <span class="hljs-literal">true</span><span class="hljs-string">;</span> <span class="hljs-string">//</span> <span class="hljs-string">After</span> <span class="hljs-string">tapping</span> <span class="hljs-string">on</span> <span class="hljs-string">our</span> <span class="hljs-string">own</span> <span class="hljs-string">button</span>
                      <span class="hljs-string">//</span> <span class="hljs-string">change</span> <span class="hljs-string">the</span> <span class="hljs-string">value</span> <span class="hljs-string">to</span> <span class="hljs-literal">true</span> <span class="hljs-string">and</span> <span class="hljs-string">perform</span> <span class="hljs-string">some</span> <span class="hljs-string">operations.</span>
                    }<span class="hljs-string">);</span>
                    <span class="hljs-string">//</span> <span class="hljs-string">Removing</span> <span class="hljs-string">this</span> <span class="hljs-string">part</span> <span class="hljs-string">for</span> <span class="hljs-string">the</span> <span class="hljs-string">sake</span> <span class="hljs-string">of</span> <span class="hljs-string">understanding</span>, <span class="hljs-string">what's</span> <span class="hljs-string">happening.</span>
                    <span class="hljs-string">//</span> <span class="hljs-string">Navigator.push(</span>
                    <span class="hljs-string">//</span>   <span class="hljs-string">//</span> <span class="hljs-string">routing</span> <span class="hljs-string">our</span> <span class="hljs-string">page</span> <span class="hljs-string">to</span> <span class="hljs-string">homepage</span>
                    <span class="hljs-string">//</span>   <span class="hljs-string">context</span>,
                    <span class="hljs-string">//</span>   <span class="hljs-string">MaterialPageRoute(</span>
                    <span class="hljs-string">//</span>     <span class="hljs-attr">builder:</span> <span class="hljs-string">(context)</span> <span class="hljs-string">=&gt;</span>
                    <span class="hljs-string">//</span>         <span class="hljs-string">MyHomePage(title:</span> <span class="hljs-string">"Gulshan Yadav"</span><span class="hljs-string">)</span>,
                    <span class="hljs-string">//</span>   <span class="hljs-string">)</span>,
                    <span class="hljs-string">//</span> <span class="hljs-string">);</span>
                  }<span class="hljs-string">,</span>
                  <span class="hljs-attr">splashColor:</span> <span class="hljs-string">Colors.purple[</span>
                      <span class="hljs-number">100</span><span class="hljs-string">],</span> <span class="hljs-string">//</span> <span class="hljs-string">Long</span> <span class="hljs-string">press</span> <span class="hljs-string">the</span> <span class="hljs-string">button</span> <span class="hljs-string">to</span> <span class="hljs-string">see</span> <span class="hljs-string">the</span> <span class="hljs-string">usage</span> <span class="hljs-string">of</span> <span class="hljs-string">splash</span> <span class="hljs-string">color</span>
                <span class="hljs-string">),</span>
</code></pre><p>What this code does is, after we tap on our login button it will change the value inside our variable to true. In our case <code>changedButton</code>.</p>
<p>But you may ask, why did I comment on our navigator part?</p>
<p>Because if there's a navigator part involved, the animation part is totally ignored our page is directly moved to our homepage or next page.</p>
<p>For attaining both animation and navigation through pages, we need something else.</p>
<p>Here comes the <code>Future delay</code> widget to help us.</p>
<p>here's how I used it,</p>
<pre><code>onTap: () async {
                    setState(() {
                      changedButton = <span class="hljs-keyword">true</span>; // <span class="hljs-keyword">After</span> tapping <span class="hljs-keyword">on</span> our own button
                      // change the <span class="hljs-keyword">value</span> <span class="hljs-keyword">to</span> <span class="hljs-keyword">true</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">perform</span> <span class="hljs-keyword">some</span> operations.
                    });
                    await Future.delayed(Duration(seconds: <span class="hljs-number">1</span>));
                    Navigator.push(
                      // routing our page <span class="hljs-keyword">to</span> homepage
                      context,
                      MaterialPageRoute(
                        builder: (context) =&gt;
                            MyHomePage(title: "Gulshan Yadav"),
                      ),
                    );
                  }
</code></pre><p>You may notice that I have used <code>async</code> and <code>await</code> keywords, what are those?</p>
<blockquote>
<p><code>Async</code> Simply means occurring at the same time.<br />
And <code>Await</code> means to wait. i.e. to wait for a certain operation to over.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1623750054145/LR7gcMllG.gif" alt="flutter app.gif" /></p>
<p>I want you to do some tweaks to the application so that it will help you in your learning.</p>
<p>Just play around and you will learn a lot.</p>
<hr />
<p>In this article, we learned about the stateful widget, set-state usage, and its importance, Building our own button using a container, and also tried future delay for performing some small animations.</p>
<p>In the next article, we will be exploring more flutter widgets you are supposed to know.</p>
<p>until then, stay home stay safe.</p>
<p>Cya :)</p>
]]></content:encoded></item><item><title><![CDATA[#Flutter: What are SingleChildScrollView and Expanded?]]></title><description><![CDATA[A SingleChildScrollView is a widget.
As we know almost everything in flutter is a widget.
But how this widget differs from others?

This widget is used when dealing with devices with smaller screens.
Or in the case when using a column or row as for d...]]></description><link>https://gulshan.dev/flutter-what-are-singlechildscrollview-and-expanded</link><guid isPermaLink="true">https://gulshan.dev/flutter-what-are-singlechildscrollview-and-expanded</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Android]]></category><category><![CDATA[iOS]]></category><category><![CDATA[app development]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Sun, 06 Jun 2021 14:54:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431345658/O5JJHHj2o.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A SingleChildScrollView is a widget.
As we know almost everything in flutter is a widget.</p>
<h3 id="but-how-this-widget-differs-from-others">But how this widget differs from others?</h3>
<blockquote>
<p>This widget is used when dealing with devices with smaller screens.</p>
<p>Or in the case when using a column or row as for displaying something which doesn't fit in the screen.</p>
</blockquote>
<p>And when something which doesn't fit in the screen, flutter throws some error like, </p>
<blockquote>
<blockquote>
<p>Bottom Overflow</p>
</blockquote>
</blockquote>
<p>But we can fix this <code>bottom Overflow</code> issue by using the <code>expanded</code> widget.</p>
<p>So why should we use <code>SingleChildScrollView</code>?</p>
<p>Because when using the <code>Expanded</code> widget, it shrinks all the content or child to fit inside it.</p>
<p>But sometimes, due to this our design doesn't look that appealing for the user.</p>
<p>Though the <code>Expanded</code> widget is a Good widget.
And it has some use cases, but it is not recommended to fix the overflow issue by using the <code>expanded</code> widget.</p>
<h3 id="now-you-may-ask-whats-the-expanded-widget">Now you may ask what's the <code>Expanded</code> widget?</h3>
<p>It's a widget that expands a child of a Row, Column, or Flex so that the child fills the available space.</p>
<p>Easy?</p>
<p>Let's dive deeper.</p>
<p>Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space along the main axis (e.g., for a Row or for a Column). </p>
<p>If many children are expanded, the available space is divided among them according to the flex factor.</p>
<p>You may ask that how to use these two widgets?</p>
<ul>
<li>For <code>SingleChildScrollView</code><blockquote>
<blockquote>
<p>Wrap the whole widget with <code>SingleChildScrollView</code>.</p>
</blockquote>
</blockquote>
</li>
</ul>
<p>For e.g.</p>
<pre><code>
<span class="hljs-selector-tag">class</span> <span class="hljs-selector-tag">LoginPage</span> <span class="hljs-selector-tag">extends</span> <span class="hljs-selector-tag">StatelessWidget</span> {
  <span class="hljs-variable">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-selector-tag">return</span> <span class="hljs-selector-tag">Scaffold</span>(
      <span class="hljs-attribute">body</span>: SafeArea(
        <span class="hljs-attribute">child</span>: Material(
          <span class="hljs-attribute">color</span>: Colors.white,
          <span class="hljs-attribute">child</span>: SingleChildScrollView(
            <span class="hljs-attribute">child</span>: Center(
              <span class="hljs-attribute">child</span>: somethingInsideColumn(context),
                     <span class="hljs-comment">//I declared a function, it's not something Special.</span>
            ),
          ),
        ),
      ),
    );
  }
}
</code></pre><p>And One can also use the expanded widget in a similar way.</p>
<hr />
<p>I hope you understood the usage of these two widgets in Flutter.</p>
<p>If you are facing some difficulties, or you want to give some suggestion, 
please head over to our <a target="_blank" href="https://t.me/bufferoverflowdotme/">telegram group</a>.</p>
<p>So that's it for today.</p>
<p>Please wait for our next article.</p>
<p>Until then stay home, stay safe.</p>
<p>And be productive with your time.</p>
<p>Cya :)</p>
]]></content:encoded></item><item><title><![CDATA[#Flutter: Pages]]></title><description><![CDATA[Ahoy, Thanks for being here :)
I have a quote for you which says that,

There's no substitute for hard work.

Now let's get to today's topic, i.e. pages.
First of all, you may ask why I should even care, what pages are in Flutter? 

My answer

You ca...]]></description><link>https://gulshan.dev/flutter-pages</link><guid isPermaLink="true">https://gulshan.dev/flutter-pages</guid><category><![CDATA[Flutter]]></category><category><![CDATA[android app development]]></category><category><![CDATA[Flutter Examples]]></category><category><![CDATA[android apps]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Tue, 01 Jun 2021 09:09:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431377634/d5KYid_8p.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Ahoy</strong>, Thanks for being here :)</p>
<p>I have a quote for you which says that,</p>
<blockquote>
<p>There's no substitute for hard work.</p>
</blockquote>
<p>Now let's get to today's topic, i.e. pages.</p>
<p>First of all, you may ask why I should even care, what pages are in Flutter? </p>
<blockquote>
<p>My answer</p>
<blockquote>
<p>You can think of that your app as actually a website and a website needs some pages to view the content on your site.</p>
<p>So this means pages are something important.
So there's no problem in learning about pages in Flutter.</p>
</blockquote>
</blockquote>
<p><strong>What are we going to learn in this article?</strong></p>
<blockquote>
<p>We will be learning about,</p>
<blockquote>
<ul>
<li>Safe area and its importance.</li>
<li>Adding an image in our application.</li>
<li>Using Textformfield in our application and its importance.</li>
<li>How to choose colors to use.</li>
<li>How to navigate through different pages.</li>
</ul>
</blockquote>
</blockquote>
<p>So now let's get started!</p>
<p>I will be considering the design of our application as shown in my previous article.</p>
<p>Get into the <code>login.dart</code> file and import the material.</p>
<p>here's how,</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
</code></pre><p>Now type <code>stless</code> to click on the template recommended by your text editor or ide.</p>
<p>This will insert a stateless widget into your code.</p>
<p><strong>Hey, but what is a stateless widget?</strong></p>
<blockquote>
<p>The widgets whose state can not be altered once they are built are called stateless widgets. These widgets are immutable once they are built i.e any amount of change in the variables, icons, buttons, or retrieving data can not change the state of the app.</p>
<p>In simple words, A stateless widget never changes. Icon, IconButton, and Text are examples of stateless widgets.</p>
</blockquote>
<p>So, according to our design, there's an image or illustration at the upper part of our page/screen.</p>
<p><strong>But how to add that image to our application?</strong></p>
<p>Here come's our widget named <code>image.asset</code> which takes the address of the image in a directory as an argument.</p>
<pre><code><span class="hljs-selector-tag">Image</span><span class="hljs-selector-class">.asset</span>(
                  <span class="hljs-string">"assets/image2.png"</span>,
                  <span class="hljs-attribute">fit</span>: BoxFit.cover,
                ),
</code></pre><p>You may ask a question, what is this <code>BoxFit.cover</code> means in our code?</p>
<p>what a <code>cover</code> constant does is, clips the picture if it is not fitting inside our box.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622478264773/wDOkSm9PH.png" alt="Cover" /></p>
<p>It is good to use when we don't want our image to be enlarged or scaled up for making that image fit inside that box.</p>
<p>Though you can try this by using the <code>fill</code> constant instead of <code>cover</code>.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622478290774/Gl6D9-HCQ.png" alt="Fit" /></p>
<p>There's another constant too, which is named <code>contain</code>, It is a kind of box which can be as large as it can.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622478224336/HI6rOOYmV.png" alt="Contain" /></p>
<p><strong>You may ask me, where I should place my image?</strong></p>
<p><strong>And how am I going to tell the Flutter, that here's my image I am going to use?</strong></p>
<p>Create a folder named <code>assets</code> inside the root folder of our project and create one more folder named <code>images</code> inside the <code>assets</code> folder.</p>
<p>And here our images will be stored.</p>
<p>Here's how our file structure will look like,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622478783992/Qt9RpST4E.png" alt="File structure" /></p>
<p>But wait, we are not done yet. We have to tell Flutter that here's my image will be getting stored.</p>
<p>Now open the <code>pubspec.yaml</code> file and paste this piece of code.</p>
<pre><code>  <span class="hljs-attribute">assets</span>:
    - assets/images/
</code></pre><p>Please refer to the comments too, If you are facing some issue or don't be shy about texting me.</p>
<p>What this line of code saying is,</p>
<blockquote>
<p>hey Flutter, remember that my assets will be stored in this folder!</p>
</blockquote>
<p>But you may also ask what is an asset in the first place.</p>
<blockquote>
<p>I did a google search for you.</p>
<blockquote>
<p>Thing that is useful to somebody/something is known as an asset.</p>
</blockquote>
</blockquote>
<p>Let's check <strong>how to use the text form field?</strong></p>
<p>A FormField that contains a TextField.</p>
<p>This is a convenience widget that wraps a TextField widget in a FormField.</p>
<p>The Form simply makes it easier to save, reset, or validate multiple fields at once.</p>
<p>Here's how it is used</p>
<pre><code><span class="hljs-selector-tag">TextFormField</span>(
                        <span class="hljs-attribute">controller</span>: someTextEditController,
                        <span class="hljs-attribute">decoration</span>: InputDecoration(
                          <span class="hljs-attribute">labelText</span>: <span class="hljs-string">"Username or Email"</span>,
                          <span class="hljs-attribute">hintText</span>: <span class="hljs-string">"you@yourmail.com"</span>,
                        ),
                      ),
</code></pre><p>Hey, but what is that <code>Text Edit Controller</code>?</p>
<blockquote>
<blockquote>
<p>It is a controller for an editable text field.
Something which can be modified from the user's side.
This can be used to store the email address or password of the user or anything else.</p>
</blockquote>
</blockquote>
<p>but you may also ask what are those label text and hint text doing inside decoration?</p>
<p>I cannot explain this question, but this picture can surely help you understand what it is.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622537163435/F0VThOrAy.png" alt="what are those label text and hint text" /></p>
<p>Now we are done with the text form field and image, the next thing we need is a login button in our application.</p>
<p>We have some options to choose from like the Text button, Elevated button, etc.</p>
<p>For now, we will be using the <code>ElevatedButton</code>.</p>
<p>You may also ask how these buttons differ from one another?</p>
<p>I want you to see the image given below, which will give you some idea about how they look.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622537657808/tcn42YL5u.png" alt="how these buttons differ" /></p>
<p>And please note that every button has the same or similar functionality, it's just a matter of how they look. Though there are some differences, which you will come to know in our later articles.</p>
<p>Here's how to use an elevated button as our widget,</p>
<pre><code><span class="hljs-selector-tag">ElevatedButton</span>(
    <span class="hljs-attribute">onPressed</span>: () {

           <span class="hljs-selector-tag">Navigator</span><span class="hljs-selector-class">.push</span>(
              context,
              MaterialPageRoute(
                <span class="hljs-attribute">builder</span>: (context) =&gt; MyHomePage(<span class="hljs-attribute">title</span>: <span class="hljs-string">"Gulshan Yadav"</span>),
              ),
            );

    },

    <span class="hljs-selector-tag">child</span>: <span class="hljs-selector-tag">Text</span>(
      <span class="hljs-string">"$task"</span>,
      <span class="hljs-attribute">style</span>: TextStyle(<span class="hljs-attribute">fontWeight</span>: FontWeight.bold),
    ),
  )
</code></pre><p>You may ask us what is that <code>Navigator.push</code> it seems a bit overwhelming naa?</p>
<p>It's just saying to our app that you route me to the Homepage if I click that login button!</p>
<p>And that's it.</p>
<p>So after all these concepts, leme share the actual code for the login page with you.</p>
<pre><code><span class="hljs-string">import</span> <span class="hljs-string">'package:firstapp/pages/homepage.dart'</span><span class="hljs-string">;</span>
<span class="hljs-string">import</span> <span class="hljs-string">'package:flutter/material.dart'</span><span class="hljs-string">;</span>
<span class="hljs-string">import</span> <span class="hljs-string">'dart:async'</span><span class="hljs-string">;</span>

<span class="hljs-string">class</span> <span class="hljs-string">LoginPage</span> <span class="hljs-string">extends</span> <span class="hljs-string">StatelessWidget</span> {
  <span class="hljs-string">@override</span>
  <span class="hljs-string">Widget</span> <span class="hljs-string">build(BuildContext</span> <span class="hljs-string">context)</span> {
    <span class="hljs-string">return</span> <span class="hljs-string">Scaffold(</span>
      <span class="hljs-attr">body:</span> <span class="hljs-string">SafeArea(</span>
        <span class="hljs-attr">child:</span> <span class="hljs-string">Material(</span>
          <span class="hljs-attr">color:</span> <span class="hljs-string">Colors.white</span>,
          <span class="hljs-attr">child:</span> <span class="hljs-string">Center(</span>
            <span class="hljs-attr">child:</span> <span class="hljs-string">Column(</span>
              <span class="hljs-attr">children:</span> [
                <span class="hljs-string">Image.asset(</span>
                  <span class="hljs-string">"assets/images/image2.png"</span>,
                  <span class="hljs-attr">fit:</span> <span class="hljs-string">BoxFit.cover</span>,
                <span class="hljs-string">)</span>,
                <span class="hljs-string">Text(</span>
                  <span class="hljs-string">"Welcome"</span>,
                  <span class="hljs-attr">style:</span> <span class="hljs-string">TextStyle(</span>
                    <span class="hljs-attr">fontSize:</span> <span class="hljs-number">21.0</span>,
                    <span class="hljs-attr">fontWeight:</span> <span class="hljs-string">FontWeight.bold</span>,
                  <span class="hljs-string">)</span>,
                <span class="hljs-string">)</span>,
                <span class="hljs-string">Padding(</span>
                  <span class="hljs-attr">padding:</span> <span class="hljs-string">const</span> <span class="hljs-string">EdgeInsets.symmetric(</span>
                    <span class="hljs-attr">horizontal:</span> <span class="hljs-number">30</span>,
                    <span class="hljs-attr">vertical:</span> <span class="hljs-number">30</span>,
                  <span class="hljs-string">)</span>,
                  <span class="hljs-attr">child:</span> <span class="hljs-string">Column(</span>
                    <span class="hljs-attr">children:</span> [
                      <span class="hljs-string">TextFormField(</span>
                        <span class="hljs-attr">decoration:</span> <span class="hljs-string">InputDecoration(</span>
                          <span class="hljs-attr">labelText:</span> <span class="hljs-string">"Username or Email"</span>,
                          <span class="hljs-attr">hintText:</span> <span class="hljs-string">"you@yourmail.com"</span>,
                        <span class="hljs-string">)</span>,
                      <span class="hljs-string">)</span>,
                      <span class="hljs-string">TextFormField(</span>

                        <span class="hljs-attr">decoration:</span> <span class="hljs-string">InputDecoration(</span>
                          <span class="hljs-attr">labelText:</span> <span class="hljs-string">"Password"</span>,
                          <span class="hljs-attr">hintText:</span> <span class="hljs-string">"My strong Password"</span>,
                        <span class="hljs-string">)</span>,
                        <span class="hljs-attr">obscureText:</span> <span class="hljs-literal">true</span>,
                      <span class="hljs-string">)</span>
                    ],
                  <span class="hljs-string">)</span>,
                <span class="hljs-string">)</span>,
                <span class="hljs-string">_textbutton(context</span>, <span class="hljs-attr">islongpress:</span> <span class="hljs-literal">true</span><span class="hljs-string">)</span>
              ],
            <span class="hljs-string">)</span>,
          <span class="hljs-string">)</span>,
        <span class="hljs-string">)</span>,
      <span class="hljs-string">)</span>,
    <span class="hljs-string">);</span>
  }
}

<span class="hljs-string">Widget</span> <span class="hljs-string">_textbutton(BuildContext</span> <span class="hljs-string">context)</span> {
  <span class="hljs-string">return</span> <span class="hljs-string">ElevatedButton(</span>
    <span class="hljs-attr">onPressed:</span> <span class="hljs-string">()</span> {
          <span class="hljs-string">Navigator.push(</span>
              <span class="hljs-string">context</span>,
              <span class="hljs-string">MaterialPageRoute(</span>
                <span class="hljs-attr">builder:</span> <span class="hljs-string">(context)</span> <span class="hljs-string">=&gt;</span> <span class="hljs-string">MyHomePage(title:</span> <span class="hljs-string">"Gulshan Yadav"</span><span class="hljs-string">)</span>,
              <span class="hljs-string">)</span>,
            <span class="hljs-string">);</span>
    },

    <span class="hljs-attr">child:</span> <span class="hljs-string">Text(</span>
      <span class="hljs-string">"$task"</span>,
      <span class="hljs-attr">style:</span> <span class="hljs-string">TextStyle(fontWeight:</span> <span class="hljs-string">FontWeight.bold)</span>,
    <span class="hljs-string">)</span>,
  <span class="hljs-string">);</span>
}
</code></pre><p>Ohh, I got that illustration from a site named <a target="_blank" href="https://undraw.co/">undraw</a>.</p>
<p>As you can see inside our code, there's something named <code>safe area</code>, what's that?</p>
<p>It's a widget that inserts its child with enough padding to avoid intrusions by the operating system.</p>
<blockquote>
<p>For example, this will indent the child by enough to avoid the status bar at the top of the screen.</p>
<p>It will also indent the child by the amount necessary to avoid The Notch on the screen, or other similar creative physical features of the display.</p>
</blockquote>
<p>I want you to read <a target="_blank" href="https://material.io/design/color/the-color-system.html">this</a> page to know how to choose the shade of color for your application to look materialistic.</p>
<p>It will help you in choosing the right color for your design.</p>
<hr />
<p>We're done, hope you liked this article. If you have any doubt, please don't be shy to ask in our <a target="_blank" href="https://t.me/Bufferoverflowdotme/">Telegram group</a>.</p>
<p>Stay home, stay safe.</p>
<p>Cya :)</p>
]]></content:encoded></item><item><title><![CDATA[#Flutter: Intro to basic widgets in Flutter]]></title><description><![CDATA[Ahoy, after learning something about Object-oriented Programming, let's get started with some cool stuff in Flutter.
Open your Code-editors or open Dartpad
Let's go!
So first of all what is widgets ??


an application, or a component of an interface,...]]></description><link>https://gulshan.dev/flutter-intro-to-basic-widgets-in-flutter</link><guid isPermaLink="true">https://gulshan.dev/flutter-intro-to-basic-widgets-in-flutter</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Android]]></category><category><![CDATA[app development]]></category><category><![CDATA[login]]></category><category><![CDATA[Dart]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Mon, 31 May 2021 07:44:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431398882/UcazeAS1w.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ahoy, after learning something about Object-oriented Programming, let's get started with some cool stuff in Flutter.</p>
<p><strong>Open your Code-editors or open <a target="_blank" href="https://dartpad.dev/flutter?null_safety=true">Dartpad</a></strong></p>
<p>Let's go!</p>
<p>So first of all what is widgets ??</p>
<blockquote>
<blockquote>
<p>an application, or a component of an interface, that enables us to perform some function, right?</p>
</blockquote>
</blockquote>
<p>But what are widgets doing inside Flutter?</p>
<blockquote>
<p>One of the main things that you quickly realize, while using Flutter is that nearly everything is a widget.</p>
</blockquote>
<p>That also means there's so much built all ready to use in Flutter, you don't need to build some function from scratch.</p>
<p>Though for building your application, you have to start from scratch.</p>
<p>Let's begin with some of the basic things you should know before starting coding in Flutter.</p>
<p>Some Important classes.</p>
<h3>Scaffold:</h3>

<p>The Scaffold is a widget in Flutter used to implements the basic material design visual layout structure.</p>
<p>This widget can occupy the whole device screen.</p>
<p>we can say that it is mainly responsible for creating a base to the app screen on which the child widgets hold on and render on the screen.</p>
<p>It provides many widgets or APIs for showing Drawer, SnackBar, BottomNavigationBar, AppBar, FloatingActionButton, and many more.</p>
<p>The Scaffold class is a shortcut to set up the look and design of our app that allows us not to build the individual visual elements manually. </p>
<p>It saves our time to write more code for the look and feel of the app. </p>
<p>The following are the constructor and properties of the Scaffold widget class.</p>
<pre><code><span class="hljs-keyword">const</span> Scaffold({  
    Key? key,
    <span class="hljs-keyword">this</span>.appBar,
    <span class="hljs-keyword">this</span>.body,
    <span class="hljs-keyword">this</span>.floatingActionButton,
    <span class="hljs-keyword">this</span>.floatingActionButtonLocation,
    <span class="hljs-keyword">this</span>.floatingActionButtonAnimator,
    <span class="hljs-keyword">this</span>.persistentFooterButtons,
    <span class="hljs-keyword">this</span>.drawer,
    <span class="hljs-keyword">this</span>.onDrawerChanged,
    <span class="hljs-keyword">this</span>.endDrawer,
    <span class="hljs-keyword">this</span>.onEndDrawerChanged,
    <span class="hljs-keyword">this</span>.bottomNavigationBar,
    <span class="hljs-keyword">this</span>.bottomSheet,
    <span class="hljs-keyword">this</span>.backgroundColor,
    <span class="hljs-keyword">this</span>.resizeToAvoidBottomInset,
    <span class="hljs-keyword">this</span>.primary = <span class="hljs-literal">true</span>,
    <span class="hljs-keyword">this</span>.drawerDragStartBehavior = DragStartBehavior.start,
    <span class="hljs-keyword">this</span>.extendBody = <span class="hljs-literal">false</span>,
    <span class="hljs-keyword">this</span>.extendBodyBehindAppBar = <span class="hljs-literal">false</span>,
    <span class="hljs-keyword">this</span>.drawerScrimColor,
    <span class="hljs-keyword">this</span>.drawerEdgeDragWidth,
    <span class="hljs-keyword">this</span>.drawerEnableOpenDragGesture = <span class="hljs-literal">true</span>,
    <span class="hljs-keyword">this</span>.endDrawerEnableOpenDragGesture = <span class="hljs-literal">true</span>,
    <span class="hljs-keyword">this</span>.restorationId,
})
</code></pre><p>Cool huh?</p>
<blockquote>
<blockquote>
<p>I know it seems overwhelming XD</p>
</blockquote>
<p>No worries, we will be dealing with most of them in our future articles.</p>
</blockquote>
<p>Be relaxed, let's check them one by one.</p>
<p><strong>appBar</strong></p>
<p>First of all what is appBar ??</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622295086826/M0YmljEzp.png" alt="AppBar" /></p>
<p>Got it?</p>
<p>Let's code our AppBar.</p>
<pre><code><span class="hljs-attribute">appBar</span>: AppBar(
        <span class="hljs-attribute">title</span>: Text("My First App),
         )
</code></pre><p>Yaa, that's it!</p>
<p>By the way, this should be written inside the brackets of the scaffold.</p>
<p>Please refer to the last part of <a target="_blank" href="https://blog.bufferoverflow.me/lets-get-started-with-flutter">this</a> article. About the placement of your code.</p>
<p><strong>Body</strong></p>
<p>As the name suggests, it's the actual body of your application, where most of our meaningful code is going to be written.</p>
<pre><code><span class="hljs-attribute">body</span>: Center(
          <span class="hljs-attribute">child</span>: MyWidget(),
                      )
</code></pre><p><code>MyWidget</code>:</p>
<pre><code>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyWidget</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  @override
  Wid<span class="hljs-keyword">get</span> <span class="hljs-title">build</span>(<span class="hljs-params">BuildContext context</span>) {
    <span class="hljs-keyword">return</span> Text(<span class="hljs-string">'Buffer Overflow'</span>, <span class="hljs-attr">style</span>: Theme.of(context).textTheme.headline4);
  }
}
</code></pre><p>Ahh, I won't bore you. Let's code something!</p>
<p>So What are we going to code?</p>
<p>Before coding let's first determine what our app is going to do?</p>
<p>Umm, let's code a useless app. It will help you understand how things work and how you can easily build your application.</p>
<p>My next question is how our app will look like?</p>
<p>I prefer using <a target="_blank" href="https://www.figma.com/">Figma</a>, you may use <a target="_blank" href="https://www.adobe.com/">Adobe XD</a>. </p>
<p>It's your choice :)</p>
<p>My design:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622441694739/yG-L8JOon.jpeg" alt="Login Page Design" /></p>
<p>I know it's not that good-looking, but let's just code this design into an Application.</p>
<p>So what we are going to learn after building this page?</p>
<blockquote>
<p>Theming</p>
<p>What is a primary swatch</p>
<p>How to route our pages?</p>
</blockquote>
<p>So, As we can see it's an Application that has a login page.</p>
<p><strong>First Step:</strong></p>
<p>Follow the steps listed in <a target="_blank" href="https://blog.bufferoverflow.me/lets-get-started-with-flutter">this</a> article, which will build a basic application base.</p>
<p>Change the directory and get into the <code>lib</code> folder and open <code>main.dart</code> file.</p>
<p>Let's just remove all the comments written.</p>
<p>Remove this part too</p>
<pre><code><span class="hljs-keyword">int</span> _counter = <span class="hljs-number">0</span>;

  <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">_incrementCounter</span><span class="hljs-params">()</span> </span>{
    setState(() {
      _counter++;
    });
  }
</code></pre><p>This too</p>
<pre><code><span class="hljs-attribute">floatingActionButton</span>: FloatingActionButton(
        <span class="hljs-attribute">onPressed</span>: _incrementCounter,
        <span class="hljs-attribute">tooltip</span>: <span class="hljs-string">'Increment'</span>,
        <span class="hljs-attribute">child</span>: Icon(Icons.add),
      ),
</code></pre><p>And finally, remove this too.</p>
<pre><code> <span class="hljs-selector-tag">Center</span>(
        <span class="hljs-attribute">child</span>: Column(
          <span class="hljs-attribute">mainAxisAlignment</span>: MainAxisAlignment.center,
          <span class="hljs-attribute">children</span>: &lt;Widget&gt;[
            Text(
              <span class="hljs-string">'You have pushed the button this many times:'</span>,
            ),
            Text(
              <span class="hljs-string">'$_counter'</span>,
              <span class="hljs-attribute">style</span>: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
</code></pre><p>Here's how my <code>main.dart</code> looks</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:firstapp/pages/login_Page.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'pages/homepage.dart'</span>;

<span class="hljs-keyword">void</span> main() {
  runApp(MyApp());
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  @override
  Wid<span class="hljs-keyword">get</span> <span class="hljs-title">build</span>(<span class="hljs-params">BuildContext context</span>) {
    <span class="hljs-keyword">return</span> MaterialApp(
      title: <span class="hljs-string">'Flutter Demo'</span>,
      <span class="hljs-attr">theme</span>: ThemeData(
        primarySwatch: Colors.deepOrange,
        <span class="hljs-attr">brightness</span>: Brightness.dark,
      ),
      <span class="hljs-comment">// darkTheme: ThemeData(brightness: Brightness.dark),</span>
      <span class="hljs-comment">// home: MyHomePage(title: 'Flutter Demo Home Page'),</span>
      <span class="hljs-attr">routes</span>: {
        <span class="hljs-string">"/"</span>: <span class="hljs-function">(<span class="hljs-params">context</span>) =&gt;</span> MyHomePage(title: <span class="hljs-string">"Gulshan"</span>),
        <span class="hljs-string">"/loginPage"</span>: <span class="hljs-function">(<span class="hljs-params">context</span>) =&gt;</span> LoginPage(),
      },
    );
  }
}
</code></pre><p>By seeing the above code, we can see that the widget is returning a Material app.</p>
<p>Please if you are not getting some of the things, please refer to my previous articles on Flutter.</p>
<p>It will surely give you an idea of some of the important concepts used in programming.</p>
<p>Coming back to the Material app, we can see that it has some <code>Title</code> and some theme, which takes Theme data as its input.</p>
<blockquote>
<blockquote>
<p>You can think of this as, <code>char name</code></p>
<p>This variable <code>name</code> can only take character as an input, and one can't assign any number to it.</p>
</blockquote>
<p>Though it is possible to assign a number to a variable of type <code>char</code> you have to first convert that number into a type <code>string</code>.</p>
<blockquote>
<p>Didn't Understand?</p>
</blockquote>
<p>No Worries. </p>
</blockquote>
<p>There's an <code>Argument</code> named <code>PrimarySwatch</code> and has a value as <code>Colors.deepOrange</code>.</p>
<pre><code><span class="hljs-attribute">PrimaruSwatch</span>: Colors.deepOrange
</code></pre><p>Please refer to our design, one can see that the app bar of our design has something like a violet color.</p>
<p>But because of this value <code>Colors.deepOrange</code>, Our application will appear as deep orange in color.</p>
<p>I recommend you to play with colors and choose the color of your choice.</p>
<p>The next line of code says something about brightness, it's nothing but it is asking you that <code>will your application be in dark or light mode?</code></p>
<p>For instance, use light mode as that deep orange won't be appearing to you, as the dark mode will override everything into the dark theme.</p>
<p>Moving to the next line
we can see a commented line</p>
<pre><code><span class="hljs-attribute">home</span>: MyHomePage(<span class="hljs-attribute">title</span>: <span class="hljs-string">'Flutter Demo Home Page'</span>),
</code></pre><p>This will route our application to this class named <code>MyHomePage</code></p>
<p>Therefore, the first page for our application is defined in this class named <code>MyHomePage</code>.</p>
<p>But why I commented this out??</p>
<p>I wanna introduce you to <code>routes</code> in Flutter, it will even help you build a web app based on Flutter.</p>
<p>Moving to a piece of code, we can see</p>
<pre><code>routes: {
        <span class="hljs-string">"/"</span>: <span class="hljs-function"><span class="hljs-params">(context)</span> =&gt;</span> MyHomePage(title: <span class="hljs-string">"This is title"</span>),
        <span class="hljs-string">"/loginPage"</span>: <span class="hljs-function"><span class="hljs-params">(context)</span> =&gt;</span> LoginPage(),
      },
</code></pre><p>Here <code>/</code> means the same as <code>home</code> in the above code. Yaa, it's the same thing.</p>
<p>But we want our login page to be displayed first naa?</p>
<p>let's change the code in some way that it will show the login page as it's the homepage for our application.</p>
<p>I want you to change this piece of code on your own :)</p>
<blockquote>
<blockquote>
<p>hint: Replace <code>MyHomepage(title: ".....")</code> with LoginPage()</p>
</blockquote>
</blockquote>
<p>So now I think we are done with our <code>main.dart</code> file.</p>
<p>Are you excited about coding our login page??</p>
<blockquote>
<p>I know you are bored till now, I just want you to create a folder named <code>pages</code> inside the <code>lib</code> folder and create a file named <code>login.dart</code> inside the <code>pages</code> folder.</p>
</blockquote>
<hr />
<p>We are done, for now, we learned about theming, and how to route our application to a specific page in this article.</p>
<p>I hope you understood everything I specified in this article. In the next article, we will be coding our login page.</p>
<p>If you have some doubts, please head over to our <a target="_blank" href="https://t.me/bufferoverflowdotme">Telegram group</a>. I will be more than happy to help you.</p>
<p>There's saying </p>
<pre><code><span class="hljs-keyword">if</span> you want <span class="hljs-keyword">to</span> impress people make things complicated, <span class="hljs-keyword">If</span> you want <span class="hljs-keyword">to</span> help people, keep it simple
</code></pre><p>I wanna help you and I will be there for you.</p>
<p>Stay home, stay safe.</p>
<p>Cya :)</p>
]]></content:encoded></item><item><title><![CDATA[#Flutter: A short intro to OOP]]></title><description><![CDATA[For those of you, who haven't learned object-oriented programming language.
I want to give you a short intro to this "Object-Oriented Programming"
This would be highly beneficial to you, as Procedural programming is about writing procedures or functi...]]></description><link>https://gulshan.dev/flutter-a-short-intro-to-oop</link><guid isPermaLink="true">https://gulshan.dev/flutter-a-short-intro-to-oop</guid><category><![CDATA[Flutter]]></category><category><![CDATA[oop]]></category><category><![CDATA[Android]]></category><category><![CDATA[iOS]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Tue, 25 May 2021 14:01:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431420849/n5iQ2mlN2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1621945142953/60E9VAR_Sn.jpeg" alt="Flutter" /></p>
<p>For those of you, who haven't learned object-oriented programming language.</p>
<p><strong>I want to give you a short intro to this "Object-Oriented Programming"</strong></p>
<p>This would be highly beneficial to you, as Procedural programming is about writing procedures or functions that perform operations on the <strong>data</strong> while object-oriented programming is about creating objects that contain both <strong>data</strong> and <strong>functions</strong>.</p>
<p>didn't understand?</p>
<blockquote>
<p>Don't worry! You will understand soon :)</p>
</blockquote>
<hr />
<p>By the way, what are the advantages of <code>Object-Oriented Programming</code> and why it is important?</p>
<p>Because</p>
<blockquote>
<ul>
<li>OOP is faster and easier to execute</li>
<li>OOP provides a clear structure for the programs</li>
<li>OOP helps to keep the C++/Java/Dart code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug</li>
<li>OOP makes it possible to create full reusable applications with less code and shorter development time</li>
</ul>
</blockquote>
<h4 id="object-oriented-programming-is-associated-with-concepts-like-class-object-abstraction-encapsulation-polymorphism-and-inheritance">Object-Oriented Programming is associated with concepts like Class, Object, Abstraction, Encapsulation, Polymorphism, and Inheritance.</h4>
<p>First of all, what is a <strong>class</strong>?</p>
<blockquote>
<p>Class is what defines the properties and functions of any functional Entity. Like humans having body parts, clothes, etc.</p>
<p>Collection of objects is known as a class.</p>
<blockquote>
<p>For example, if you are a student studying in a college or school. </p>
<p>Then all the students in your classroom are objects and the classroom itself is a class.
The <code>name</code>, <code>age</code> of a student can be assumed as <strong>variable</strong> and the <code>activities</code> he/she does in his/her whole day can be termed as <strong>methods</strong></p>
<p>Like <code>sleeping()</code>, <code>eating()</code>, <code>crying</code>, <code>studying()</code>, etc</p>
</blockquote>
</blockquote>
<p>Now I think we are done with <code>class</code>, <code>objects</code>, <code>methods</code>. Now let's understand the important principles of OOP</p>
<p>The principles of object-oriented programming are <strong>encapsulation</strong>, <strong>abstraction</strong>, <strong>inheritance</strong>, and <strong>polymorphism</strong>.</p>
<blockquote>
<blockquote>
<p>I know all this is a bit hard to digest, but all these things will help you a lot in your programming journey.</p>
<p>I know these words sound scary, but don't worry they are not that scary as they look.</p>
</blockquote>
<p>I want to give you a short and simple explanation of these words!</p>
<p>Are you ready?</p>
<p>Now Let's Go........</p>
</blockquote>
<p><strong>Encapsulation:</strong></p>
<p>Say we have a program. It has a few logically different objects which communicate with each other — according to the rules defined in the program.</p>
<p>Encapsulation is achieved when each object keeps its state private, inside a class. Other objects don’t have direct access to this state. Instead, they can only call a list of public functions — called methods.</p>
<blockquote>
<p>For example</p>
<blockquote>
<ol>
<li><p>When we buy a new Mobile phone, we don’t see how the circuit board works or how memory is managed. This irrelevant information is hidden. That hidden information is called “Encapsulation”</p>
</li>
<li><p>A capsule. Basically, the capsule encapsulates several combinations of medicine.</p>
</li>
</ol>
<p>If combinations of medicine are variables and methods then the capsule will act as a class and the whole process is called Encapsulation.</p>
</blockquote>
<p>I hope you are done with Encapsulation. If not then please read these examples again. Or else join our <a target="_blank" href="https://t.me/Bufferoverflowdotme">Telegram group</a> only made to help coders with the difficulties they were facing in their programming journey.</p>
</blockquote>
<p><strong>Abstraction:</strong></p>
<p>Abstraction is a process of showing only the necessary data to the end-user.</p>
<blockquote>
<p>For example:</p>
<p>In washing Machine</p>
<blockquote>
<p>We just put dirty clothes and add the washing powder. The washing machine working internally brews the cloths and gives the clean cloths.</p>
<p>You don’t need to know what is happening inside the washing machine. Someone else worried about created a washing machine and that’s acts as “Abstraction” which shows you the only necessary things.</p>
</blockquote>
</blockquote>
<p><strong>Inheritance:</strong></p>
<p>The capability of a class to derive properties and characteristics from another class is called Inheritance.</p>
<blockquote>
<p>For example,</p>
<blockquote>
<p>You are derived from your parents and they had been derived from their parents and ultimately you have some qualities and features of your both parents, and grandparents.</p>
</blockquote>
</blockquote>
<p><strong>Polymorphism:</strong></p>
<p>The word polymorphism means having many forms.</p>
<p><code>Poly</code> means <code>many</code> and <code>morphḗ</code> mean <code>forms</code> in <em>greek</em></p>
<p>In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. </p>
<blockquote>
<p>A real-life example of polymorphism, a person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism. Polymorphism is considered one of the important features of Object-Oriented Programming.</p>
</blockquote>
<hr />
<p>So now we are done with some of the important concepts of OOP, but there's a lot to learn in OOP.</p>
<p>I condensed and summarized all the data available on the web for you.</p>
<p>I hope now you have, some brief idea about OOP.</p>
<p>If you want detailed information about OOP and also want to suggest something to me, please comment and join our <a target="_blank" href="https://t.me/bufferoverflowdotme">Telegram group</a>.</p>
<p>In the next article, we will be getting our hands dirty with some flutter code</p>
<p>Until then, stay home stay safe</p>
<p>Cya :-)</p>
]]></content:encoded></item><item><title><![CDATA[Let's get started with Flutter]]></title><description><![CDATA[Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.

Prere...]]></description><link>https://gulshan.dev/lets-get-started-with-flutter</link><guid isPermaLink="true">https://gulshan.dev/lets-get-started-with-flutter</guid><category><![CDATA[Flutter]]></category><category><![CDATA[newbie]]></category><category><![CDATA[programing]]></category><category><![CDATA[Dart]]></category><category><![CDATA[development]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Sun, 23 May 2021 12:54:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431449882/jaeguHPod.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
</strong></p>
<p><em>Prerequisite: Experience in any programming language which taught you OOP.</em></p>
<blockquote>
<p>Before starting up, please note that you should have min. 8GB of ram in your laptop or computer for coding your Flutter application smoothly.</p>
<p>If you don't have a PC with the required specifications</p>
<p>I would recommend using <a target="_blank" href="https://dartpad.dev/flutter?null_safety=true">Dartpad</a>.</p>
<p>DartPad is a free, open-source online editor to help developers learn about Dart and Flutter.</p>
</blockquote>
<p><a target="_blank" href="https://flutter.dev/docs/get-started/install">Install Flutter Framework </a> </p>
<p>Now after installing Flutter, let's install a text editor, which works best with Flutter.</p>
<p>I recommend using <a target="_blank" href="https://developer.android.com/studio">Android Studio</a>, <a target="_blank" href="https://code.visualstudio.com/">Visual Studio Code</a>, or <a target="_blank" href="https://www.gnu.org/software/emacs/">Emacs</a></p>
<p>And <a target="_blank" href="https://developer.apple.com/xcode/">XCODE</a> for mac users.</p>
<p><strong>Please install a Flutter extension in your respective code Editor.</strong></p>
<blockquote>
<p>This will help you code faster in Flutter</p>
</blockquote>
<p>After setting up your favourite editor for Flutter.</p>
<p>Run:</p>
<pre><code><span class="hljs-attribute">flutter</span> doctor
</code></pre><p>The output should look like this,</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1621766684613/ZB2BysFfq.png" alt="image.png" /></p>
<p>This indicates that we are all set for coding our flutter application.</p>
<p>If there's some error, please fix it or drop a comment below, I will be happy to help you in the process.</p>
<p>So now, after setting up everything, let's jump in the terminal and fire,</p>
<pre><code>flutter <span class="hljs-keyword">create</span> yourprojectname
</code></pre><blockquote>
<p>Please note: 
The name should be all lowercase, with underscores to separate words, just_like<em>this. Use only basic Latin letters and Arabic digits: [a-z0-9</em>]. Also, make sure the name is a valid Dart identifier—that it doesn’t start with digits and isn’t a reserved word.</p>
<p>Try to pick a name that is clear, terse, and not already in use. A quick search of packages on the <a target="_blank" href="pub.dev">pub.dev</a> site to make sure that nothing else is using your name is recommended.</p>
</blockquote>
<p>If you are a windows user, press</p>
<pre><code>ctrl+<span class="hljs-built_in">shift</span>+p
</code></pre><p>This will open the command platelet for you in vs code.
then search an entry that says, create a Flutter application</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1621768011855/2llPr4HCN.png" alt="image.png" /></p>
<p>Now let's jump into your Flutter project.</p>
<p>The things we will be focusing on are the <code>main.dart</code> file inside the <code>lib</code> folder and <code>pubsec.yaml</code> file.</p>
<p>The <code>main.dart</code> contains all our required Flutter code, which we will be working on.
and <code>pubsec.yaml</code> contains the list of assets and the dependencies we will be working on.</p>
<p>Now let`s run the command </p>
<pre><code><span class="hljs-attribute">flutter</span> run
</code></pre><p>For running the sample code in <code>main.dart</code> to build a counter application in your device.</p>
<p>To use your physical Android device, Turn on USB Debugging in Developer mode.</p>
<p>Now run the above command again, if you didn't and you will see your first Flutter application running on your device in debug mode.</p>
<blockquote>
<p>Here's how it will look like,</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1621769821886/3saT-4QFd.png" alt="image.png" /></p>
<p>Let's go through the code written in <code>main.dart</code> file.</p>
<p>The first line of code</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
</code></pre><p>Imports the material code for using the widgets defined in it.</p>
<pre><code><span class="hljs-selector-tag">void</span> <span class="hljs-selector-tag">main</span>() {
  <span class="hljs-selector-tag">runApp</span>(MyApp());
}
</code></pre><p>This is the main function, And it is the entry point of our program. It is the point at which the execution of a program is started. When a program is executed, the execution control goes directly to the main() function.</p>
<p>And here it is running the <code>MyApp()</code> class defined.</p>
<pre><code>
<span class="hljs-selector-tag">class</span> <span class="hljs-selector-tag">MyApp</span> <span class="hljs-selector-tag">extends</span> <span class="hljs-selector-tag">StatelessWidget</span> {
  <span class="hljs-comment">// This widget is the root of your application.</span>
  <span class="hljs-variable">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-selector-tag">return</span> <span class="hljs-selector-tag">MaterialApp</span>(
      <span class="hljs-attribute">title</span>: <span class="hljs-string">'Flutter Demo'</span>,
      <span class="hljs-attribute">theme</span>: ThemeData(
        <span class="hljs-comment">// This is the theme of your application</span>

        <span class="hljs-attribute">primarySwatch</span>: Colors.blue,
        <span class="hljs-comment">//You can play with the name of the color you like :)</span>
      ),
      <span class="hljs-attribute">home</span>: MyHomePage(<span class="hljs-attribute">title</span>: <span class="hljs-string">'Flutter Demo Home Page'</span>),

    );
  }
}
</code></pre><p>This class, I.e. <code>MyApp</code> is a stateless widget, </p>
<blockquote>
<p>Stateless Widgets are those widgets whose state can not be altered once they are built.</p>
</blockquote>
<p><code>@override</code></p>
<blockquote>
<p>The <code>@override</code> annotation expresses the intent that a declaration should override an interface method, something which is not visible from the declaration itself. </p>
</blockquote>
<p>The meaning of Override is</p>
<blockquote>
<p>to use your authority to reject somebody’s decision, order, etc.</p>
</blockquote>
<p>If you didn't understand the use of override, It's okay for now It will get clear when you will start writing your Flutter application.</p>
<p>Let's jump into our next part of the code,</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyHomePage</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatefulWidget</span> </span>{
  MyHomePage({Key? key, <span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.title}) : <span class="hljs-keyword">super</span>(key: key);

<span class="hljs-keyword">final</span> <span class="hljs-built_in">String</span> title;

  <span class="hljs-meta">@override</span>
  _MyHomePageState createState() =&gt; _MyHomePageState();
}
</code></pre><blockquote>
<p>This widget is the home page of your application. It is stateful, meaning that it has a State object (defined below) that contains fields that affect how it looks.</p>
<p>This class is the configuration for the state. It holds the values (in this case the title) provided by the parent (in this case the App widget) and used by the build method of the State. Fields in a Widget subclass are always marked "final".</p>
</blockquote>
<pre><code>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">_MyHomePageState</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">State</span>&lt;<span class="hljs-title">MyHomePage</span>&gt; </span>{
  <span class="hljs-keyword">int</span> _counter = <span class="hljs-number">0</span>;

  <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">_incrementCounter</span><span class="hljs-params">()</span> </span>{
    setState(() {
      <span class="hljs-comment">// This call to setState tells the Flutter framework that something has</span>
      <span class="hljs-comment">// changed in this State, which causes it to rerun the build method below</span>
      <span class="hljs-comment">// so that the display can reflect the updated values. If we changed</span>
      <span class="hljs-comment">// _counter without calling setState(), then the build method would not be</span>
      <span class="hljs-comment">// called again, and so nothing would appear to happen.</span>
      _counter++;
    });
  }

  <span class="hljs-meta">@override</span>
  <span class="hljs-function">Widget <span class="hljs-title">build</span><span class="hljs-params">(BuildContext context)</span> </span>{
    <span class="hljs-comment">// This method is rerun every time setState is called, for instance as done</span>
    <span class="hljs-comment">// by the _incrementCounter method above.</span>
    <span class="hljs-comment">//</span>
    <span class="hljs-comment">// The Flutter framework has been optimized to make rerunning build methods</span>
    <span class="hljs-comment">// fast, so that you can just rebuild anything that needs updating rather</span>
    <span class="hljs-comment">// than having to individually change instances of widgets.</span>
    <span class="hljs-keyword">return</span> Scaffold(
      appBar: AppBar(
        <span class="hljs-comment">// Here we take the value from the MyHomePage object that was created by</span>
        <span class="hljs-comment">// the App.build method, and use it to set our appbar title.</span>
        title: Text(widget.title),
      ),
      body: Center(
        <span class="hljs-comment">// Center is a layout widget. It takes a single child and positions it</span>
        <span class="hljs-comment">// in the middle of the parent.</span>
        child: Column(
          <span class="hljs-comment">// Column is also a layout widget. It takes a list of children and</span>
          <span class="hljs-comment">// arranges them vertically. By default, it sizes itself to fit its</span>
          <span class="hljs-comment">// children horizontally, and tries to be as tall as its parent.</span>
          <span class="hljs-comment">//</span>
          <span class="hljs-comment">// Invoke "debug painting" (press "p" in the console, choose the</span>
          <span class="hljs-comment">// "Toggle Debug Paint" action from the Flutter Inspector in Android</span>
          <span class="hljs-comment">// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)</span>
          <span class="hljs-comment">// to see the wireframe for each widget.</span>
          <span class="hljs-comment">//</span>
          <span class="hljs-comment">// Column has various properties to control how it sizes itself and</span>
          <span class="hljs-comment">// how it positions its children. Here we use mainAxisAlignment to</span>
          <span class="hljs-comment">// center the children vertically; the main axis here is the vertical</span>
          <span class="hljs-comment">// axis because Columns are vertical (the cross axis would be</span>
          <span class="hljs-comment">// horizontal).</span>
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            Text(
              <span class="hljs-string">'You have pushed the button this many times:'</span>,
            ),
            Text(
              <span class="hljs-comment">//Variables which are declared in this class can be accessed by $ symbol </span>
             <span class="hljs-comment">//while in quotes</span>
              <span class="hljs-string">'$_counter'</span>,
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: <span class="hljs-string">'Increment'</span>,
        child: Icon(Icons.add),
      ), <span class="hljs-comment">// This trailing comma makes auto-formatting nicer for build methods.</span>
    );
  }
}
</code></pre><p>This is the extended part of the class MyHomePage as you can see that the ending line of the class MyHomePage says to override and create a state <code>_MyHomePageState</code>.</p>
<p>The rest of the code is properly being explained through comments, Please do read and use them efficiently in your code too.</p>
<p>I would like to suggest you play with this existing code so that one can understand the working of this code.</p>
<p>I will continue this flutter series until I go mad XD</p>
<p>In the next post, I will be building a Flutter application, for teaching you other components and terms related to Flutter development.</p>
<p>Until then, stay home stay safe.</p>
<p>Cya ;-)</p>
]]></content:encoded></item><item><title><![CDATA[What is PipeWire ??]]></title><description><![CDATA[Hello Linux Enthusiasts, Hope you are doing good :)
I have something to share, Named PipeWire and this stuff is more interesting than it looks. 
Earlier Linux distributions use to rely on PulseAudio-, JACK-, ALSA- and GStreamer-based applications for...]]></description><link>https://gulshan.dev/what-is-pipewire</link><guid isPermaLink="true">https://gulshan.dev/what-is-pipewire</guid><category><![CDATA[Linux]]></category><category><![CDATA[music]]></category><category><![CDATA[video]]></category><category><![CDATA[video streaming]]></category><dc:creator><![CDATA[Gulshan Yadav]]></dc:creator><pubDate>Sun, 09 May 2021 14:19:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623431577384/hw2fzd9Ts.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello Linux Enthusiasts, Hope you are doing good :)</p>
<p>I have something to share, Named <strong>PipeWire</strong> and this stuff is more interesting than it looks. </p>
<p>Earlier Linux distributions use to rely on PulseAudio-, JACK-, ALSA- and GStreamer-based applications for their multimedia frameworks to work.</p>
<blockquote>
<p>GStreamer is a multimedia handling library, it uses ALSA/PulseAudio/Jack/PipeWire/etc., but doesn't replace them</p>
</blockquote>
<p>But at the cost of higher latency.</p>
<p>Therefore now to fix this developer created this new low-level multimedia framework named PipeWire from scratch to provide </p>
<ul>
<li>graph-based processing</li>
<li>support for out-of-process processing graphs with minimal overhead</li>
<li>flexible and extensible media format negotiation and buffer allocation</li>
<li>Hard real-time capable plugins</li>
<li>achieve very low latency for both audio and video processing</li>
</ul>
<p>Linux has no unified multimedia framework for exchanging multimedia content between applications or even devices. In most cases, developers realized that a user-space daemon is needed to make this possible:</p>
<ul>
<li>For video content, we typically rely on the compositor to render our
data.</li>
<li>For video capture, we usually go directly to the hardware devices, with
all security implications and inflexible routing that this brings.</li>
<li>For consumer audio, we use PulseAudio to manage and mix multiple streams
from clients</li>
<li>For Pro audio, we use JACK to manage the graph of nodes.</li>
</ul>
<blockquote>
<p>PipeWire
aims to solve this problem and provides a unified framework to run both
consumer and Pro audio as well as video capture and processing in a
secure way.</p>
</blockquote>
<p><strong>Currently PipeWire ships with the following components:</strong></p>
<ul>
<li>a PipeWire daemon that implements the IPC and graph processing</li>
<li>an example session manager that manages objects in the PipeWire
daemon.</li>
<li>a set of tools to introspect and use the PipeWire daemon.</li>
<li>a library to develop PipeWire applications and plugins.</li>
</ul>
<p>I know you didn't understand anything I said until now, Maybe some of you did... but no worries, let me list down some of the usages of PipeWire for you in day to day life</p>
<p><strong>WebRTC screen sharing</strong></p>
<ul>
<li>Most browsers used to rely on X11 for capturing the desktop (or individual applications) when using WebRTC (e.g. on Google Hangouts). On Wayland, the sharing mechanism is handled differently for security reasons. PipeWire enables sharing content under Wayland with fine-grained access controls.</li>
</ul>
<blockquote>
<p>Firefox (84+) supports this method by default, while on Chromium (73+) one needs to enable WebRTC PipeWire support.</p>
<p>Don't know about the X11 and Wayland? No worries, I will post another page on this topic for you :)</p>
<p><strong>For now, just assume that X11 is no more or less secure than any other part of your Linux OS, And Wayland is focused on security</strong></p>
<p>By the way, both are display servers.</p>
</blockquote>
<p><strong>Video</strong></p>
<ul>
<li>Most applications that rely on GStreamer to handle e.g. video streams should work out of the box thanks to the PipeWire GStreamer plugin. Applications like e.g. cheese(camera app in Linux Distros) are therefore already able to share video input using it.</li>
</ul>
<p><strong>Audio</strong></p>
<ul>
<li>PipeWire can be used as an audio server, similar to PulseAudio and JACK. It aims to replace both PulseAudio and JACK, by providing a PulseAudio-compatible server implementation and ABI-compatible libraries for JACK clients.</li>
</ul>
<blockquote>
<p><em>You can ignore that ABI stuff for now if you didn't understand</em> :)</p>
</blockquote>
<p><strong>ALSA/Legacy applications</strong></p>
<p><strong>PulseAudio clients</strong></p>
<p><strong>JACK clients</strong></p>
<p><strong>Bluetooth devices</strong></p>
<p><strong>Run PipeWire on top of native JACK</strong></p>
<blockquote>
<p>Currently(i.e. in May 2021) Fedora 34 ships with PipeWire preinstalled.  So I think you may safely enjoy the features of PipeWire :)</p>
</blockquote>
<p><strong>In Short</strong></p>
<p>PipeWire is a server for handling audio and video streams and hardware on Linux. It was created by Wim Taymans at Red Hat. It handles multimedia routing and pipeline processing.</p>
]]></content:encoded></item></channel></rss>