<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dart Archives - CodeJourney.net</title>
	<atom:link href="https://www.codejourney.net/tag/dart/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codejourney.net/tag/dart/</link>
	<description>Become a better .NET full stack web developer</description>
	<lastBuildDate>Thu, 16 Jan 2020 04:15:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://i0.wp.com/www.codejourney.net/wp-content/uploads/2018/10/cropped-512px-na-512px-JPEG-BEZ-NAPISU-1.jpg?fit=32%2C32&#038;ssl=1</url>
	<title>dart Archives - CodeJourney.net</title>
	<link>https://www.codejourney.net/tag/dart/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">123174533</site>	<item>
		<title>Basics of Flutter Widgets</title>
		<link>https://www.codejourney.net/basics-of-flutter-widgets/</link>
					<comments>https://www.codejourney.net/basics-of-flutter-widgets/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Thu, 16 Jan 2020 16:00:59 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[dart]]></category>
		<category><![CDATA[flutter]]></category>
		<guid isPermaLink="false">https://www.codejourney.net/?p=3715</guid>

					<description><![CDATA[<p>What is a widget? If you ever worked with a web framework like React, you should know the concept of components. Flutter widgets are directly inspired by this idea. Widget is a reusable piece of code, which describes how your application&#8217;s UI looks like. Widgets define the user interface by their state. In some cases,&#8230;</p>
<p>The post <a href="https://www.codejourney.net/basics-of-flutter-widgets/">Basics of Flutter Widgets</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>After <a href="https://www.codejourney.net/2019/12/your-first-flutter-app-in-30-minutes/" target="_blank" rel="noopener noreferrer">writing our first Flutter app in less than 30 minutes</a>, today we&#8217;re taking a look at Flutter widgets. If you want to know what is a widget in Flutter, what are widgets types and how to use them &#8211; this article is for you <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<span id="more-3715"></span>



<h2 class="wp-block-heading">What is a widget?</h2>



<p>If you ever worked with a web framework like <a rel="noreferrer noopener" aria-label="React (opens in a new tab)" href="https://reactjs.org/" target="_blank">React</a>, you should know the concept of <em>components</em>. Flutter widgets are directly inspired by this idea. Widget is a <strong>reusable piece of code, which describes how your application&#8217;s UI looks like</strong>. Widgets define the user interface by their <strong>state</strong>. In some cases, the state can be static and not change over time &#8211; see the <a href="#flutter-widget-types">section below about Flutter widget types</a> for details.</p>



<p>As soon as a widget&#8217;s state changes, Flutter rebuilds its outlook and in effect re-renders the GUI. The framework is said to do it efficiently by measuring what has changed in the widgets tree since the last rendering and re-paints only what&#8217;s necessary.</p>



<p>The most basic Flutter app might look as follows:</p>



<figure class="wp-block-embed"><div class="wp-block-embed__wrapper">
<style>.gist table { margin-bottom: 0; }</style><div style="tab-size: 8" id="gist100539783" class="gist">
    <div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
      <div class="gist-data">
        <div class="js-gist-file-update-container js-task-list-container">
  <div id="file-main_simplest_app-dart" class="file my-2">
    
    <div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-dart  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="main_simplest_app.dart content, created by dsibinski on 02:13AM on January 13, 2020."
    >

        
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">

  <template class="js-file-alert-template">
  <div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
    <span>
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a>
    </span>


  <div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters
</a>
</div>
</div></template>
<template class="js-line-alert-template">
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e">
    <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
</span></template>

  <table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="main_simplest_app.dart">
        <tr>
          <td id="file-main_simplest_app-dart-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
          <td id="file-main_simplest_app-dart-LC1" class="blob-code blob-code-inner js-file-line">import &#39;package:flutter/material.dart&#39;;</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
          <td id="file-main_simplest_app-dart-LC2" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
          <td id="file-main_simplest_app-dart-LC3" class="blob-code blob-code-inner js-file-line">void main() =&gt; runApp(</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
          <td id="file-main_simplest_app-dart-LC4" class="blob-code blob-code-inner js-file-line">      Center(</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
          <td id="file-main_simplest_app-dart-LC5" class="blob-code blob-code-inner js-file-line">          child: Text(</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
          <td id="file-main_simplest_app-dart-LC6" class="blob-code blob-code-inner js-file-line">        &quot;Hello Flutter!&quot;,</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
          <td id="file-main_simplest_app-dart-LC7" class="blob-code blob-code-inner js-file-line">        textDirection: TextDirection.ltr,</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
          <td id="file-main_simplest_app-dart-LC8" class="blob-code blob-code-inner js-file-line">      )),</td>
        </tr>
        <tr>
          <td id="file-main_simplest_app-dart-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
          <td id="file-main_simplest_app-dart-LC9" class="blob-code blob-code-inner js-file-line">    );</td>
        </tr>
  </table>
</div>


    </div>

  </div>
</div>

      </div>
      <div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/e950a3cd710a539359a855752900c295/raw/23a6fec940a3c5e420ab9483a585f9ea495345d4/main_simplest_app.dart" style="float:right" class="Link--inTextBlock">view raw</a>
        <a href="https://gist.github.com/dsibinski/e950a3cd710a539359a855752900c295#file-main_simplest_app-dart" class="Link--inTextBlock">
          main_simplest_app.dart
        </a>
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
    </div>
</div>

</div></figure>



<p>The<span style="color:#bb9d1b" class="tadv-color"> </span><span style="color:#f7bb1e" class="tadv-color">runApp()</span> method takes a <span style="color:#f7bb1e" class="tadv-color">Widget</span> as its argument. In our case, it takes a <span style="color:#f7bb1e" class="tadv-color">Center</span> widget, which has one child &#8211; a <span style="color:#f7bb1e" class="tadv-color">Text</span> widget. As expected, such a simple Flutter app shows a &#8220;Hello Flutter!&#8221; text at the center of the screen.</p>



<p>This simple example shows us a few interesting facts:</p>



<ul class="wp-block-list"><li>there are <strong>many built-in widgets</strong>, like <span style="color:#f7bb1e" class="tadv-color">Center</span> and <span style="color:#f7bb1e" class="tadv-color">Text</span></li><li><strong>widgets can have a child or children</strong> &#8211; this is <em>widgets nesting</em> and it happens all the time and can be very deep</li><li>Flutter <strong>widgets can have their own properties</strong>, like <span style="color:#f7bb1e" class="tadv-color">textDirection</span>.</li></ul>



<p>Widgets nesting sometimes makes simple Flutter apps having a lot of source code inside a single file. However, as I mentioned in <a rel="noreferrer noopener" aria-label="the previous post (opens in a new tab)" href="https://www.codejourney.net/2019/12/your-first-flutter-app-in-30-minutes/" target="_blank">the previous post</a>, don&#8217;t get discouraged by that <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Actually, <strong>having a lot of nested widgets in Flutter is a good practice</strong>. If you have a few huge widgets without much nesting instead, it means that there&#8217;s something wrong with your implementation. Flutter widgets &#8211; as all reusable pieces of code &#8211; should not have too many responsibilities. <a rel="noreferrer noopener" aria-label="SOLID (opens in a new tab)" href="https://en.wikipedia.org/wiki/SOLID" target="_blank">SOLID</a> also applies here <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading">Viewing Flutter widgets with Flutter Inspector</h2>



<p>As widgets tree may get big and quite heavily nested, there&#8217;s a very useful tool to easily view and explore it. This tool is called <a rel="noreferrer noopener" aria-label="Flutter Inspector (opens in a new tab)" href="https://flutter.dev/docs/development/tools/devtools/inspector" target="_blank">Flutter Inspector</a>.</p>



<p>While in debug mode in Visual Studio Code, you can launch it by clicking the blue magnifier icon:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="866" height="174" data-attachment-id="3727" data-permalink="https://www.codejourney.net/basics-of-flutter-widgets/image/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?fit=866%2C174&amp;ssl=1" data-orig-size="866,174" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?fit=300%2C60&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?fit=866%2C174&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?resize=866%2C174&#038;ssl=1" alt="Flutter Widgets: blue magnifier button in VS Code which opens the widgets inspector" class="wp-image-3727" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?w=866&amp;ssl=1 866w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?resize=300%2C60&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?resize=768%2C154&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image.png?resize=676%2C136&amp;ssl=1 676w" sizes="(max-width: 866px) 100vw, 866px" /><figcaption>A button for opening Flutter Widgets Inspector from VS Code</figcaption></figure>



<p>It opens in a web browser and allows you to see the whole widgets tree in your app:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" width="950" height="1025" data-attachment-id="3728" data-permalink="https://www.codejourney.net/basics-of-flutter-widgets/image-1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?fit=950%2C1025&amp;ssl=1" data-orig-size="950,1025" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image-1" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?fit=278%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?fit=950%2C1025&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?resize=950%2C1025&#038;ssl=1" alt="Flutter Widgets: Dart DevTools widgets inspector" class="wp-image-3728" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?w=950&amp;ssl=1 950w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?resize=278%2C300&amp;ssl=1 278w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?resize=768%2C829&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/image-1.png?resize=676%2C729&amp;ssl=1 676w" sizes="(max-width: 950px) 100vw, 950px" /><figcaption>Flutter Inspector (part of Dart DevTools)</figcaption></figure>



<p>There&#8217;s a very handy feature &#8220;Select Widget Mode&#8221; which, when enabled, lets you select the widgets directly in your emulator or phone. After doing this, you can see the selected widget&#8217;s properties in the inspector.</p>



<h2 class="wp-block-heading" id="flutter-widget-types">Types of Flutter widgets</h2>



<p>In Flutter, you can &#8211; and will &#8211; create your own widgets. Widget is just a Dart class which extends a proper base class. Depending on whether your widget actually manages any state and changes over time, you have two types of base classes to inherit from &#8211; <a rel="noreferrer noopener" aria-label="StatelessWidget (opens in a new tab)" href="https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html" target="_blank">StatelessWidget</a> or <a rel="noreferrer noopener" aria-label="StatefulWidget (opens in a new tab)" href="https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html" target="_blank">StatefulWidget</a>.</p>



<p>The main purpose of each type of widget is to provide an implementation of a <span style="color:#f7bb1e" class="tadv-color">build() </span>method which returns a <span style="color:#f7bb1e" class="tadv-color">Widget</span> object. However, each widget type does it a bit differently. Let&#8217;s see this in action.</p>



<h3 class="wp-block-heading">StatelessWidgets</h3>



<p>The simplest widget you can create is a stateless widget. You create it by simply creating a class extending <a rel="noreferrer noopener" href="https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html" target="_blank">StatelessWidget</a>.  Here&#8217;s the sample source code and a view it generates:</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-embed alignwide"><div class="wp-block-embed__wrapper">
<style>.gist table { margin-bottom: 0; }</style><div style="tab-size: 8" id="gist100563362" class="gist">
    <div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
      <div class="gist-data">
        <div class="js-gist-file-update-container js-task-list-container">
  <div id="file-main_stateless_widget-dart" class="file my-2">
    
    <div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-dart  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="main_stateless_widget.dart content, created by dsibinski on 03:36AM on January 14, 2020."
    >

        
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">

  <template class="js-file-alert-template">
  <div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
    <span>
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a>
    </span>


  <div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters
</a>
</div>
</div></template>
<template class="js-line-alert-template">
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e">
    <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
</span></template>

  <table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="main_stateless_widget.dart">
        <tr>
          <td id="file-main_stateless_widget-dart-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
          <td id="file-main_stateless_widget-dart-LC1" class="blob-code blob-code-inner js-file-line">import &#39;package:flutter/material.dart&#39;;</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
          <td id="file-main_stateless_widget-dart-LC2" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
          <td id="file-main_stateless_widget-dart-LC3" class="blob-code blob-code-inner js-file-line">void main() =&gt; runApp(</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
          <td id="file-main_stateless_widget-dart-LC4" class="blob-code blob-code-inner js-file-line">      MaterialApp(</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
          <td id="file-main_stateless_widget-dart-LC5" class="blob-code blob-code-inner js-file-line">        title: &quot;My CodeJourney Flutter app&quot;,</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
          <td id="file-main_stateless_widget-dart-LC6" class="blob-code blob-code-inner js-file-line">        home: Scaffold(</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
          <td id="file-main_stateless_widget-dart-LC7" class="blob-code blob-code-inner js-file-line">          appBar: AppBar(</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
          <td id="file-main_stateless_widget-dart-LC8" class="blob-code blob-code-inner js-file-line">            title: Text(&quot;My First App&quot;),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
          <td id="file-main_stateless_widget-dart-LC9" class="blob-code blob-code-inner js-file-line">          ),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
          <td id="file-main_stateless_widget-dart-LC10" class="blob-code blob-code-inner js-file-line">          body: MyFirstWidget(),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
          <td id="file-main_stateless_widget-dart-LC11" class="blob-code blob-code-inner js-file-line">        ),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
          <td id="file-main_stateless_widget-dart-LC12" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
          <td id="file-main_stateless_widget-dart-LC13" class="blob-code blob-code-inner js-file-line">    );</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
          <td id="file-main_stateless_widget-dart-LC14" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
          <td id="file-main_stateless_widget-dart-LC15" class="blob-code blob-code-inner js-file-line">class MyFirstWidget extends StatelessWidget {</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
          <td id="file-main_stateless_widget-dart-LC16" class="blob-code blob-code-inner js-file-line">  @override</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
          <td id="file-main_stateless_widget-dart-LC17" class="blob-code blob-code-inner js-file-line">  Widget build(BuildContext context) {</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
          <td id="file-main_stateless_widget-dart-LC18" class="blob-code blob-code-inner js-file-line">    return Container(</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
          <td id="file-main_stateless_widget-dart-LC19" class="blob-code blob-code-inner js-file-line">      padding: EdgeInsets.all(8.0),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
          <td id="file-main_stateless_widget-dart-LC20" class="blob-code blob-code-inner js-file-line">      child: Text(</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
          <td id="file-main_stateless_widget-dart-LC21" class="blob-code blob-code-inner js-file-line">        &quot;Hello MyFirstWidget!&quot;,</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
          <td id="file-main_stateless_widget-dart-LC22" class="blob-code blob-code-inner js-file-line">        style: TextStyle(color: Colors.green),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
          <td id="file-main_stateless_widget-dart-LC23" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
          <td id="file-main_stateless_widget-dart-LC24" class="blob-code blob-code-inner js-file-line">    );</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
          <td id="file-main_stateless_widget-dart-LC25" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-main_stateless_widget-dart-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
          <td id="file-main_stateless_widget-dart-LC26" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
  </table>
</div>


    </div>

  </div>
</div>

      </div>
      <div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/1a26fa1e212adbb858230f62183f7109/raw/28bd7f47b938fc6d295f3700c2550c5efe902b44/main_stateless_widget.dart" style="float:right" class="Link--inTextBlock">view raw</a>
        <a href="https://gist.github.com/dsibinski/1a26fa1e212adbb858230f62183f7109#file-main_stateless_widget-dart" class="Link--inTextBlock">
          main_stateless_widget.dart
        </a>
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
    </div>
</div>

</div></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image alignwide size-large"><img decoding="async" width="1080" height="1920" data-attachment-id="3731" data-permalink="https://www.codejourney.net/basics-of-flutter-widgets/flutter_statelesswidget/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_statelessWidget" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?fit=169%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?fit=576%2C1024&amp;ssl=1" src="https://i1.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?fit=576%2C1024&amp;ssl=1" alt="" class="wp-image-3731" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?resize=864%2C1536&amp;ssl=1 864w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statelessWidget.png?resize=676%2C1202&amp;ssl=1 676w" sizes="(max-width: 1080px) 100vw, 1080px" /></figure>


</div>
</div>



<p>You can play with it yourself <a rel="noreferrer noopener" aria-label="in the DartPad (opens in a new tab)" href="https://dartpad.dev/1a26fa1e212adbb858230f62183f7109" target="_blank">in the DartPad</a>.</p>



<p>There are quite a few new things in the source code. Let&#8217;s point them out:</p>



<ul class="wp-block-list"><li>as our main widget, we used <span style="color:#f7bb1e" class="tadv-color">MaterialApp</span> and provided it to <span style="color:#f7bb1e" class="tadv-color">runApp()</span> method. MaterialApp widget gives us material design for our app out of the box. As soon as you use it, you can nest more material widgets from the <a rel="noreferrer noopener" aria-label="widgets library (opens in a new tab)" href="https://flutter.dev/docs/development/ui/widgets/material" target="_blank">widgets library</a>. There&#8217;s a similar widget for Apple-oriented widgets called <a rel="noreferrer noopener" aria-label="CupertinoApp (opens in a new tab)" href="https://api.flutter.dev/flutter/cupertino/CupertinoApp-class.html" target="_blank">CupertinoApp</a>, which allows using <a rel="noreferrer noopener" aria-label="Cupertino widgets (opens in a new tab)" href="https://flutter.dev/docs/development/ui/widgets/cupertino" target="_blank">Cupertino widgets</a></li><li>we used another material widget &#8211; a <span style="color:#f7bb1e" class="tadv-color">Scaffold</span>. It provides us with an <span style="color:#f7bb1e" class="tadv-color">appBar</span> and <span style="color:#f7bb1e" class="tadv-color">body</span> properties &#8211; setting them we&#8217;re getting this nice-looking application&#8217;s skeleton with entitled app bar and home for our widget. Scaffold also gives us many things &#8220;for free&#8221;, e.g.  <a rel="noreferrer noopener" href="https://api.flutter.dev/flutter/material/FloatingActionButton-class.html" target="_blank">FloatingActionButton</a></li><li><span style="color:#f7bb1e" class="tadv-color">body</span> of our <span style="color:#f7bb1e" class="tadv-color">Scaffold</span> is our first own stateless widget &#8211; <span style="color:#f7bb1e" class="tadv-color">MyFirstWidget</span>. As mentioned before, it overrides the <span style="color:#f7bb1e" class="tadv-color">build()</span> method, which simply returns another widget tree. Notice the usage of a <span style="color:#f7bb1e" class="tadv-color">Container</span> widget, which is very useful for grouping other widgets.</li></ul>



<p>StatelessWidget is simple, works and is just there <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Let&#8217;s see something more interesting now &#8211; StatefulWidgets.</p>



<h3 class="wp-block-heading">StatefulWidgets</h3>



<p>When you want your widget to change over time and maintain its state (in most cases you do), you can create a stateful widget. You do it by creating a Dart class extending <a rel="noreferrer noopener" aria-label="StatefulWidget (opens in a new tab)" href="https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html" target="_blank">StatefulWidget</a>. Unlike StatelessWidgets, StatefulWidget doesn&#8217;t override the <span style="color:#f7bb1e" class="tadv-color">build()</span> method. Instead, it implements a <span style="color:#f7bb1e" class="tadv-color">createState()</span> method, which creates the initial widget&#8217;s state (see below).</p>



<p>Apart from the main widget class, which itself is still &#8220;final&#8221; (or better said &#8211; immutable), you create a class extending <a rel="noreferrer noopener" aria-label="State (opens in a new tab)" href="https://api.flutter.dev/flutter/widgets/State-class.html" target="_blank">State</a>. This class maintains the actual state and it is now who provides the <span style="color:#f7bb1e" class="tadv-color">build()</span> method&#8217;s implementation.</p>



<p>Let&#8217;s see the sample code and produced GUI:</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<figure class="wp-block-embed alignwide"><div class="wp-block-embed__wrapper">
<style>.gist table { margin-bottom: 0; }</style><div style="tab-size: 8" id="gist100605434" class="gist">
    <div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
      <div class="gist-data">
        <div class="js-gist-file-update-container js-task-list-container">
  <div id="file-main_stateful_widget-dart" class="file my-2">
    
    <div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-dart  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="main_stateful_widget.dart content, created by dsibinski on 11:31PM on January 15, 2020."
    >

        
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">

  <template class="js-file-alert-template">
  <div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
    <span>
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a>
    </span>


  <div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters
</a>
</div>
</div></template>
<template class="js-line-alert-template">
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e">
    <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
</span></template>

  <table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="main_stateful_widget.dart">
        <tr>
          <td id="file-main_stateful_widget-dart-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
          <td id="file-main_stateful_widget-dart-LC1" class="blob-code blob-code-inner js-file-line">class MySecondWidget extends StatefulWidget {</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
          <td id="file-main_stateful_widget-dart-LC2" class="blob-code blob-code-inner js-file-line">  MySecondWidget({Key key}) : super(key: key);</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
          <td id="file-main_stateful_widget-dart-LC3" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
          <td id="file-main_stateful_widget-dart-LC4" class="blob-code blob-code-inner js-file-line">  @override</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
          <td id="file-main_stateful_widget-dart-LC5" class="blob-code blob-code-inner js-file-line">  _MySecondWidgetState createState() =&gt; </td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
          <td id="file-main_stateful_widget-dart-LC6" class="blob-code blob-code-inner js-file-line">                _MySecondWidgetState();</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
          <td id="file-main_stateful_widget-dart-LC7" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
          <td id="file-main_stateful_widget-dart-LC8" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
          <td id="file-main_stateful_widget-dart-LC9" class="blob-code blob-code-inner js-file-line">class _MySecondWidgetState extends State&lt;MySecondWidget&gt; {</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
          <td id="file-main_stateful_widget-dart-LC10" class="blob-code blob-code-inner js-file-line">  int _clickCount = 0;</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
          <td id="file-main_stateful_widget-dart-LC11" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
          <td id="file-main_stateful_widget-dart-LC12" class="blob-code blob-code-inner js-file-line">  void incrementClickCount() {</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
          <td id="file-main_stateful_widget-dart-LC13" class="blob-code blob-code-inner js-file-line">    setState(() {</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
          <td id="file-main_stateful_widget-dart-LC14" class="blob-code blob-code-inner js-file-line">      this._clickCount++;</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
          <td id="file-main_stateful_widget-dart-LC15" class="blob-code blob-code-inner js-file-line">    });</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
          <td id="file-main_stateful_widget-dart-LC16" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
          <td id="file-main_stateful_widget-dart-LC17" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
          <td id="file-main_stateful_widget-dart-LC18" class="blob-code blob-code-inner js-file-line">  @override</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
          <td id="file-main_stateful_widget-dart-LC19" class="blob-code blob-code-inner js-file-line">  Widget build(BuildContext context) {</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
          <td id="file-main_stateful_widget-dart-LC20" class="blob-code blob-code-inner js-file-line">    return Scaffold(</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
          <td id="file-main_stateful_widget-dart-LC21" class="blob-code blob-code-inner js-file-line">      appBar: AppBar(</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
          <td id="file-main_stateful_widget-dart-LC22" class="blob-code blob-code-inner js-file-line">        title: Text(&quot;My First App&quot;),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
          <td id="file-main_stateful_widget-dart-LC23" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
          <td id="file-main_stateful_widget-dart-LC24" class="blob-code blob-code-inner js-file-line">      body: Container(</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
          <td id="file-main_stateful_widget-dart-LC25" class="blob-code blob-code-inner js-file-line">        padding: EdgeInsets.all(8.0),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
          <td id="file-main_stateful_widget-dart-LC26" class="blob-code blob-code-inner js-file-line">        child: Text(</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
          <td id="file-main_stateful_widget-dart-LC27" class="blob-code blob-code-inner js-file-line">          &quot;Hello! Times clicked: &quot; </td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L28" class="blob-num js-line-number js-blob-rnum" data-line-number="28"></td>
          <td id="file-main_stateful_widget-dart-LC28" class="blob-code blob-code-inner js-file-line">                + this._clickCount.toString(),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L29" class="blob-num js-line-number js-blob-rnum" data-line-number="29"></td>
          <td id="file-main_stateful_widget-dart-LC29" class="blob-code blob-code-inner js-file-line">          style: TextStyle(</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L30" class="blob-num js-line-number js-blob-rnum" data-line-number="30"></td>
          <td id="file-main_stateful_widget-dart-LC30" class="blob-code blob-code-inner js-file-line">            color: Colors.green, </td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L31" class="blob-num js-line-number js-blob-rnum" data-line-number="31"></td>
          <td id="file-main_stateful_widget-dart-LC31" class="blob-code blob-code-inner js-file-line">            fontSize: 20.0),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L32" class="blob-num js-line-number js-blob-rnum" data-line-number="32"></td>
          <td id="file-main_stateful_widget-dart-LC32" class="blob-code blob-code-inner js-file-line">        ),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L33" class="blob-num js-line-number js-blob-rnum" data-line-number="33"></td>
          <td id="file-main_stateful_widget-dart-LC33" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L34" class="blob-num js-line-number js-blob-rnum" data-line-number="34"></td>
          <td id="file-main_stateful_widget-dart-LC34" class="blob-code blob-code-inner js-file-line">      floatingActionButton: FloatingActionButton(</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L35" class="blob-num js-line-number js-blob-rnum" data-line-number="35"></td>
          <td id="file-main_stateful_widget-dart-LC35" class="blob-code blob-code-inner js-file-line">        child: Icon(Icons.add),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L36" class="blob-num js-line-number js-blob-rnum" data-line-number="36"></td>
          <td id="file-main_stateful_widget-dart-LC36" class="blob-code blob-code-inner js-file-line">        onPressed: this.incrementClickCount,</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L37" class="blob-num js-line-number js-blob-rnum" data-line-number="37"></td>
          <td id="file-main_stateful_widget-dart-LC37" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L38" class="blob-num js-line-number js-blob-rnum" data-line-number="38"></td>
          <td id="file-main_stateful_widget-dart-LC38" class="blob-code blob-code-inner js-file-line">    );</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L39" class="blob-num js-line-number js-blob-rnum" data-line-number="39"></td>
          <td id="file-main_stateful_widget-dart-LC39" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-main_stateful_widget-dart-L40" class="blob-num js-line-number js-blob-rnum" data-line-number="40"></td>
          <td id="file-main_stateful_widget-dart-LC40" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
  </table>
</div>


    </div>

  </div>
</div>

      </div>
      <div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/74e2318c87f611ce3b8e2f0dab817567/raw/55cbf4b0cf9f29e6f855c04d36a5a361bad588fc/main_stateful_widget.dart" style="float:right" class="Link--inTextBlock">view raw</a>
        <a href="https://gist.github.com/dsibinski/74e2318c87f611ce3b8e2f0dab817567#file-main_stateful_widget-dart" class="Link--inTextBlock">
          main_stateful_widget.dart
        </a>
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
    </div>
</div>

</div></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<figure class="wp-block-image alignwide size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="576" height="1024" data-attachment-id="3745" data-permalink="https://www.codejourney.net/basics-of-flutter-widgets/flutter_statefulwidget-1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_statefulWidget-1" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?fit=169%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?fit=576%2C1024&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?resize=576%2C1024&#038;ssl=1" alt="" class="wp-image-3745" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?resize=864%2C1536&amp;ssl=1 864w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?resize=676%2C1202&amp;ssl=1 676w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_statefulWidget-1.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 576px) 100vw, 576px" /></figure>
</div>
</div>



<p>The full code you can play with is available <a rel="noreferrer noopener" aria-label="in the DartPad (opens in a new tab)" href="https://dartpad.dev/6a140d19910f60d03e8752b1a3b7f083" target="_blank">in the DartPad</a>.</p>



<p>Now some comments about the StatefulWidget code:</p>



<ul class="wp-block-list"><li>notice how <span style="color:#f7bb1e" class="tadv-color">MySecondWidget</span> class passes a <span style="color:#f7bb1e" class="tadv-color">key</span> to its superclass. Concept of Flutter widgets keys is interesting and we&#8217;ll dig into it in a separate post. For now, just treat it as a convention to always accept a <span style="color:#f7bb1e" class="tadv-color">key</span> as a named argument and pass it to the base class</li><li>as said before, in this simple example, <span style="color:#f7bb1e" class="tadv-color">MySecondWidget</span> only creates the initial state by instantiating <span style="color:#f7bb1e" class="tadv-color">_MySecondWidgetState</span></li><li>you&#8217;re already familiar with most of the code in <span style="color:#f7bb1e" class="tadv-color">_MySecondWidgetState</span>, but notice the usage of <span style="color:#f7bb1e" class="tadv-color">setState()</span> in <span style="color:#f7bb1e" class="tadv-color">incrementClickCount()</span> function. It tells Flutter that the state has changed, so the framework can re-render the UI. If you directly change the value of <span style="color:#f7bb1e" class="tadv-color">this._clickCount</span> without calling <span style="color:#f7bb1e" class="tadv-color">setState()</span>, GUI will not be updated until <span style="color:#f7bb1e" class="tadv-color">setState()</span> is called in some other place. We&#8217;ll talk more about state management techniques in Flutter in the future articles</li><li>note how easy it is to add a <span style="color:#f7bb1e" class="tadv-color">FloatingActionButton</span> thanks to using <a rel="noreferrer noopener" aria-label="Scaffold (opens in a new tab)" href="https://api.flutter.dev/flutter/material/Scaffold-class.html" target="_blank">Scaffold</a> material widget.</li></ul>



<p>That was easy and works nicely! You now know how to use both Flutter widget types <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4aa.png" alt="💪" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading">Flutter quick actions in VS Code</h2>



<p>I&#8217;d like to share with you two easy tips for working with Flutter in Visual Studio Code. Both speed up the development nicely. It assumes that you configured VS Code properly (if not read <a href="https://www.codejourney.net/2019/12/your-first-flutter-app-in-30-minutes/" target="_blank" rel="noreferrer noopener" aria-label="this article (opens in a new tab)">this article</a>) and have Flutter extension installed.</p>



<h3 class="wp-block-heading">Ctrl + .</h3>



<p>First important keyboard shortcut is <em>Ctrl</em>+<em>.</em> (<em>Cmd</em>+<em>.</em> on Mac). It allows you to perform many element-contextual actions. For me it&#8217;s most useful for removing widgets or wrapping widgets with other ones:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="3760" data-permalink="https://www.codejourney.net/basics-of-flutter-widgets/flutter_quickactions/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_quickActions.png?fit=418%2C409&amp;ssl=1" data-orig-size="418,409" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_quickActions" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_quickActions.png?fit=300%2C294&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_quickActions.png?fit=418%2C409&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_quickActions.png?resize=314%2C307&#038;ssl=1" alt="" class="wp-image-3760" width="314" height="307" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_quickActions.png?w=418&amp;ssl=1 418w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_quickActions.png?resize=300%2C294&amp;ssl=1 300w" sizes="auto, (max-width: 314px) 100vw, 314px" /><figcaption>Quick Flutter actions in VS Code (Ctrl+.)</figcaption></figure></div>



<h3 class="wp-block-heading">Snippets for widgets creation</h3>



<p>Another useful feature are code snippets for creating widgets. You use them by starting to type their acronym in your <em>.dart</em> file. There are two acronyms for widgets creation &#8211; <em>stless</em> for <span style="color:#f7bb1e" class="tadv-color">StatelessWidget</span> and <em>stful</em> for <span style="color:#f7bb1e" class="tadv-color">StatefulWidget</span> scaffolding. The usage looks as follows:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="909" height="327" data-attachment-id="3763" data-permalink="https://www.codejourney.net/basics-of-flutter-widgets/flutter_snippets/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?fit=909%2C327&amp;ssl=1" data-orig-size="909,327" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_snippets" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?fit=300%2C108&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?fit=909%2C327&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?resize=909%2C327&#038;ssl=1" alt="" class="wp-image-3763" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?w=909&amp;ssl=1 909w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?resize=300%2C108&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?resize=768%2C276&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2020/01/Flutter_snippets.png?resize=676%2C243&amp;ssl=1 676w" sizes="auto, (max-width: 909px) 100vw, 909px" /><figcaption>Visual Studio Code &#8211; using Flutter snippets</figcaption></figure></div>



<h2 class="wp-block-heading">Most popular Flutter widgets</h2>



<p>I wanted to list you here some most popular Flutter widgets, but they are quite well described <a rel="noreferrer noopener" aria-label="here (opens in a new tab)" href="https://flutter.dev/docs/development/ui/widgets-intro#basic-widgets" target="_blank">here</a>. You can also search through the <a rel="noreferrer noopener" aria-label="widgets library (opens in a new tab)" href="https://flutter.dev/docs/reference/widgets" target="_blank">widgets library</a>. We&#8217;ve also used quite few of them in our examples above <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading">Community widgets</h2>



<p>Many more people are starting to use Flutter and they also create a lot of community widgets. You can find the Dart packages for Flutter on <a rel="noreferrer noopener" aria-label="pub.dev (opens in a new tab)" href="https://pub.dev/" target="_blank">pub.dev</a>. I also recommend checking the <a rel="noreferrer noopener" aria-label="Flutter Awesome website (opens in a new tab)" href="https://flutterawesome.com/" target="_blank">Flutter Awesome website</a> where the best Flutter widgets, libraries and other extensions are listed.</p>



<h2 class="wp-block-heading">Summary</h2>



<p>That&#8217;s it! You&#8217;ve just learned how to use stateless and stateful widgets in Flutter. We&#8217;ve also seen what&#8217;s the difference between them and what are some basic conventions in creating them. There&#8217;s a lot more to Flutter widgets and related topics, but these are topics for separate posts. I hope to publish more of them soon <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>In my opinion, bringing components into the mobile world in the form of widgets is a very nice idea. They give quite a good separation of logic and GUI management. For sure it&#8217;s a fresh start, totally changing the way in which we think about mobile apps development. Components have done their job in the web world, so why would widgets not succeed in mobile apps? <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f914.png" alt="🤔" class="wp-smiley" style="height: 1em; max-height: 1em;" /> We&#8217;ll see!</p>



<p>What do you think? If you are interested in some particular topics related to Flutter &#8211; let me know! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>


<p>The post <a href="https://www.codejourney.net/basics-of-flutter-widgets/">Basics of Flutter Widgets</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/basics-of-flutter-widgets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3715</post-id>	</item>
		<item>
		<title>Your First Flutter App in 30 Minutes</title>
		<link>https://www.codejourney.net/your-first-flutter-app-in-30-minutes/</link>
					<comments>https://www.codejourney.net/your-first-flutter-app-in-30-minutes/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Wed, 04 Dec 2019 17:26:31 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[dart]]></category>
		<category><![CDATA[flutter]]></category>
		<guid isPermaLink="false">https://www.codejourney.net/?p=3652</guid>

					<description><![CDATA[<p>You may know my past affair with Xamarin, which somehow died a natural death. In today&#8217;s post, we&#8217;re taking a look at Flutter. If you want to know what is Flutter and how to build your first Flutter app in less than 30 minutes (including installation time) &#8211; let&#8217;s jump right into it 😉 What&#8230;</p>
<p>The post <a href="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/">Your First Flutter App in 30 Minutes</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[


<p>You may know my past <a rel="noreferrer noopener" aria-label="affair with Xamarin (opens in a new tab)" href="https://www.codejourney.net/xamarin/" target="_blank">affair with Xamarin</a>, which somehow died a natural death. In today&#8217;s post, we&#8217;re taking a look at Flutter. If you want to know what is Flutter and how to build your first Flutter app in less than 30 minutes (including installation time) &#8211; let&#8217;s jump right into it <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<span id="more-3652"></span>



<h2 class="wp-block-heading">What is Flutter?</h2>



<p>Flutter is an <strong>open-source</strong> platform and development kit created by Google. You can use it to create <strong>mobile (Android, iOS), desktop (Windows, Mac, Linux)</strong> and recently also <strong>web applications</strong>.</p>



<p>Flutter is quite new, as it&#8217;s <strong>first official version 1.0 was released in December 2018</strong>. Before, it was developed and used internally by Google for a few years.</p>



<p>Since this time, countless Flutter apps have been published. You can find their list for instance <a rel="noreferrer noopener" aria-label="here (opens in a new tab)" href="https://itsallwidgets.com/" target="_blank">here</a>. One of the most well-known Flutter apps is <a href="https://youtu.be/jtYk3gWRSw0" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">Xianyu app created by Alibaba</a> and used by 50M+ people.</p>



<p>The main purposes of Flutter are claimed to be <strong>fast development</strong>, <strong>beautiful and consistent UIs</strong> and <strong>native performance on each platform</strong>.</p>



<h2 class="wp-block-heading">Dart as a programming language</h2>



<p>Flutter uses <strong><a rel="noreferrer noopener" aria-label="Dart (opens in a new tab)" href="https://dart.dev/" target="_blank">Dart</a> as a programming language</strong>. Why is that? Well, of course, Dart is also developed by Google <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f601.png" alt="😁" class="wp-smiley" style="height: 1em; max-height: 1em;" /> However, one of the real reasons is believed to be performance. </p>



<p>As you probably know, Flutter is not the first (and not the last) cross-platform mobile development platform. Its main competitor is <a rel="noreferrer noopener" aria-label="React Native (opens in a new tab)" href="https://facebook.github.io/react-native/" target="_blank">React Native</a>, which uses JavaScript. Dart <strong>compiles to the given platform&#8217;s native machine code</strong>. Thanks to that, it doesn&#8217;t have to use a <a rel="noreferrer noopener" aria-label="JavaScript bridge (opens in a new tab)" href="https://hackernoon.com/understanding-react-native-bridge-concept-e9526066ddb8" target="_blank">JavaScript bridge</a> to interact with native components that React Native apps have to do. I don&#8217;t know how true this is in real life and how it helps with performance, but that is one of the reasons for using Dart as a programming language for Flutter apps.</p>



<p>Dart is a <strong>UI-oriented language</strong>. For C/C#/Java developers, Dart&#8217;s syntax will be rather familiar and easy to learn. It&#8217;s <strong>object-oriented</strong>, including support for classes and interfaces. The language is <strong>type-safe</strong>, meaning it combines static and runtime types checking.</p>



<p>Dart is supported by its <strong>virtual machine</strong>, which also provides &#8211; amongst others &#8211; a <strong>garbage collector</strong> (if you don&#8217;t know what the GC is, check out <a rel="noreferrer noopener" aria-label="this post (opens in a new tab)" href="https://www.codejourney.net/2018/08/net-internals-04-what-is-garbage-collection-memory-allocation-in-net/" target="_blank">this post</a>).</p>



<p>Here&#8217;s a simple program written in Dart:</p>



<figure class="wp-block-embed"><div class="wp-block-embed__wrapper">
<style>.gist table { margin-bottom: 0; }</style><div style="tab-size: 8" id="gist99841306" class="gist">
    <div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
      <div class="gist-data">
        <div class="js-gist-file-update-container js-task-list-container">
  <div id="file-main-dart" class="file my-2">
    
    <div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-dart  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="main.dart content, created by dsibinski on 02:03AM on December 04, 2019."
    >

        
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">

  <template class="js-file-alert-template">
  <div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
    <span>
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a>
    </span>


  <div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters
</a>
</div>
</div></template>
<template class="js-line-alert-template">
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e">
    <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
</span></template>

  <table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="main.dart">
        <tr>
          <td id="file-main-dart-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
          <td id="file-main-dart-LC1" class="blob-code blob-code-inner js-file-line">main() {</td>
        </tr>
        <tr>
          <td id="file-main-dart-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
          <td id="file-main-dart-LC2" class="blob-code blob-code-inner js-file-line">  var myCar = new Car(&quot;Cybertruck&quot;, new DateTime(2021, 01, 01));</td>
        </tr>
        <tr>
          <td id="file-main-dart-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
          <td id="file-main-dart-LC3" class="blob-code blob-code-inner js-file-line">  myCar.describe();</td>
        </tr>
        <tr>
          <td id="file-main-dart-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
          <td id="file-main-dart-LC4" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
        <tr>
          <td id="file-main-dart-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
          <td id="file-main-dart-LC5" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main-dart-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
          <td id="file-main-dart-LC6" class="blob-code blob-code-inner js-file-line">class Car {</td>
        </tr>
        <tr>
          <td id="file-main-dart-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
          <td id="file-main-dart-LC7" class="blob-code blob-code-inner js-file-line">  String model;</td>
        </tr>
        <tr>
          <td id="file-main-dart-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
          <td id="file-main-dart-LC8" class="blob-code blob-code-inner js-file-line">  DateTime productionDate;</td>
        </tr>
        <tr>
          <td id="file-main-dart-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
          <td id="file-main-dart-LC9" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main-dart-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
          <td id="file-main-dart-LC10" class="blob-code blob-code-inner js-file-line">  // Ctor: notice the syntactic sugar members&#39; assignment</td>
        </tr>
        <tr>
          <td id="file-main-dart-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
          <td id="file-main-dart-LC11" class="blob-code blob-code-inner js-file-line">  Car(this.model, this.productionDate) {</td>
        </tr>
        <tr>
          <td id="file-main-dart-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
          <td id="file-main-dart-LC12" class="blob-code blob-code-inner js-file-line">    // Some other ctor init code here</td>
        </tr>
        <tr>
          <td id="file-main-dart-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
          <td id="file-main-dart-LC13" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-main-dart-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
          <td id="file-main-dart-LC14" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-main-dart-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
          <td id="file-main-dart-LC15" class="blob-code blob-code-inner js-file-line">  int get productionYear =&gt;</td>
        </tr>
        <tr>
          <td id="file-main-dart-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
          <td id="file-main-dart-LC16" class="blob-code blob-code-inner js-file-line">      productionDate?.year;</td>
        </tr>
        <tr>
          <td id="file-main-dart-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
          <td id="file-main-dart-LC17" class="blob-code blob-code-inner js-file-line">  </td>
        </tr>
        <tr>
          <td id="file-main-dart-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
          <td id="file-main-dart-LC18" class="blob-code blob-code-inner js-file-line">  void describe() {</td>
        </tr>
        <tr>
          <td id="file-main-dart-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
          <td id="file-main-dart-LC19" class="blob-code blob-code-inner js-file-line">    print(&#39;Car: $model, produced in $productionYear&#39;);</td>
        </tr>
        <tr>
          <td id="file-main-dart-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
          <td id="file-main-dart-LC20" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-main-dart-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
          <td id="file-main-dart-LC21" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
  </table>
</div>


    </div>

  </div>
</div>

      </div>
      <div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/62f21a6a9e62af732b28fceec1310f9c/raw/4cbb0678c4f0c12be9ea22990e08f9f4c481da3d/main.dart" style="float:right" class="Link--inTextBlock">view raw</a>
        <a href="https://gist.github.com/dsibinski/62f21a6a9e62af732b28fceec1310f9c#file-main-dart" class="Link--inTextBlock">
          main.dart
        </a>
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
    </div>
</div>

</div></figure>



<p>You can play with the code yourself <a rel="noreferrer noopener" aria-label="in the DartPad (opens in a new tab)" href="https://dartpad.dev/62f21a6a9e62af732b28fceec1310f9c" target="_blank">in the DartPad</a>.</p>



<p>Another interesting feature that is possible thanks to Dart is the <em>hot reload</em>. We&#8217;ll explore it later, but it significantly speeds up the development and testing time.</p>



<p>If you want to learn more about Dart, check out <a rel="noreferrer noopener" aria-label="the official docs (opens in a new tab)" href="https://dart.dev/tutorials" target="_blank">the official docs</a>.</p>



<h2 class="wp-block-heading">Everything as a widget</h2>



<p>The main concept in building Flutter apps are <strong>widgets</strong>. In Flutter, <strong>everything is a widget</strong> &#8211; buttons, texts, menus, colors, themes, spacings and paddings. Even your Flutter app is a widget.</p>



<p>What&#8217;s very interesting is that Flutter doesn&#8217;t use platform native widgets. Instead, it <strong>provides its own set of widgets for each platform</strong>, e.g. <a rel="noreferrer noopener" aria-label="Material Design (opens in a new tab)" href="https://material.io/develop/flutter/" target="_blank">Material Design</a> for Android and <a rel="noreferrer noopener" aria-label="Cupertino widgets (opens in a new tab)" href="https://flutter.dev/docs/development/ui/widgets/cupertino" target="_blank">Cupertino widgets</a> for iOS. Additionally, as a programmer, <strong>you can create your own widgets</strong>. Thanks to that, all Flutter apps look pretty much the same on every Android/iOS version. You don&#8217;t need to worry about some UI elements changes between OS releases. At the same time, an app built using these widgets looks like native GUI.</p>



<p>Thanks to the widgets concept, <strong>Flutter apps can be easily personalized and branded</strong>. <a rel="noreferrer noopener" aria-label="Recent researches show (opens in a new tab)" href="https://learn.g2.com/mobile-app-development-trends" target="_blank">Recent researches show</a> that customers are now starting to prefer more specific-looking apps to standard and boring native-designed UIs.</p>



<p>The drawback which I see about widgets is that <strong>there&#8217;s normally A LOT of source code in Flutter apps</strong>. Don&#8217;t get confused straightaway <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading">Installation and configuration</h2>



<p>Now, let&#8217;s get into the real work. It surprised me how easy it is to start working with Flutter. As you&#8217;ll see in a moment, you can build quite a nice-looking mobile app with Flutter in less than 30 minutes!</p>



<p>There are several possibilities to work with Flutter. You can easily <a rel="noreferrer noopener" aria-label="set up Android Studio or IntelliJ (opens in a new tab)" href="https://flutter.dev/docs/get-started/editor?tab=androidstudio" target="_blank">set up Android Studio or IntelliJ</a>. For example purposes, we&#8217;ll focus on <strong>running and debugging an Android application on Windows PC using Visual Studio Code</strong>. If you&#8217;re on Mac or Linux, check out a corresponding <a rel="noreferrer noopener" aria-label="official installation guide (opens in a new tab)" href="https://flutter.dev/docs/get-started/install" target="_blank">official installation guide</a>.</p>



<h3 class="wp-block-heading">Install Flutter and Android SDK</h3>



<p>The installation process is quite easy. Initially I wanted to describe it here for you, but actually the <a rel="noreferrer noopener" aria-label="official installation docs (opens in a new tab)" href="https://flutter.dev/docs/get-started/install" target="_blank">official installation docs</a> do it pretty well <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> I&#8217;ll just guide you through the steps below with links to the official installation guide.</p>



<p><strong>Install Flutter SDK</strong> <strong>and Android Studio</strong></p>



<p>First of all, install Flutter SDK and Android Studio (which is required for Android SDK) following <a rel="noreferrer noopener" aria-label="this installation guide (opens in a new tab)" href="https://flutter.dev/docs/get-started/install/windows" target="_blank">this installation guide</a>. The process is fairly easy and should not take more than 15 minutes. Remember about using <em>flutter doctor</em> command to verify if everything is installed correctly &#8211; it gives very clear messages. In the end, using VS Code and having Android phone connected in USB Debugging mode, your <em>flutter doctor</em> command should have an output similar to mine:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="867" height="240" data-attachment-id="3669" data-permalink="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/flutterdoctor_vscode_ok/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?fit=867%2C240&amp;ssl=1" data-orig-size="867,240" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="FlutterDoctor_VSCode_OK" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?fit=300%2C83&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?fit=867%2C240&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?resize=867%2C240&#038;ssl=1" alt="Flutter App - flutter doctor proper result" class="wp-image-3669" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?w=867&amp;ssl=1 867w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?resize=300%2C83&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?resize=768%2C213&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/FlutterDoctor_VSCode_OK.png?resize=676%2C187&amp;ssl=1 676w" sizes="auto, (max-width: 867px) 100vw, 867px" /><figcaption>The correct output of <strong>flutter doctor</strong> command for VS Code (not Android Studio) development and Android phone connected in USB Debugging mode</figcaption></figure>



<h3 class="wp-block-heading">Configure Visual Studio Code</h3>



<p>The next step is to configure Visual Studio Code to be able to develop, compile, run and debug Flutter apps. You only need to install the Flutter extension, which is very well described <a rel="noreferrer noopener" aria-label="here (opens in a new tab)" href="https://flutter.dev/docs/get-started/editor?tab=vscode" target="_blank">here</a>. It should also automatically install the <a rel="noreferrer noopener" aria-label="Dart VS Code extension (opens in a new tab)" href="https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code" target="_blank">Dart VS Code extension</a> which adds Dart language support to VS Code.</p>



<h2 class="wp-block-heading">Your first Flutter app</h2>



<p>Now let&#8217;s finally create this first Flutter Android application <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> It&#8217;s probably gonna be the quickest part!</p>



<h3 class="wp-block-heading">Create and run a sample app</h3>



<p>First of all, open Visual Studio Code. Use <em>Ctrl+Shift+P</em> to open a Command Palette. Start typing &#8220;Flutter&#8221; and select <em>Flutter: New Project</em>:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="831" height="252" data-attachment-id="3671" data-permalink="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/flutter_newproject_vscode/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?fit=831%2C252&amp;ssl=1" data-orig-size="831,252" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_NewProject_VSCode" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?fit=300%2C91&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?fit=831%2C252&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?resize=831%2C252&#038;ssl=1" alt="Flutter App - New Project creation in VS Code" class="wp-image-3671" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?w=831&amp;ssl=1 831w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?resize=300%2C91&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?resize=768%2C233&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_NewProject_VSCode.png?resize=676%2C205&amp;ssl=1 676w" sizes="auto, (max-width: 831px) 100vw, 831px" /></figure>



<p>In two next steps specify your project&#8217;s name (e.g. &#8220;hello_flutter&#8221;) and choose a location where the template should be generated.</p>



<p>Wait until VS Code generates the whole project and you see <em>main.dart</em> file in <em>lib</em> folder:</p>



<div class="wp-block-image"><figure class="aligncenter size-medium"><img data-recalc-dims="1" loading="lazy" decoding="async" width="159" height="300" data-attachment-id="3678" data-permalink="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/flutter_maindartfile-1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_maindartfile-1.png?fit=221%2C416&amp;ssl=1" data-orig-size="221,416" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_maindartfile-1" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_maindartfile-1.png?fit=159%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_maindartfile-1.png?fit=221%2C416&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_maindartfile-1.png?resize=159%2C300&#038;ssl=1" alt="Flutter App - files structure of a template project with main.dart file" class="wp-image-3678" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_maindartfile-1.png?resize=159%2C300&amp;ssl=1 159w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_maindartfile-1.png?w=221&amp;ssl=1 221w" sizes="auto, (max-width: 159px) 100vw, 159px" /></figure></div>



<p>Open the <em>main.dart</em> file and replace its contents with the following, a bit cleaned-up code:</p>



<figure class="wp-block-embed"><div class="wp-block-embed__wrapper">
<style>.gist table { margin-bottom: 0; }</style><div style="tab-size: 8" id="gist99854969" class="gist">
    <div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
      <div class="gist-data">
        <div class="js-gist-file-update-container js-task-list-container">
  <div id="file-flutter_demo_main-dart" class="file my-2">
    
    <div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-dart  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="flutter_demo_main.dart content, created by dsibinski on 03:25PM on December 04, 2019."
    >

        
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">

  <template class="js-file-alert-template">
  <div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
    <span>
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a>
    </span>


  <div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters
</a>
</div>
</div></template>
<template class="js-line-alert-template">
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e">
    <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
</span></template>

  <table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="flutter_demo_main.dart">
        <tr>
          <td id="file-flutter_demo_main-dart-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
          <td id="file-flutter_demo_main-dart-LC1" class="blob-code blob-code-inner js-file-line">import &#39;package:flutter/material.dart&#39;;</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
          <td id="file-flutter_demo_main-dart-LC2" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
          <td id="file-flutter_demo_main-dart-LC3" class="blob-code blob-code-inner js-file-line">void main() =&gt; runApp(HelloFlutterApp());</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
          <td id="file-flutter_demo_main-dart-LC4" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
          <td id="file-flutter_demo_main-dart-LC5" class="blob-code blob-code-inner js-file-line">class HelloFlutterApp extends StatelessWidget {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
          <td id="file-flutter_demo_main-dart-LC6" class="blob-code blob-code-inner js-file-line">  @override</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
          <td id="file-flutter_demo_main-dart-LC7" class="blob-code blob-code-inner js-file-line">  Widget build(BuildContext context) {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
          <td id="file-flutter_demo_main-dart-LC8" class="blob-code blob-code-inner js-file-line">    return MaterialApp(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
          <td id="file-flutter_demo_main-dart-LC9" class="blob-code blob-code-inner js-file-line">      title: &#39;HelloFlutter&#39;,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
          <td id="file-flutter_demo_main-dart-LC10" class="blob-code blob-code-inner js-file-line">      theme: ThemeData(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
          <td id="file-flutter_demo_main-dart-LC11" class="blob-code blob-code-inner js-file-line">        primarySwatch: Colors.lightGreen,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
          <td id="file-flutter_demo_main-dart-LC12" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
          <td id="file-flutter_demo_main-dart-LC13" class="blob-code blob-code-inner js-file-line">      home: MyHomePage(title: &#39;Hello Flutter!&#39;),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
          <td id="file-flutter_demo_main-dart-LC14" class="blob-code blob-code-inner js-file-line">    );</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
          <td id="file-flutter_demo_main-dart-LC15" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
          <td id="file-flutter_demo_main-dart-LC16" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
          <td id="file-flutter_demo_main-dart-LC17" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
          <td id="file-flutter_demo_main-dart-LC18" class="blob-code blob-code-inner js-file-line">class MyHomePage extends StatefulWidget {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
          <td id="file-flutter_demo_main-dart-LC19" class="blob-code blob-code-inner js-file-line">  MyHomePage({Key key, this.title}) : super(key: key);</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
          <td id="file-flutter_demo_main-dart-LC20" class="blob-code blob-code-inner js-file-line">  final String title;</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
          <td id="file-flutter_demo_main-dart-LC21" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
          <td id="file-flutter_demo_main-dart-LC22" class="blob-code blob-code-inner js-file-line">  @override</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
          <td id="file-flutter_demo_main-dart-LC23" class="blob-code blob-code-inner js-file-line">  _MyHomePageState createState() =&gt; _MyHomePageState();</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
          <td id="file-flutter_demo_main-dart-LC24" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
          <td id="file-flutter_demo_main-dart-LC25" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
          <td id="file-flutter_demo_main-dart-LC26" class="blob-code blob-code-inner js-file-line">class _MyHomePageState extends State&lt;MyHomePage&gt; {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
          <td id="file-flutter_demo_main-dart-LC27" class="blob-code blob-code-inner js-file-line">  int _counter = 0;</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L28" class="blob-num js-line-number js-blob-rnum" data-line-number="28"></td>
          <td id="file-flutter_demo_main-dart-LC28" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L29" class="blob-num js-line-number js-blob-rnum" data-line-number="29"></td>
          <td id="file-flutter_demo_main-dart-LC29" class="blob-code blob-code-inner js-file-line">  void _incrementCounter() {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L30" class="blob-num js-line-number js-blob-rnum" data-line-number="30"></td>
          <td id="file-flutter_demo_main-dart-LC30" class="blob-code blob-code-inner js-file-line">    setState(() {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L31" class="blob-num js-line-number js-blob-rnum" data-line-number="31"></td>
          <td id="file-flutter_demo_main-dart-LC31" class="blob-code blob-code-inner js-file-line">      _counter++;</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L32" class="blob-num js-line-number js-blob-rnum" data-line-number="32"></td>
          <td id="file-flutter_demo_main-dart-LC32" class="blob-code blob-code-inner js-file-line">    });</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L33" class="blob-num js-line-number js-blob-rnum" data-line-number="33"></td>
          <td id="file-flutter_demo_main-dart-LC33" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L34" class="blob-num js-line-number js-blob-rnum" data-line-number="34"></td>
          <td id="file-flutter_demo_main-dart-LC34" class="blob-code blob-code-inner js-file-line">
</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L35" class="blob-num js-line-number js-blob-rnum" data-line-number="35"></td>
          <td id="file-flutter_demo_main-dart-LC35" class="blob-code blob-code-inner js-file-line">  @override</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L36" class="blob-num js-line-number js-blob-rnum" data-line-number="36"></td>
          <td id="file-flutter_demo_main-dart-LC36" class="blob-code blob-code-inner js-file-line">  Widget build(BuildContext context) {</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L37" class="blob-num js-line-number js-blob-rnum" data-line-number="37"></td>
          <td id="file-flutter_demo_main-dart-LC37" class="blob-code blob-code-inner js-file-line">    return Scaffold(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L38" class="blob-num js-line-number js-blob-rnum" data-line-number="38"></td>
          <td id="file-flutter_demo_main-dart-LC38" class="blob-code blob-code-inner js-file-line">      appBar: AppBar(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L39" class="blob-num js-line-number js-blob-rnum" data-line-number="39"></td>
          <td id="file-flutter_demo_main-dart-LC39" class="blob-code blob-code-inner js-file-line">        title: Text(widget.title),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L40" class="blob-num js-line-number js-blob-rnum" data-line-number="40"></td>
          <td id="file-flutter_demo_main-dart-LC40" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L41" class="blob-num js-line-number js-blob-rnum" data-line-number="41"></td>
          <td id="file-flutter_demo_main-dart-LC41" class="blob-code blob-code-inner js-file-line">      body: Center(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L42" class="blob-num js-line-number js-blob-rnum" data-line-number="42"></td>
          <td id="file-flutter_demo_main-dart-LC42" class="blob-code blob-code-inner js-file-line">        child: Column(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L43" class="blob-num js-line-number js-blob-rnum" data-line-number="43"></td>
          <td id="file-flutter_demo_main-dart-LC43" class="blob-code blob-code-inner js-file-line">          mainAxisAlignment: MainAxisAlignment.center,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L44" class="blob-num js-line-number js-blob-rnum" data-line-number="44"></td>
          <td id="file-flutter_demo_main-dart-LC44" class="blob-code blob-code-inner js-file-line">          children: &lt;Widget&gt;[</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L45" class="blob-num js-line-number js-blob-rnum" data-line-number="45"></td>
          <td id="file-flutter_demo_main-dart-LC45" class="blob-code blob-code-inner js-file-line">            Text(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L46" class="blob-num js-line-number js-blob-rnum" data-line-number="46"></td>
          <td id="file-flutter_demo_main-dart-LC46" class="blob-code blob-code-inner js-file-line">              &#39;You have pushed the button this many times: &#39;,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L47" class="blob-num js-line-number js-blob-rnum" data-line-number="47"></td>
          <td id="file-flutter_demo_main-dart-LC47" class="blob-code blob-code-inner js-file-line">            ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L48" class="blob-num js-line-number js-blob-rnum" data-line-number="48"></td>
          <td id="file-flutter_demo_main-dart-LC48" class="blob-code blob-code-inner js-file-line">            Text(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L49" class="blob-num js-line-number js-blob-rnum" data-line-number="49"></td>
          <td id="file-flutter_demo_main-dart-LC49" class="blob-code blob-code-inner js-file-line">              &#39;$_counter&#39;,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L50" class="blob-num js-line-number js-blob-rnum" data-line-number="50"></td>
          <td id="file-flutter_demo_main-dart-LC50" class="blob-code blob-code-inner js-file-line">              style: TextStyle(color: Colors.green, fontSize: 25),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L51" class="blob-num js-line-number js-blob-rnum" data-line-number="51"></td>
          <td id="file-flutter_demo_main-dart-LC51" class="blob-code blob-code-inner js-file-line">            ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L52" class="blob-num js-line-number js-blob-rnum" data-line-number="52"></td>
          <td id="file-flutter_demo_main-dart-LC52" class="blob-code blob-code-inner js-file-line">          ],</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L53" class="blob-num js-line-number js-blob-rnum" data-line-number="53"></td>
          <td id="file-flutter_demo_main-dart-LC53" class="blob-code blob-code-inner js-file-line">        ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L54" class="blob-num js-line-number js-blob-rnum" data-line-number="54"></td>
          <td id="file-flutter_demo_main-dart-LC54" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L55" class="blob-num js-line-number js-blob-rnum" data-line-number="55"></td>
          <td id="file-flutter_demo_main-dart-LC55" class="blob-code blob-code-inner js-file-line">      floatingActionButton: FloatingActionButton(</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L56" class="blob-num js-line-number js-blob-rnum" data-line-number="56"></td>
          <td id="file-flutter_demo_main-dart-LC56" class="blob-code blob-code-inner js-file-line">        onPressed: _incrementCounter,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L57" class="blob-num js-line-number js-blob-rnum" data-line-number="57"></td>
          <td id="file-flutter_demo_main-dart-LC57" class="blob-code blob-code-inner js-file-line">        tooltip: &#39;Increment&#39;,</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L58" class="blob-num js-line-number js-blob-rnum" data-line-number="58"></td>
          <td id="file-flutter_demo_main-dart-LC58" class="blob-code blob-code-inner js-file-line">        child: Icon(Icons.add),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L59" class="blob-num js-line-number js-blob-rnum" data-line-number="59"></td>
          <td id="file-flutter_demo_main-dart-LC59" class="blob-code blob-code-inner js-file-line">      ),</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L60" class="blob-num js-line-number js-blob-rnum" data-line-number="60"></td>
          <td id="file-flutter_demo_main-dart-LC60" class="blob-code blob-code-inner js-file-line">    );</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L61" class="blob-num js-line-number js-blob-rnum" data-line-number="61"></td>
          <td id="file-flutter_demo_main-dart-LC61" class="blob-code blob-code-inner js-file-line">  }</td>
        </tr>
        <tr>
          <td id="file-flutter_demo_main-dart-L62" class="blob-num js-line-number js-blob-rnum" data-line-number="62"></td>
          <td id="file-flutter_demo_main-dart-LC62" class="blob-code blob-code-inner js-file-line">}</td>
        </tr>
  </table>
</div>


    </div>

  </div>
</div>

      </div>
      <div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/9b10fa31f0d050979a03404eb7a75c73/raw/baea3b034734c06fb994663d8716e594d24b7194/flutter_demo_main.dart" style="float:right" class="Link--inTextBlock">view raw</a>
        <a href="https://gist.github.com/dsibinski/9b10fa31f0d050979a03404eb7a75c73#file-flutter_demo_main-dart" class="Link--inTextBlock">
          flutter_demo_main.dart
        </a>
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
    </div>
</div>

</div></figure>



<p>We won&#8217;t focus on the source code here &#8211; I hope to dig more in the coming posts <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Just notice there are quite a few widgets &#8211; can you count them all? <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> I found at least 12 different widgets used in this small template code.</p>



<p>Now the best part &#8211; having your Android phone connected (you should see it in the right-bottom corner of VS Code) press F5 to run the application. After a few seconds (usually longer for the first time) you should see this beautiful application on your smartphone&#8217;s screen:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="3679" data-permalink="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/flutter-firstandroidapp/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?fit=1080%2C2280&amp;ssl=1" data-orig-size="1080,2280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter-FirstAndroidApp" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?fit=142%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?fit=485%2C1024&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=364%2C768&#038;ssl=1" alt="Flutter App - first Flutter app (Android)" class="wp-image-3679" width="364" height="768" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=485%2C1024&amp;ssl=1 485w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=142%2C300&amp;ssl=1 142w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=768%2C1621&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=728%2C1536&amp;ssl=1 728w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=970%2C2048&amp;ssl=1 970w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?resize=676%2C1427&amp;ssl=1 676w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter-FirstAndroidApp.jpg?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 364px) 100vw, 364px" /></figure></div>



<p>As soon as you press the &#8220;+&#8221; button the green counter increments. Yaaaaay! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f601.png" alt="😁" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h3 class="wp-block-heading">Debug your Flutter app</h3>



<p>Now, try putting a breakpoint in <em>main.dart</em> file at line 30 (beginning of <em>_incrementCounter()</em> function). When you click the &#8220;+&#8221; button next time, VS Code should stop at the breakpoint:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="867" height="306" data-attachment-id="3686" data-permalink="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/flutter_vscode_debug/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?fit=867%2C306&amp;ssl=1" data-orig-size="867,306" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_VSCode_Debug" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?fit=300%2C106&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?fit=867%2C306&amp;ssl=1" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?resize=867%2C306&#038;ssl=1" alt="Dart's breakpoint hit in VS Code" class="wp-image-3686" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?w=867&amp;ssl=1 867w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?resize=300%2C106&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?resize=768%2C271&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_VSCode_Debug.png?resize=676%2C239&amp;ssl=1 676w" sizes="auto, (max-width: 867px) 100vw, 867px" /></figure>



<h3 class="wp-block-heading">Try hot reload</h3>



<p>The best for the end. As I mentioned before, Flutter lets you use a <a rel="noreferrer noopener" aria-label="hot reload (opens in a new tab)" href="https://flutter.dev/docs/development/tools/hot-reload" target="_blank">hot reload</a>. It lets you <strong>change the code while running the app and see the changes immediately</strong> after saving the source code file. I love it especially because it&#8217;s a <strong>stateful hot reload</strong>, meaning that except UI the state is also reloaded (or rather kept).</p>



<p>With your Flutter app running in debug mode, click the &#8220;+&#8221; button several times so the counter has value &gt; 0. Then go directly into VS Code and modify line 50 by changing the counter text color from <em>Colors.green</em> to  <em>Colors.red</em>. Line 50 should now look as follows:</p>



<figure class="wp-block-embed"><div class="wp-block-embed__wrapper">
<style>.gist table { margin-bottom: 0; }</style><div style="tab-size: 8" id="gist99855426" class="gist">
    <div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
      <div class="gist-data">
        <div class="js-gist-file-update-container js-task-list-container">
  <div id="file-flutter_demo_main_line50_color-dart" class="file my-2">
    
    <div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-dart  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="flutter_demo_main_line50_color.dart content, created by dsibinski on 03:50PM on December 04, 2019."
    >

        
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">

  <template class="js-file-alert-template">
  <div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
    <span>
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a>
    </span>


  <div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters
</a>
</div>
</div></template>
<template class="js-line-alert-template">
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e">
    <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
</span></template>

  <table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="flutter_demo_main_line50_color.dart">
        <tr>
          <td id="file-flutter_demo_main_line50_color-dart-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
          <td id="file-flutter_demo_main_line50_color-dart-LC1" class="blob-code blob-code-inner js-file-line">style: TextStyle(color: Colors.red, fontSize: 25),</td>
        </tr>
  </table>
</div>


    </div>

  </div>
</div>

      </div>
      <div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/1a2cc4d1a176a22531807e87261dd6ea/raw/39a2c2aa97e5b3f34a9be63f7cef83c4eac5be06/flutter_demo_main_line50_color.dart" style="float:right" class="Link--inTextBlock">view raw</a>
        <a href="https://gist.github.com/dsibinski/1a2cc4d1a176a22531807e87261dd6ea#file-flutter_demo_main_line50_color-dart" class="Link--inTextBlock">
          flutter_demo_main_line50_color.dart
        </a>
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
    </div>
</div>

</div></figure>



<p>Save <em>main.dart</em> file by pressing Ctrl+S. Take a look at your smartphone and see the magic:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" data-attachment-id="3689" data-permalink="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/flutter_hotreload-1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?fit=1080%2C2280&amp;ssl=1" data-orig-size="1080,2280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Flutter_HotReload-1" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?fit=142%2C300&amp;ssl=1" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?fit=485%2C1024&amp;ssl=1" src="https://i1.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?fit=485%2C1024&amp;ssl=1" alt="Flutteer's hot reload in action" class="wp-image-3689" width="364" height="768" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?resize=142%2C300&amp;ssl=1 142w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?resize=485%2C1024&amp;ssl=1 485w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?resize=768%2C1621&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?resize=728%2C1536&amp;ssl=1 728w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?resize=970%2C2048&amp;ssl=1 970w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2019/12/Flutter_HotReload-1.jpg?resize=676%2C1427&amp;ssl=1 676w" sizes="auto, (max-width: 364px) 100vw, 364px" /></figure></div>



<p>Notice how the color of number &#8220;7&#8221; (counter value) changed to red while its value remains untouched. Quite a nice feature for quick development <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> </p>



<p>I noticed that sometimes it doesn&#8217;t work that smoothly and you need to restart the app to see the changes. However, it happens only with some bigger code changes. Flutter quite young SDK and tools are still developing quickly so I hope such drawbacks will be eliminated soon.</p>



<h2 class="wp-block-heading">Summary</h2>



<p>Today we&#8217;ve seen how easy it is to start working with Flutter. We got familiar with basic Flutter concepts like widgets. We&#8217;ve also created our first Flutter app and debugged it. Finally, we&#8217;ve seen the very cool hot reload feature in action <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4aa.png" alt="💪" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>For me, Flutter looks promising. After my adventures with <a rel="noreferrer noopener" aria-label="Xamarin (opens in a new tab)" href="https://www.codejourney.net/xamarin/" target="_blank">Xamarin</a>, which mostly felt like changing Java to C# and Android Studio to Visual Studio, I&#8217;m excited to try something fresh and totally different.</p>



<p>I know this was just a simple introduction to Flutter, but there&#8217;s more coming! I hope to publish the next articles about Flutter as I continue playing with it. If you&#8217;ve ever used Flutter and have some good sources to recommend &#8211; let me know in the comments!</p>



<p>Stay tuned!</p>


<p>The post <a href="https://www.codejourney.net/your-first-flutter-app-in-30-minutes/">Your First Flutter App in 30 Minutes</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/your-first-flutter-app-in-30-minutes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3652</post-id>	</item>
	</channel>
</rss>
