<?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[Snehal's Blog]]></title><description><![CDATA[Snehal's Blog]]></description><link>https://snehal.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 06:50:41 GMT</lastBuildDate><atom:link href="https://snehal.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Modern Flutter: 6 Tips and Tricks for Beginner Developers]]></title><description><![CDATA[Flutter is a well-liked cross-platform framework that creates stunning and robust mobile and web applications.
Here are some pointers and tricks to help you fully utilize Flutter if you’re a novice developer just getting started with it:

Use the fin...]]></description><link>https://snehal.hashnode.dev/modern-flutter-6-tips-and-tricks-for-beginner-developers</link><guid isPermaLink="true">https://snehal.hashnode.dev/modern-flutter-6-tips-and-tricks-for-beginner-developers</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Dart]]></category><category><![CDATA[tips]]></category><category><![CDATA[tricks]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Snehal Singh]]></dc:creator><pubDate>Thu, 02 Mar 2023 09:00:39 GMT</pubDate><content:encoded><![CDATA[<p>Flutter is a well-liked cross-platform framework that creates stunning and robust mobile and web applications.</p>
<p>Here are some pointers and tricks to help you fully utilize Flutter if you’re a novice developer just getting started with it:</p>
<p><img src="https://miro.medium.com/max/1400/0*NmXsLnfO38v5H-CZ.png" alt /></p>
<h1 id="heading-use-the-final-keyword"><strong>Use the</strong> <code>final</code> keyword:</h1>
<p>In Dart, variables that are initialized and cannot be changed are declared using the <code>final</code> keyword. Your code will become more predictable and help to prevent bugs.</p>
<p>Here’s an example:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">final</span> <span class="hljs-built_in">String</span> name = <span class="hljs-string">'Snehal Singh'</span>;

name = <span class="hljs-string">'Snehal Singh'</span>; <span class="hljs-comment">// Error: The final variable 'name' can't be assigned a value.</span>
</code></pre>
<p>In this example, we declare a variable <code>name</code> and assign it the value 'Snehal Singh'. Since <code>name</code> is declared as <code>final</code>, we cannot reassign it to a new value.</p>
<h1 id="heading-use-named-parameters"><strong>Use named parameters:</strong></h1>
<p>Using named parameters in function calls is supported in Dart, which can improve the readability and comprehension of your code.</p>
<p>You have more control over the order in which arguments are passed to functions when using named parameters.</p>
<p>Here’s an example:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">void</span> greet({<span class="hljs-built_in">String</span> name, <span class="hljs-built_in">String</span> message}) {
  <span class="hljs-built_in">print</span>(<span class="hljs-string">'<span class="hljs-subst">$name</span> says <span class="hljs-subst">$message</span>'</span>);
}

greet(name: <span class="hljs-string">'Snehal Singh'</span>, message: <span class="hljs-string">'Hello, world!'</span>); <span class="hljs-comment">// Snehal Singh says Hello, world!</span>
</code></pre>
<p>In this example, we define a function <code>greet</code> that takes two named parameters, <code>name</code> and <code>message</code>. We can then call the function and pass in the arguments in any order we like, as long as we specify the names of the parameters.</p>
<h1 id="heading-use-null-aware-operators"><strong>Use null-aware operators:</strong></h1>
<p>Dart offers a number of null-aware operators that can make your code shorter and more productive.</p>
<p>For instance, you can safely access the properties of an object that might be null by using the <code>?.</code> operator.</p>
<p>Here's an example:</p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">String</span> name;
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">int</span> age;

  Person({<span class="hljs-keyword">this</span>.name, <span class="hljs-keyword">this</span>.age});
}

<span class="hljs-keyword">final</span> person = Person(name: <span class="hljs-string">'Snehal Singh'</span>, age: <span class="hljs-keyword">null</span>);

<span class="hljs-keyword">final</span> name = person?.name ?? <span class="hljs-string">'Unknown'</span>;
<span class="hljs-keyword">final</span> age = person?.age ?? <span class="hljs-number">-1</span>;

<span class="hljs-built_in">print</span>(name); <span class="hljs-comment">// Snehal Singh</span>
<span class="hljs-built_in">print</span>(age); <span class="hljs-comment">// -1</span>
</code></pre>
<p>In this example, we define a class <code>Person</code> that has two properties, <code>name</code> and <code>age</code>. We create an instance of <code>Person</code> and assign <code>null</code> to the <code>age</code> property. We then use the null-aware operator <code>?.</code> to safely access the <code>name</code> and <code>age</code> properties, and the null-coalescing operator <code>??</code> to provide default values in case they are <code>null</code>.</p>
<h1 id="heading-use-extension-methods"><strong>Use extension methods:</strong></h1>
<p>Using extension methods, Dart lets you add new methods to classes that already have them.</p>
<p>This can be helpful if you want to expand a class’s functionality without changing its source code.</p>
<p>Here’s an example:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">extension</span> StringExtension <span class="hljs-keyword">on</span> <span class="hljs-built_in">String</span> {
  <span class="hljs-built_in">bool</span> <span class="hljs-keyword">get</span> isPalindrome {
    <span class="hljs-keyword">final</span> reversed = <span class="hljs-keyword">this</span>.split(<span class="hljs-string">''</span>).reversed.join(<span class="hljs-string">''</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span> == reversed;
  }
}

