<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shuvojit Kar</title>
    <description>The latest articles on DEV Community by Shuvojit Kar (@shuvojit007).</description>
    <link>https://dev.to/shuvojit007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F66848%2Fd306dcbb-fe7a-49d1-8c83-89971ff61d21.jpeg</url>
      <title>DEV Community: Shuvojit Kar</title>
      <link>https://dev.to/shuvojit007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shuvojit007"/>
    <language>en</language>
    <item>
      <title>18+ Flutter tips and tricks</title>
      <dc:creator>Shuvojit Kar</dc:creator>
      <pubDate>Sat, 09 May 2020 11:12:57 +0000</pubDate>
      <link>https://dev.to/shuvojit007/18-flutter-tips-and-tricks-5cjl</link>
      <guid>https://dev.to/shuvojit007/18-flutter-tips-and-tricks-5cjl</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xjV2-xvw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/psw782jgf7z3dl08tcag.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xjV2-xvw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/psw782jgf7z3dl08tcag.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we were developing the &lt;a href="https://onelink.to/proghero"&gt;Programming Hero&lt;/a&gt; ios app using Flutter, we discovered a few tips, tricks, and libraries. If you are new to this Flutter/Dart world, some of these might help you. 👇&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create Intro Screen in Just 10 Minutes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you need an awesome intro screen but don’t have an awesome idea,&lt;a href="https://pub.dev/packages/introduction_screen"&gt; Introduction Screen&lt;/a&gt; will save you. You'll be amazed. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MgZMD1rb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708627969429602394/introSlider.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MgZMD1rb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708627969429602394/introSlider.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Use Flutter Snippet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you need productivity, Flutter Code Snippet will make you a superstar. You can easily create commonly used Flutter classes and methods. For example, you can create StreamBuilder Widget or SingleChildScrollView Widget by typing the shortcut streamBldr and singleChildSV respectively. You can use the flutter snippet in&lt;a href="https://github.com/benznest/flutter-snippet"&gt; Android Studio&lt;/a&gt; or&lt;a href="https://marketplace.visualstudio.com/items?itemName=Nash.awesome-flutter-snippets"&gt; VSCode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7dwXHl1C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708628308811710503/AwesomeSnippet.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7dwXHl1C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708628308811710503/AwesomeSnippet.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Create Mind-blowing Icons Using Font Awesome&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don’t have to be the designer to include mind-blowing icons in your app. Just use the&lt;a href="https://pub.dev/packages/font_awesome_flutter#-readme-tab-"&gt; font awesome for flutter&lt;/a&gt; and you will create magic in minutes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SWjb2cAx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708629325120929833/FontAwesome.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SWjb2cAx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708629325120929833/FontAwesome.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Enjoy Dependency Magic Using&lt;/strong&gt; &lt;strong&gt;get.it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A good practice is to put your app’s logic in classes separated from your Widgets and then inject it wherever needed. For example, one of my app, we need to access the Prefmanger class from multiple places to read and update the user state stored in the localstorage. We used &lt;a href="https://pub.dev/packages/get_it"&gt; get_it&lt;/a&gt; so that this class can be injectable as a dependency.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;5. Reuse Data Using the Singleton Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Singleton means the class has only one instance and also provides a global point of access to it. It is also an easy one to get wrong if you are not using it carefully. We need to access our ThemeColorclass (dark mode or light mode) again and again to set our theme color in widget . 👇&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;6. Avoid Widget Rebuild by Using&lt;/strong&gt; &lt;strong&gt;const&lt;/strong&gt; &lt;strong&gt;Constructor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to prevent unwanted widget rebuilds always use &lt;strong&gt;const&lt;/strong&gt; constructor. In the code below, the instance of BoxDecoration will remain the same even if the setState is called.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;7. Code Format Using&lt;/strong&gt; &lt;strong&gt;dartfmt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Always add Trailing Commas (,). It will help you to format your code by using &lt;strong&gt;dartfmt&lt;/strong&gt;. After that you will be able to get rid of the headache of formatting by using&lt;a href="https://dart.dev/tools/dartfmt"&gt; dartfmt&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5NJ2APKg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708628629344485446/Trailing_Comma.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5NJ2APKg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708628629344485446/Trailing_Comma.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Write Cleaner Code Using the Spread Operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Dart 2.3 introduced a few useful features and one of them I like is the Spread operator. This is very useful when you need conditional UI widgets. Specially when you have nested conditional UI Widget.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;9. Custom Extension to Reduce Duplicate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t make your code wet 😎. Keep it DRY. Here the word DRY means — Don’t Repeat Yourself. Hence, you should not repeat the same functionality in multiple places.&lt;/p&gt;

