<?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>Forem: Narendran</title>
    <description>The latest articles on Forem by Narendran (@nrndev).</description>
    <link>https://forem.com/nrndev</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%2F329446%2Fd20c26dc-bc7a-4998-a168-9aa96b44b33b.jpeg</url>
      <title>Forem: Narendran</title>
      <link>https://forem.com/nrndev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nrndev"/>
    <language>en</language>
    <item>
      <title>Hitchhikers Guide to flutter from the JS world</title>
      <dc:creator>Narendran</dc:creator>
      <pubDate>Wed, 05 Feb 2020 00:41:51 +0000</pubDate>
      <link>https://forem.com/nrndev/hitchhikers-guide-to-flutter-from-the-js-world-4b26</link>
      <guid>https://forem.com/nrndev/hitchhikers-guide-to-flutter-from-the-js-world-4b26</guid>
      <description>&lt;p&gt;Every day it's the dawn of a new framework that has the potential to overthrow the existing one. This will be a series that focus on introducing flutter to the mass of the JS world. This series will be building from the ground up to the advanced level and I'll be guiding you through this journey. So, let our journey begin...&lt;/p&gt;

&lt;h2&gt;
  
  
  Epilogue
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;The year is 2020, a year over since the first &lt;a href="https://flutter.dev/docs/development/tools/sdk/releases" rel="noopener noreferrer"&gt;stable release&lt;/a&gt; of Flutter. Flutter is changing the way we look at developing for multiple platforms with a single code base. With the stable version of flutter, we can create **IOS&lt;/em&gt;* &amp;amp; &lt;strong&gt;Android&lt;/strong&gt; apps and support for creating apps for the web is in beta version and for macOS in alpha(which is under active development). The flutter team is working hard to get support for Linux and Windows support too.*&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Lets understand the ecosystem of the flutter&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;Flutter is an opensource framework that is built on top of &lt;a href="https://dart.dev/" rel="noopener noreferrer"&gt;Dart&lt;/a&gt; programming language. Being said, Dart is a c syntax, statically typed, Object-oriented programming (&lt;code&gt;OOP&lt;/code&gt;) language which adds lots of benefits to the flutter.&lt;br&gt;
Flutter comes with hot reload the much-liked attribute of reactjs for us in the JS world, which makes us see the changes made to the app instantly. &lt;br&gt;
Flutter repaints every widget*{? yes, the building blocks of flutter app, just like components in reactjs}* on the screen at 60 FPS, which makes the User Interface feel smooth. It's due to Flutter comes with &lt;a href="https://skia.org/" rel="noopener noreferrer"&gt;skia&lt;/a&gt; an open-source 2D graphics library, which makes animations snappier and crisp.&lt;br&gt;
Flutter comes with much-loved Google's material design built-in, which makes UI development a lot faster.&lt;br&gt;
To install flutter in your system please &lt;a href="https://flutter.dev/docs/get-started/install" rel="noopener noreferrer"&gt;follow this guide&lt;/a&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The latest stable version of flutter is v1.12.13+hotfix.7 &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For us folks in the JS world, we are well aware of &lt;code&gt;package.json&lt;/code&gt; and npm registry &lt;code&gt;{no problem managed or never pressure me}&lt;/code&gt;  as they are the management system for packages in our builds and experiments.&lt;/p&gt;