<span class="hljs-built_in">print</span>(<span class="hljs-string">'racecar'</span>.isPalindrome); <span class="hljs-comment">// true</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">'hello'</span>.isPalindrome); <span class="hljs-comment">// false</span>
</code></pre>
<p>In this example, we define an extension method <code>isPalindrome</code> on the <code>String</code> class. The method checks if the string is a palindrome and returns <code>true</code> or <code>false</code>.</p>
<h1 id="heading-use-asyncawait"><strong>Use async/await:</strong></h1>
<p>Asynchronous programming is supported in Dart using the <code>async</code> and <code>await</code> keywords.</p>
<p>This can assist you in writing more responsive code that doesn’t obstruct the UI thread.</p>
<p>Here's an example:</p>
<pre><code class="lang-dart">Future&lt;<span class="hljs-keyword">void</span>&gt; main() <span class="hljs-keyword">async</span> {
  <span class="hljs-built_in">print</span>(<span class="hljs-string">'Fetching data...'</span>);
  <span class="hljs-keyword">final</span> data = <span class="hljs-keyword">await</span> fetchSomeData();
  <span class="hljs-built_in">print</span>(<span class="hljs-string">'Data received: <span class="hljs-subst">$data</span>'</span>);
}

Future&lt;<span class="hljs-built_in">String</span>&gt; fetchSomeData() <span class="hljs-keyword">async</span> {
  <span class="hljs-keyword">await</span> Future.delayed(<span class="hljs-built_in">Duration</span>(seconds: <span class="hljs-number">2</span>)); <span class="hljs-comment">// Simulate network delay</span>
  <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello</span>
</code></pre>
<p>In this example, we define a function <code>main</code> that is marked as <code>async</code>. Inside <code>main</code>, we call a function <code>fetchSomeData</code> using the <code>await</code> keyword. This tells Dart to wait for the <code>fetchSomeData</code> function to complete before continuing the execution of the rest of the <code>main</code> function. <code>fetchSomeData</code> simulates a network delay using the <code>Future.delayed</code> function and returns a string.</p>
<p>When we run the <code>main</code> function, we first print a message to the console indicating that we are fetching data. We then call <code>fetchSomeData</code> and wait for it to complete before printing the received data to the console.</p>
<h1 id="heading-use-the-cascade-operator"><strong>Use the cascade operator:</strong></h1>
<p>The cascade operator (<code>..</code>) in Dart enables you to chain together several method calls on the same object.</p>
<p>Your code may become clearer and easier to read as a result.</p>
<p>Here's an example:</p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
  <span class="hljs-built_in">String</span> name;
  <span class="hljs-built_in">int</span> age;

  <span class="hljs-keyword">void</span> sayHello() {
    <span class="hljs-built_in">print</span>(<span class="hljs-string">'Hello, my name is <span class="hljs-subst">$name</span> and I am <span class="hljs-subst">$age</span> years old'</span>);
  }
}

<span class="hljs-keyword">final</span> person = Person()
  ..name = <span class="hljs-string">'Snehal Singh'</span>
  ..age = <span class="hljs-number">30</span>
  ..sayHello(); <span class="hljs-comment">// Hello, my name is Snehal Singh and I am 30 years old</span>
</code></pre>
<p>In this example, we define a class <code>Person</code> that has two properties, <code>name</code> and <code>age</code>, and a method <code>sayHello</code>. We create an instance of <code>Person</code> and use the cascade operator <code>..</code> to set the <code>name</code> and <code>age</code> properties and call the <code>sayHello</code> method in a single chain of method calls.</p>
<p>Please <strong>Follow</strong> 💙 and <strong>clap 👏,</strong> if you find the article useful. And get notified of my upcoming articles.</p>
<p><strong>A little about myself:</strong></p>
<p>I am Snehal Singh, Software developer at <a target="_blank" href="https://dhiwise.com/?utm_campaign=blog&amp;utm_source=medium&amp;utm_medium=cms&amp;utm_term=education&amp;utm_content=modern_flutter_6_tips_and_tricks">DhiWise</a>.<br />DhiWise lets you build React and Flutter Apps at blazing fast speed without compromising on code-quality and developer-experience. Check out <a target="_blank" href="http://app.dhiwise.com/?utm_campaign=blog&amp;utm_source=medium&amp;utm_medium=cms&amp;utm_term=education&amp;utm_content=modern_flutter_6_tips_and_tricks">the platform</a> to know more.</p>
]]></content:encoded></item></channel></rss>