&lt;p&gt;In my app, I need to convert HTML tags to be displayed on the UI because mighty Flutter is still reluctant to support HTML tags. And, we needed to repeat the code below in several places. That's why I created an&lt;a href="https://dart.dev/guides/language/extension-methods"&gt; extension method&lt;/a&gt; that can be used anywhere needed.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;10. Less Code Using Double Dot, The Cascade Operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dart has a single dot (.) operator. And a few minutes ago, we talked about three dots (…) . So, one and three dots are covered. Do you feel like anything missing in the middle? You got it correctly. We are talking about the middle person, the double dot (..) which is also known as the&lt;a href="https://www.w3adda.com/dart-tutorial/dart-cascade-notation"&gt; cascadeoperator&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can use the cascade operator to save typing time when multiple method calls on the same object are being made.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;11. Knock Out the iPhone Notch with Safe Area&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s a pain that some of your content is getting cut by the iPhone 10+ notch. The same could happen in Android.&lt;/p&gt;

&lt;p&gt;Consider using the&lt;a href="https://api.flutter.dev/flutter/widgets/SafeArea-class.html"&gt; SafeArea widget&lt;/a&gt; can keep the pesky notification bars and phone notches from encroaching on your app’s UI. It uses a MediaQuery to check the dimensions of the screen and pads its child Widget to match, making sure your app is safe on both iOS and Android!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. Use Key for Efficient ListView Rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make rendering efficient,&lt;a href="https://flutter.dev/docs/development/ui/widgets-intro#keys"&gt; use keys&lt;/a&gt; on each item. This will make your list view rendering very efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. Efficient Debugging with Performance Overlay&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Performance Overlay shows how long each frame took to build and at the top there is the GPU time (Raster Thread) and at the bottom is Ui Time (Ui Thread). If you see a red bar in the UI graph, the Dart code is too expensive. If a red vertical bar appears in the GPU graph, the scene is too expensive to render.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vh41IHCS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708629827229581313/profiling.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vh41IHCS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.discordapp.com/attachments/446181146989035531/708629827229581313/profiling.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Avoid Profiling in the Debug Mode&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You will not get accurate performance indication if you profile in the debug mode. Debug mode is by default much slower than production mode. Simulator/ Emulator is not indicative of how your app actually works in Real Device.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. Use Tracing to Measure Execution Time&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You might not know how much time you took to finish your job in the bathroom. However, you can use the Tracing to see how much time is taken to execute.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;16. Declare Multiple Variables with Shortcut&lt;/strong&gt; Usually, I declare my variable most of the time this way&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;But if you are lazy like me than you can also do these things this way&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;17. Smart Logging, Log Anything&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Though we are used to log the string message, we can also pass other objects like List, Map, or Set. For more about log level, logPrinter, logOutput, checkout the&lt;a href="https://pub.dev/packages/logger#-readme-tab-"&gt; logger doc&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;18. Set Cross-Platform Icons Like a Pro&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Are you messed up to set icons for both the Android and the iOS version of your app? Don’t worry, I will give you two steps to handle it using the&lt;a href="https://pub.dev/packages/flutter_launcher_icons"&gt; Flutter Launcher Icon&lt;/a&gt;. First, setup your config file.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;18+. Get That Level Powered by Basic Utils&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do you need extra power in some crucial moments? Consider using basic_util. It contains a list of amazing methods to give you productivity at the right time. For more utils like SortUtils, ColorUtils, DateUtils, IterableUtils, CryptoUtils, HttpUtils in the&lt;a href="https://pub.dev/packages/basic_utils#-readme-tab-"&gt; basic utils&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let me know the tips &amp;amp; tricks that you discovered while developing your flutter app.&lt;/p&gt;

&lt;p&gt;Please feel free to check out our &lt;a href="https://onelink.to/proghero"&gt;app&lt;/a&gt; built with Flutter.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>android</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