&lt;p&gt;In flutter world, external packages are called as &lt;code&gt;pub&lt;/code&gt; packages and they are managed in &lt;code&gt;pubspec.yaml&lt;/code&gt; file &lt;em&gt;{yes, flutter team went with YAML file format than the ever beloved JSON file }&lt;/em&gt;. There's a central pub package registry, it's the &lt;strong&gt;&lt;a href="https://pub.dev" rel="noopener noreferrer"&gt;pub.dev&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In short: package.json --&amp;gt; pubspec.yaml , npmjs.com --&amp;gt; pub.dev&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Flutter supports &lt;a href="https://flutter.dev/docs/get-started/editor?tab=androidstudio" rel="noopener noreferrer"&gt;Android studio ide, IntelliJ IDEA ide&lt;/a&gt; and the most loved &lt;strong&gt;&lt;a href="https://flutter.dev/docs/get-started/editor?tab=vscode" rel="noopener noreferrer"&gt;VScode&lt;/a&gt;&lt;/strong&gt; editor for development. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I love writing flutter code in vscode (I'm based on it, leave your comments on what you think.){when I say "writing flutter code" I actually mean writing &lt;strong&gt;&lt;code&gt;dart&lt;/code&gt;&lt;/strong&gt; code }&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Good news to us curious folks out there who want to experiment with flutter environment before going through all the hassle installing (something like &lt;code&gt;code sandbox&lt;/code&gt; for flutter) of was announced during flutter interact 2019 (which happened in 11 DEC 2019).Completely revamped &lt;strong&gt;&lt;a href="https://dartpad.dev/31a6e82694f2e28b851ec7abb60843d2" rel="noopener noreferrer"&gt;DartPad&lt;/a&gt;&lt;/strong&gt;, where we can try on.&lt;code&gt;(dartpad has its limitations such as doesn’t support dart:io or libraries from pub.dev)&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Since this is the epilogue we'll stick to dartpad to get familiar with flutter.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Buckle up for our journey to Flutter
&lt;/h3&gt;

&lt;p&gt;Dart is the language of the flutter world, yet when dealing with flutter we have to know the framework-specific syntax way to write clean code.&lt;br&gt;
Back in our JS world, we are much familiar with &lt;strong&gt;&lt;code&gt;stateful&lt;/code&gt; &amp;amp; &lt;code&gt;stateless&lt;/code&gt; class components&lt;/strong&gt;.In flutter, we have &lt;code&gt;StatefulWidget&lt;/code&gt; &amp;amp; &lt;code&gt;StatelessWidget&lt;/code&gt; class &lt;strong&gt;widgets&lt;/strong&gt; which are the basic building blocks.&lt;/p&gt;

&lt;p&gt;Let's write our first flutter app.&lt;br&gt;
We have to import flutter's material package to take advantage of the built-in Material design, &lt;code&gt;import 'package:flutter/material.dart';&lt;/code&gt;.Since Dart is statically typed language we need to have a &lt;code&gt;main()&lt;/code&gt; function which will invoke the app. In flutter, our app is started by calling the root widget &lt;code&gt;runApp()&lt;/code&gt; in &lt;code&gt;main()&lt;/code&gt;-function.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As mentioned above, everything in flutter is a widget, either the class extends a &lt;code&gt;StatefulWidget&lt;/code&gt; or &lt;code&gt;StatelessWidget&lt;/code&gt; to build that. In reactjs, we'll render each and every component to the screen, whereas in flutter we build it with passing the BuildContext context.BuildContext is used by flutter to manage the internal state of the widget in the widget tree. Every widget has its own buildContext. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here, we need to override the build with the &lt;code&gt;@override&lt;/code&gt; decorator every time inside &lt;code&gt;StatefulWidget&lt;/code&gt; and &lt;code&gt;StatelessWidget&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The annotation &lt;a href="https://api.dart.dev/stable/2.7.1/dart-core/override-constant.html" rel="noopener noreferrer"&gt;@override&lt;/a&gt; marks an instance member as overriding a superclass member with the same name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here comes the fun part. We return &lt;code&gt;MaterialApp&lt;/code&gt; widget which is imported from the inbuilt material package &lt;code&gt;import 'package:flutter/material.dart';&lt;/code&gt;.The MaterialApp widget has given us the power of Google's material design. &lt;br&gt;
MaterialApp widget comes with loads of properties, yet our focus will remain on &lt;code&gt;home&lt;/code&gt; widget which is for the default route of the app. To &lt;code&gt;home&lt;/code&gt;, we assign the &lt;code&gt;Scaffold&lt;/code&gt; widget which comes with the pre-configured material visual layout which is highly customizable. &lt;br&gt;
&lt;code&gt;Scaffold&lt;/code&gt; has the &lt;code&gt;body&lt;/code&gt; property, which is responsible for the painting the body of the page(all the area below appBar).&lt;br&gt;
To write something on the body, we use the &lt;code&gt;Text&lt;/code&gt; widget, which takes a string as the input. &lt;em&gt;(To carry forward the tradition of programming, let's give "Hello world")&lt;/em&gt;. Check out the live version &lt;a href="https://dartpad.dev/ecabc097cb627cdc8db1b6835a9b3aab" rel="noopener noreferrer"&gt;here&lt;/a&gt; Look at the top left corner to see our &lt;code&gt;hello world&lt;/code&gt;, so tiny, we'll style it.&lt;/p&gt;


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

&lt;blockquote&gt;
&lt;p&gt;In dart, for most cases we don't have to explicitly import methods from the package as we do in JS world. But there are certain cases where we need to do explicit imports, now we don't need to worry about it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Let's style our app
&lt;/h4&gt;

&lt;p&gt;In the JS world, we have all sorts of way to style {for eg. inline styles, css-in-js, css modules, SASS,LESS, etc}.In flutter, we style our widgets there and then, if you are used to css-in-js type styling you'll love the styling in flutter.&lt;br&gt;
Let's first center our &lt;code&gt;hello world&lt;/code&gt; with the help of &lt;code&gt;Center&lt;/code&gt; widget, we assign a widget to another by using &lt;code&gt;child&lt;/code&gt; or &lt;code&gt;children&lt;/code&gt; property depending on the number of widgets it accepts.&lt;br&gt;
&lt;code&gt;Center&lt;/code&gt; widget takes only one child widget, so let's &lt;a href="https://dartpad.dev/772524a3660aeb83aedffe648446471e" rel="noopener noreferrer"&gt;refactor like this&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now let's tweak the color, font size, font weight, font style.&lt;code&gt;Text&lt;/code&gt; widget has &lt;code&gt;style&lt;/code&gt; property which takes &lt;code&gt;TextStyle&lt;/code&gt; class, where we can set these.&lt;br&gt;
&lt;code&gt;fontSize&lt;/code&gt; property takes a double value (float value for us from JS world), &lt;code&gt;fontStyle&lt;/code&gt; property  takes a FontStyle enum, &lt;code&gt;fontWeight&lt;/code&gt; takes values from FontWeight.[ w100,w200,w300,w400,w500,w600,w700,w800,w900,bold,normal]. &lt;code&gt;color&lt;/code&gt;property takes in full 8 hexadecimal digits or with rgba or with rgbo or with a &lt;code&gt;Colors&lt;/code&gt; enum. Let's set them &lt;a href="https://dartpad.dev/4b5593acb859fb28a4a36e44633e1b69" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We have done some basic styles and built a simple widget with flutter. Now, let's create our own Beautiful widget called &lt;code&gt;SmoothWidget&lt;/code&gt; which is a StatelessWidget.&lt;br&gt;
Let's put &lt;code&gt;@override&lt;/code&gt; and &lt;code&gt;Widget build(BuildContext context)&lt;/code&gt; and then return our new &lt;code&gt;Container&lt;/code&gt; widget. &lt;code&gt;Container&lt;/code&gt; can be considered as &lt;code&gt;div&lt;/code&gt; equivalent in the JS world, it returns a single child. There's a lot of property &lt;code&gt;Container&lt;/code&gt; exposes which are easy and useful. We can set the width and height of the container with &lt;code&gt;width&lt;/code&gt; &amp;amp; &lt;code&gt;height&lt;/code&gt; property respectively, they take double as their value. We can decorate the &lt;code&gt;Container&lt;/code&gt; with &lt;code&gt;decoration&lt;/code&gt;, which accepts &lt;code&gt;BoxDecoration&lt;/code&gt; where we can set the &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;borderRadius&lt;/code&gt;,&lt;code&gt;border&lt;/code&gt; etc.&lt;br&gt;
Cut out the &lt;code&gt;Center&lt;/code&gt; widget along with its child and put it as the child of &lt;code&gt;Container&lt;/code&gt;. Vola, our new widget is &lt;a href="https://dartpad.dev/a7a53b96a3c7f5fdf02183dc8d60917a" rel="noopener noreferrer"&gt;ready&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; class SmoothWidget extends StatelessWidget{
   @override
   Widget build(BuildContext context){
     return Container(
        width: 200.0,
        height: 200.0,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(25.0),
          color: Colors.cyan,
          border: Border.all(color: Colors.black, width: 6.0),
        ),
        child: Center(
          child: Text(
            "Hello World",
            style: TextStyle(
                fontSize: 26.0,
                fontStyle: FontStyle.italic,
                fontWeight: FontWeight.bold,
                color: Colors.amber),
          ),
        ),
     );
  } 
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;But we see a problem, it's fixed to the top-left. It's easy to fix, wrap the return with the &lt;code&gt;center&lt;/code&gt; widget and assign &lt;code&gt;container&lt;/code&gt; as a child to it.Now, it's &lt;a href="https://dartpad.dev/18b533e16552a211de7da7815579427f" rel="noopener noreferrer"&gt;fixed&lt;/a&gt;&lt;/p&gt;


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



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;debugShowCheckedModeBanner&lt;/code&gt; is one of the properties exposed by the &lt;code&gt;MaterialApp&lt;/code&gt; widget, it takes a boolean value by default it is true. Explicit assigning of false takes away the debug sticker from the top right corner.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Are we there?
&lt;/h4&gt;

&lt;p&gt;This is the simple introduction to the flutter ecosystem, there's a lot to cover in the upcoming post such as Dart language, other awesome flutter widgets, stateFulWidgets lifecycle, Animations, Beautiful UI, platform-specific integration, etc. From the upComing post, we'll switch to a local flutter environment and we'll have our beloved Dash bird (flutter mascot)  be with us to guide to his planet.&lt;br&gt;
Till then, see you.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;this is my first ever blog. Looking forward to your feedback and comments.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
