<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Guilherme V. on Medium]]></title>
        <description><![CDATA[Stories by Guilherme V. on Medium]]></description>
        <link>https://medium.com/@valiodas?source=rss-46e7ddacc193------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*uX9wMa5fLDv7CBhaFBgwPw.jpeg</url>
            <title>Stories by Guilherme V. on Medium</title>
            <link>https://medium.com/@valiodas?source=rss-46e7ddacc193------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:44:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@valiodas/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter — Layout system overview]]></title>
            <link>https://itnext.io/flutter-layout-system-overview-c70bbe9ba909?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/c70bbe9ba909</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Sat, 22 Aug 2020 03:57:28 GMT</pubDate>
            <atom:updated>2020-08-24T06:13:18.240Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — Layout system overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mVLppo8C5pN1aZRPtveEzw.png" /></figure><p>Recently, I’ve decided to focus on Flutter fundamentals. This time I’m trying to understand a little better “how the Layout system works,” answering questions like:</p><ul><li>The size of my Widget doesn’t look right, what’s happening?</li><li>I only want to put my Widget in a specific position, but there isn’t any property to control that, why?</li><li>I keep seeing terms like <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a>, <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a>, and <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a>. How is it all related?</li><li>It would be possible to have a general idea of how does the layout system works?</li></ul><p>This article doesn’t mean to be an in-depth and detailed description of everything above. But we’ll get a good overview of the most important things, trying to visualize whatever is possible.</p><h4>“Two Phases” Layout System and Constraints</h4><p>First things first, Widgets are the building blocks of Flutter SDK, but they aren’t responsible for drawing themselves into the screen. Every Widget is associated with a <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a> object that is responsible for that. These boxes are a 2D Cartesian coordinate system, with <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a> expressed as the offset from the origin point. Every <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a> will also be associated with a <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a> object, that holds four values: <em>max|min width</em>, and <em>max|min height</em>. A <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a> can choose to have any <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a> it wants, but it must respect those values/constraints. The size/position a Widget has depends purely on these RenderBox’s properties. The same way Widgets build a Widget three, RenderBoxes make a render three.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LG2bCyf8VbQm5-f6qCl_kw.png" /></figure><p>We can think of Flutter’s layout system as a 2-phase system. During the first phase, the framework walks down the render tree passing <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a> objects from Parent to child(s) recursively. It gives parents a way to opine/enforce their children’s <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a>, updating these constraints as they like. In other words, this is the phase responsible for propagating the constraining information, letting everyone know about its max/min size possible.</p><p>Once done, the second phase starts. This time, every <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a> passes back to its Parent the <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a> it has chosen. The Parent collects the <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a> of all its children, and then It uses this geometric information to position each one correctly inside its own Cartesian system. It is the phase responsible for sizing and positioning where parents know how big each child will be, and where they’ll be placed.</p><p>So, in the end, what does all that mean?</p><p>It means that Parents are responsible for defining/limiting/constraining their children’s size and positioning them relative to its coordinate system. In other words, a Widget can choose its size, but it must always respect the constraints received from its Parent. Furthermore, a Widget doesn’t know its position on the screen, but its Parent does.</p><p>If you have a problem with a Widget’s size or position, try to look at (update) its Parent.</p><h4>Example</h4><p>Ok, let’s visualize all that, trying to understand what is happening through an example. But before, here are some terms that may be useful when debugging constraints:</p><ul><li>If<em> </em><strong><em>max(w|h) = min (w|h)</em></strong>, that is <strong><em>tightly</em></strong> constrained.</li><li>If <strong><em>min(w|h) = 0</em></strong>, we have a <strong><em>loose</em></strong> constraint.</li><li>If <strong><em>max(w|h) != infinite</em></strong>, the constraint is <strong><em>bounded.</em></strong></li><li>If <strong><em>max(w|h) = infinite</em></strong>, the constraint is <strong><em>unbounded.</em></strong></li><li>If <strong><em>min(w|h) = infinite</em></strong>, is just said to be <strong><em>infinite</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4EkyzsvBzMlYfMufea1kQ.png" /></figure><p>The app we’ll be using is a slide modified version of the initial app template. In general, you have two easy ways to check a widget <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a>, and it’s properties:</p><ol><li>Doing by code: We can intercept the <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a> propagation during the layout system first phase using LayoutBuilder, and check the constraints. Then, after the second phase finishes, we use keys to get the widget’s <a href="https://api.flutter.dev/flutter/rendering/RenderBox-class.html">RenderBox</a> and be able to check <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a>, Position.</li><li>Or using the DevTools Widget Inspector:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AT__J3lxx3j5VjoxPw3i1w.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9ef629a8cf9825ab47f9313d130b89d/href">https://medium.com/media/a9ef629a8cf9825ab47f9313d130b89d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bXjBdoLrfjlhf8nmNRshA.png" /><figcaption>Printed constants</figcaption></figure><p>Let&#39;s go step by step and see what&#39;s happening (we&#39;ll ignore LayoutBuilders here).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*89dGdagDNw6aNtrq5Z4EhQ.gif" /></figure><p>The first thing that happens in our example is the main executing runApp(..). This function checks the screen current size (<strong>in our case 392:759</strong>), and then it creates a <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a> object holding the constraints that will be sent to our first widget (MyApp). Note that <strong><em>max|min width and height are all equals</em></strong>; therefore, runApp uses a <strong><em>tight</em></strong> constraint — by doing so, MyApp will have no choice when choosing its size besides filling the full space available on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nsV-7cIMxNR-MHc3UAs1Lg.gif" /></figure><p>The constraints are then propagated down the Widget tree. MyApp , MaterialApp , HomePage , and Scaffold are all informed about the same <strong><em>tight</em></strong> constraints. So all will be forced to fill the full screen. Each widget has a chance to inform a different <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a> to its child (still respecting the one it has received). But, in this case, they have chosen not to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqubLnQ8f8Xfn05JGpC8Cg.gif" /></figure><p>Now things start to get more interesting. Scaffold informs AppBar about about the <a href="https://api.flutter.dev/flutter/rendering/BoxConstraints-class.html">BoxConstraints</a> it must use, but, this time, it uses a <strong><em>loose</em></strong> constraint (min h = 0). It gives AppBar a chance to choose any height it wants, but it must still use width = 390.</p><p>AppBar is a special kind of widget called PreferredSizeWidget. This type of widgets <em>won&#39;t impose</em> any constraints on its child. If you try to use LayoutBuilder to get Title &#39;s constraints, you&#39;ll get an error. Instead, AppBar responds to Scaffold with a preferred/default size: <em>height = 80</em>, <em>width = 392 </em>(forced by the received constraints)</p><p>After getting AppBar &#39;s <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>Size</em></a><em>, </em>Scaffold goes on to its next child: Center</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GD68iWA9nEcjLYa7plg_hQ.gif" /></figure><p>Ok, a lot of things going on here. Let&#39;s try to understand:</p><ol><li>Scaffold informs Center its constraints, letting it choose any size between 0 &lt; w &lt; 392 and 0 &lt; h &lt; 697. Note that max height is <strong>759 (screen max height) minus 80 (height that AppBar has chosen)</strong></li><li>Center goes to its child, Text, forwarding the same constraints/</li><li>Text picks a Size that is enough to show its data (279:16), and answer back Center.</li><li>With that geometric information <a href="https://api.flutter.dev/flutter/dart-ui/Size-class.html"><em>(Size</em></a><em>)</em> on hands, Center can correctly position Text inside its Cartesian system. As a parent, the Center has the right to choose its child position, and, in this case, it decides to centralize it.</li></ol><p>The flow goes on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xu8RduNCQJAs4_VttjJAPA.gif" /></figure><ol><li>Then the Center chooses a Size for itself, but instead of only picking an &quot;enough&quot; size (like Text did), It decides to be as big as possible, accordingly the constraints it has received.</li><li>Scaffold receives Center wanted size, and the flow goes on in direction to its last-child: FAB</li><li>FAB receives the constraints and gives back to Scaffold its preferred size (56:56)</li><li>Finally, Scaffold has all the geometric information it needs to position each child inside its Cartesian system too.</li></ol><p>Lastly, the process is repeated for all widget above Scaffold :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOjBaMvX114eD8S4nFxLTQ.gif" /></figure><ol><li>The Size information continues to be propagated up the render tree.</li><li>Every widget uses this information to position each child inside the Cartesian System.</li><li>Scaffold answer HomePage, that answers MaterialApp , that in turn answer MyApp. Until if finally reach Main again.</li><li>Main get this &quot;final&quot; widget and ultimately bind it into the screen.</li></ol><p>The RenderBox tree is finally bound on the screen. We have a running app.</p><h4>Something interesting to remember</h4><ul><li>A Widget doesn&#39;t know its position on the screen; its parent does.</li><li>A Widget can choose the Size it wants to have, but it must be according to its parent’s limits.</li><li>The constraints are propagated down, and the Size up.</li><li>Try to learn that constraints terms, they may be useful later.</li></ul><p>I hope all this has helped you understand a better how the Flutter layout system works. If this post cast🧙‍♂️ a small light 💡 on this shadow, please, consider following me on Twitter too:</p><p>☕️ <a href="https://twitter.com/GuiSilvaV">Twitter</a></p><p>☕️ <a href="https://www.linkedin.com/in/guilherme-silva-aa042a27/">LinkedIn</a></p><ul><li><a href="https://github.com/guilherme-v">guilherme-v - Overview</a></li><li><a href="https://itnext.io/flutter-how-to-dismiss-keyboard-globally-a543452cfefa">Flutter — How to dismiss keyboard globally</a></li><li><a href="https://medium.com/@valiodas/flutter-inspecting-http-request-response-payloads-and-sharedpreferences-dbd3d0cc309e">Flutter — Inspecting HTTP Request/Response Payloads and SharedPreferences</a></li><li><a href="https://medium.com/@valiodas/dart-isolates-and-computation-e6bbbb076d74">Dart — Isolates</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c70bbe9ba909" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/flutter-layout-system-overview-c70bbe9ba909">Flutter — Layout system overview</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — How to dismiss keyboard globally]]></title>
            <link>https://itnext.io/flutter-how-to-dismiss-keyboard-globally-a543452cfefa?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/a543452cfefa</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 01:07:59 GMT</pubDate>
            <atom:updated>2020-08-13T06:39:25.719Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — How to dismiss keyboard globally</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*sg3pyyc63zsNt_C5.gif" /></figure><p>When working with Flutter, we regularly try to mimic platform-specific behaviors. For example, the <em>keyboard</em> on iOS usually hides automatically once the user taps any place in the screen out of a TextField.</p><p>One way to replicate this is by controlling the Focus manually in each screen that contains a TextField; once it loses the Focus, we dismiss the keyboard. It is a tedious solution, prone error, and generates a lot of code.</p><p>A better way is to set this behavior globally in our Flutter app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8210d920f6150dd0969efc6d6fcb12ca/href">https://medium.com/media/8210d920f6150dd0969efc6d6fcb12ca/href</a></iframe><p>The <strong>builder</strong> method from <strong>MaterialApp</strong> can be used for inserting widgets above the Navigator but below the other widgets. We’ve simply added a “global” <strong>GestureDetector</strong> that will handle the keyboard dismiss for us. The result can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*lAt8OA8lmy-au9NQg1YUyA.gif" /><figcaption>TextFields using the same &quot;global&quot; GestureDetector to dismiss the keyboard</figcaption></figure><p>☕️ <a href="https://twitter.com/GuiSilvaV">Twitter</a></p><p>☕️ <a href="https://www.linkedin.com/in/guilherme-silva-aa042a27/">LinkedIn</a></p><p><a href="https://github.com/guilherme-v">guilherme-v - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a543452cfefa" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/flutter-how-to-dismiss-keyboard-globally-a543452cfefa">Flutter — How to dismiss keyboard globally</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dart — Exploring Zones & Prints]]></title>
            <link>https://medium.com/@valiodas/dart-exploring-zones-prints-41c8a44e139a?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/41c8a44e139a</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Thu, 06 Aug 2020 00:50:05 GMT</pubDate>
            <atom:updated>2020-08-06T00:50:05.186Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dart — Exploring Zones &amp; Prints</h3><p>Giving continuity to the series of articles to better understanding how Dart supports <strong>asynchronous programming </strong>— through <em>Isolates, Zones, Computation, Streams, and Futures. </em>In this article, we’ll talk about the <strong>Zones </strong>concept, getting an overall look at it, exploring what it is, and some things we can do with it.</p><p>At the end of this article, we’ll use <strong>Zones to replicate Crashlytics behavior</strong>. But instead of logging crashes in a remote server, our Emulator will send all our prints to a local server that will save everything into a File.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X7_BmCsqtYzm3SLmrIZScA.png" /></figure><p>The Dart <a href="https://api.flutter.dev/flutter/dart-async/Zone-class.html">documentation</a> has a few interesting facts:</p><blockquote>1. The code is always executed in the context of a zone. The initial main function runs in the context of the default zone (<a href="https://api.flutter.dev/flutter/dart-async/Zone/root-constant.html">Zone.root</a>).</blockquote><blockquote>2. A zone represents an environment that remains stable across asynchronous calls.</blockquote><blockquote>3. Developers can create a new Zone and overrides some of the functionalities.</blockquote><p>Let&#39;s try to understand better what does that means.</p><blockquote>1. The code is always executed in the context of a zone. The initial main function runs in the context of the default zone (<a href="https://api.flutter.dev/flutter/dart-async/Zone/root-constant.html">Zone.root</a>).</blockquote><p>So, basically, a Zone works like an <strong>executing context</strong>. It’s a virtual area inside an <em>Isolate</em> that can hold<strong> variables</strong>, declare<strong> pre-define behaviors</strong>, provide<strong> hooks to execution points</strong>, and run<strong> your code in isolation</strong>. It means that is that if some unexpected exception happens in one Zone, it won’t affect the others.</p><blockquote>If you don’t remember what an Isolate is, imagine an Isolate like a box containing <em>Memory</em>, running a S<em>ingle Thread</em>, an E<em>vent Loop</em>, and one or more <em>Zones</em>. Check this article to know more about it: <a href="https://medium.com/@valiodas/dart-isolates-and-computation-e6bbbb076d74">Dart — Isolates</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HcnpI_Nlbu28VdSadbPJ6A.png" /><figcaption>Isolate running code into it&#39;s default &quot;Root zone&quot;</figcaption></figure><blockquote>2. A zone represents an environment that remains stable across asynchronous calls.</blockquote><p>This is probably the main reason to use Zones;<strong> it translates to its ability to handle uncaught errors/exceptions</strong>. It’s like a global try-catch block, but the error handler might be invoked multiple times. If you used <strong>Crashlytics</strong> before, you probably have noticed the following line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kew2V7EgnzsqGFF8nbmhtA.png" /><figcaption>Crashlytics exploring Zones capabilities</figcaption></figure><p><strong>Crashlytics</strong> works <em>creating a new Zon</em>e, and logging remotely all errors caught by the app. The original RootZone won’t be affected by any crash, which will make our app keep running.</p><blockquote>3. Developers can create a new Zone and overrides some of the functionalities.</blockquote><p>When creating custom Zones, Developers can replace or modify the behavior of print, timer, microtasks, and how uncaught errors are handled. To define these things, we need to create a Specification object and pass it to the runZoned method.</p><p>Two things I’ve always missed when logging are: the <strong>App’s name</strong>, and a <strong>Timestamp.</strong> So let’s try to override the default behavior of all prints to include it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DRRatIKIK80D2ddR8cj6cQ.png" /><figcaption>Print override output</figcaption></figure><h3>Exploring all that in a Flutter App</h3><p>So let’s create a Flutter app and tries to:</p><ol><li>Include the App’s name and a Timestamp in all prints.</li><li>Changing the color of our App’s print to differentiate it from the rest of the log’s prints.</li><li>Create a local server and send all our prints to that. It’ll save them in a local file that we can use later to search for something using Cmd+f(a functionality that, for some reason, is still missing in the default’s VSCode Debugger)</li></ol><p>We’ll start by creating a local server that will capture all requests and log them in a File:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b29b56d8e16e1c317ef9ca0e42f3cd92/href">https://medium.com/media/b29b56d8e16e1c317ef9ca0e42f3cd92/href</a></iframe><p>Then we execute it to start listening:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwmoIvYZILlK32zEPV5Yzg.png" /><figcaption>Start the Server</figcaption></figure><p>The next step is to create our app. Start by updating our <em>pubspec.yaml</em> file to include the following packages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DqWU6lh6g_Av-5iUsgvu4Q.png" /><figcaption>Packages required</figcaption></figure><p>We need to create our Zone, intercept all print calls, customize our print color, and send the messages to our local running server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbfe7cfd46b91baf23eb02735e38ae97/href">https://medium.com/media/fbfe7cfd46b91baf23eb02735e38ae97/href</a></iframe><p>The <strong>MyApp</strong> class simply executes a print after the user taps a button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ee6ac11f2bb2a325fd1c914cef8ac65/href">https://medium.com/media/6ee6ac11f2bb2a325fd1c914cef8ac65/href</a></iframe><p>If you check your Debug Console you’ll see our <strong>Timestamp</strong>, <strong>app&#39;s name</strong>, and <strong>custom color</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1spXozGMo0B07ou8WEeQA.png" /></figure><p>And our local <strong>log.tmp</strong> file will contain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IYbPMG2RE-UC5-NOs6Sv1g.png" /><figcaption>Logs saved locally</figcaption></figure><p>☕️ <a href="https://twitter.com/GuiSilvaV">Twitter</a></p><p>☕️ <a href="https://www.linkedin.com/in/guilherme-silva-aa042a27/">LinkedIn</a></p><p><a href="https://github.com/guilherme-v/medium_flutter_zones">guilherme-v/medium_flutter_zones</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41c8a44e139a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — Inspecting HTTP Request/Response Payloads and SharedPreferences]]></title>
            <link>https://medium.com/@valiodas/flutter-inspecting-http-request-response-payloads-and-sharedpreferences-dbd3d0cc309e?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbd3d0cc309e</guid>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[inspector]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[devtools]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Sat, 01 Aug 2020 20:29:02 GMT</pubDate>
            <atom:updated>2020-09-08T13:48:33.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — Easily inspecting HTTP Request/Response Payloads and SharedPreferences</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2hDB88860vhw1XtgfWkbcA.png" /><figcaption>HTTP Request payload</figcaption></figure><p>If you are a Flutter developer, chances are you are familiar with DevTools, an excellent suite of performance and debugging tools for Dart and Flutter. It’s under constant development, and the chances are that it’ll become the best tool out there.</p><p><em>But today </em><strong><em>it has some limitations</em></strong>, like the fact it can only inspect the header of HTTP requests and responses, or we can’t yet inspect/edit internal shared preferences used by our apps.</p><p>I want to share with you my favorite Plugin to do this kind of thing: <a href="https://pub.dev/packages/flutter_stetho"><strong>Flutter Stetho</strong></a> lib. The use is relatively easy if compared with other plugins capable of doing the same:</p><ol><li>Add it in your <em>pubspec.yaml</em> file — I recommend to use the version below instead of the official one (currently with some bugs that prevent us from seeing the request body)</li></ol><pre>flutter_stetho:<br>    git:<br>      url: https://github.com/brianegan/flutter_stetho<br>      ref: 1787dd145d792e92427c9e2ffbb6dbffede1bcbb</pre><p>2. After that, you only need to start it in your <em>main.dart</em> file (prefer to initialize it only to your “dev” environment).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edf873ad2d7c63750148878c5abdcee3/href">https://medium.com/media/edf873ad2d7c63750148878c5abdcee3/href</a></iframe><p>Then all you need to do is open Chrome web browser and go to &quot;<strong>chrome://inspect</strong>&quot; to see a list of your apps. Click upon &quot;<strong>inspect</strong>&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqD2pm68kT7byQlCgTW6dQ.png" /><figcaption>chrome://inspect</figcaption></figure><p>After that, click in the “<strong>Network</strong>” tab to see a list with all your Requests:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHJr4S8fAlYEpx4FwTr2dQ.png" /><figcaption>Network tab</figcaption></figure><p>You should be able to see all the HTTP Headers, as well the Payload of any call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2hDB88860vhw1XtgfWkbcA.png" /><figcaption>HTTP Request payload</figcaption></figure><p>If you are using <strong>SharedPreferences</strong>, you can also inspect/edit all the &quot;key-value&quot; pairs saved</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NN_CFE3P8ie-edgSo5-w0A.png" /><figcaption>Shared Preferences inspection</figcaption></figure><h4>Some limitations:</h4><ul><li>Currently, the above solution works only in Android, but it’s usually enough to check all your network requests and key-values saved into SharedPreferences.</li></ul><p><a href="https://github.com/guilherme-v/flutter-clean-arch">guilherme-v/flutter-clean-arch</a></p><p>☕️ <a href="https://twitter.com/GuiSilvaV">Twitter</a></p><p>☕️ <a href="https://www.linkedin.com/in/guilherme-silva-aa042a27/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbd3d0cc309e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Flutter Http Interceptor]]></title>
            <link>https://medium.com/@valiodas/simple-flutter-http-interceptor-53f8ad316b7c?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/53f8ad316b7c</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[http-interceptors]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[http-client]]></category>
            <category><![CDATA[override]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Sat, 25 Jul 2020 21:46:46 GMT</pubDate>
            <atom:updated>2020-08-06T01:02:52.665Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — Simple Http Interceptor</h3><p>Once a while, we need to <em>intercept</em> all Http calls and do something with them. E.g., Including an “<strong>Authorization</strong>” header that contains an &quot;<strong>AccessToken&quot;</strong>.</p><p>There are different ways to do this kind of thing, and each one has its pros and cons. My favorite option is creating a <em>Custom Http Client</em>, and start using it through all the app.</p><p>When using Flutter and the known http.Client class from http/http.dart package, we can do it quickly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fce71f1409d5cc1af2075cbfb1bf8f84/href">https://medium.com/media/fce71f1409d5cc1af2075cbfb1bf8f84/href</a></iframe><p>Then instead of httpClient = http.Client(); use httpClient = AuthenticatedHttpClient().</p><h4>Some interesting points:</h4><ul><li>Try to create a Singleton from this class. This way, you can take advantage of the in-memory token cache and avoid having to fetch it from local storage on every call.</li><li>Also, if you are using it as a Singleton, remember to “reset” the token after you log out the User.</li></ul><p>☕️ <a href="https://twitter.com/GuiSilvaV">Twitter</a></p><p>☕️ <a href="https://www.linkedin.com/in/guilherme-silva-aa042a27/">LinkedIn</a></p><p><a href="https://github.com/guilherme-v">guilherme-v - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53f8ad316b7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dart — Isolates]]></title>
            <link>https://medium.com/@valiodas/dart-isolates-and-computation-e6bbbb076d74?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6bbbb076d74</guid>
            <category><![CDATA[isolate]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 22:28:27 GMT</pubDate>
            <atom:updated>2020-08-06T01:02:28.270Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkbJZ9vVBd8aNSJV3OmWyQ.png" /></figure><h3>Dart — Isolates</h3><p>I recently decided to try to understand a little better how Dart supports <strong>asynchronous programming</strong> — through <em>Isolates, Zones, Computation, Streams, and Futures </em>— despite being a <strong>Single Thread Language</strong>. The first step is to learn the foundation better, so it seems <em>Isolates</em> would be a good start. You probably will not be using Isolates often, but this class is the basic block, responsible for supporting everything else.</p><h4>So, what is an isolate?</h4><p>You can imagine an Isolate like a box (or context) containing <em>Memory</em>, and a S<em>ingle Thread</em> running, and E<em>vent Loop </em>continuously. When you start your application, Dart VM automatically creates an instance of an <strong>Isolate</strong> and runs your “<strong>main</strong>” code on it.</p><p>To access the current Isolate being executed, you can Isolate.current. This object offers you some control methods and properties:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YXBfR1pRM0YPCdEx4rKC7A.png" /></figure><p>By default, the “main” Isolate is also called “<strong>main</strong>”, and, once main code execution is done, it finishes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5mOfpqV3nTNaSicPCadsA.png" /></figure><p>Besides <em>Memory</em>, a single <em>thread</em>, and the <em>event loop</em>, each Isolate also has a <strong>ControlPort</strong>, which is used to send messages of control and identification.</p><p><strong>Every ControlPort is also linked to its SendPort</strong>. In theory, we can send messages to this <strong>SendPort. </strong>They would be received by the ControlPort, and processed by an internal listener. But I wasn’t able to find out a way to register a listener to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qC_ED2JZJjifnlruDBdDcg.png" /><figcaption>Overview of an Isolate</figcaption></figure><p>I want to be able to create a second Isolate and make them send messages to each other. To be able to register listeners and process messages, we can create a new port called mainControlPort. Once we have created it, we can send messages to it from other Isolates, and <em>the program keeps running, waiting for messages, until it’s manually killed</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eKAnRNF_T7DCqDRCAApuTw.png" /><figcaption>The program keeps running after we added a ReceivePort</figcaption></figure><p>Now we need to create a second instance of an Isolate. There are different ways to do it; we can create a new isolate using the constructor method Isolate(...)` or use the static method Isolate.spaw. If you have a background on Akka or Elixir, you will notice the resemblance with withActors. For example, suppose we want to create a second Isolate that sends the current timestamp each second:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0db3d05d03e6242e8335be71e2d2de08/href">https://medium.com/media/0db3d05d03e6242e8335be71e2d2de08/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*46cYfwN8QHwHdyBc-o_kkw.png" /><figcaption>terminal output</figcaption></figure><h3>A full example: 2 Isolates with messages coming from both sides</h3><p>Now a full example, let’s create two isolates and make them communicate with each other. The MainIsolate will send the TimerIsolate a start message, then TimerIsolate will start sending MainIsolates a timestamp after each second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkbJZ9vVBd8aNSJV3OmWyQ.png" /><figcaption>full example overview</figcaption></figure><p>To be able to send messages on both directions, we need to give the <strong>TimerIsolate</strong> its <strong>ControlPort</strong> as well, while also informing <strong>MainIsolate</strong> about it. You can check the full example below; I believe it’s self-explanatory enough:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a285a4995e6de0f3644931b4e44d7f90/href">https://medium.com/media/a285a4995e6de0f3644931b4e44d7f90/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdBsUcr_XD-5f9GWNAkAtA.png" /><figcaption>Terminal output</figcaption></figure><p>☕️ <a href="https://twitter.com/GuiSilvaV">Twitter</a></p><p>☕️ <a href="https://www.linkedin.com/in/guilherme-silva-aa042a27/">LinkedIn</a></p><p><a href="https://github.com/guilherme-v">guilherme-v - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6bbbb076d74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why SOLID is important?]]></title>
            <link>https://medium.com/@valiodas/why-solid-is-important-8c1e99f56dd4?source=rss-46e7ddacc193------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c1e99f56dd4</guid>
            <category><![CDATA[solid-principles]]></category>
            <dc:creator><![CDATA[Guilherme V.]]></dc:creator>
            <pubDate>Fri, 08 May 2020 01:10:50 GMT</pubDate>
            <atom:updated>2020-05-08T01:10:50.413Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Evident and yet sometimes ignored situations where SOLID may help</em></p><h3>What</h3><p>If you have been a developer for a while, you probably already know the acronym above. It represents a set of 5 programming principles that offer guidance and useful advice when coding. Each one of these represents a coding design technic made to avoid well-known problems.</p><blockquote>Each one of these represents a coding design technic made to avoid well-known problems</blockquote><p><strong>It is not my intention here to go through each one of the principles</strong>. You can easily find plenty of articles out there discussing each of them deeply. Instead, I merely intend to share with you my own experience regarding it, and some satisfying outcomes I believe also be reachable by any team.</p><h3>The Journey</h3><p>I have been working as a developer for a long time now. Along the way, I have the pleasure to be taught by amazing people with different points of view and opinions about SOLID.</p><p>There were those with a deep understanding of each principle. Others that had no idea what each letter stands for, but given years of experience had already assimilated the practices into their way to do things. And some have just read something online to use during the interview process — I was one of those years ago.</p><p>I admit that it took me a while to see the value behind what seemed to be in most cheap talk of senior developers. I pretty much ignored the principles until I become technically responsible for projects and teach other developers. At this moment, I started to notice some interesting and recurring facts:</p><ol><li>Commonly, the concern with code quality is present, just as the question: “How do I know what I am building is <em>right</em>?”.</li><li>Giving code feedback while reviewing PRs is not an easy task. Programming involves creativity, creativity leads to different paths and different solutions. If you put into the equation variables like overengineering and proud programmers, you may end up in a sensible scenario.</li><li>Eventually, people will — without any reason — let/hope just time itself ends up proving the solution they imagined is a good one.</li><li>Sometimes, programmers smell something seem <em>do not fit</em>, but had no idea why, or even what.</li><li>Business is not concerned about how things are done. They just want the flexibility they need to validate ideas and iterate faster.</li></ol><p>IMHO the problems listed above can be solved in many different ways, but this is a post about SOLID. I just want to show how remembering it exists can help you when dealing with these problems.</p><p>When looking at the first situation, <em>“How do I know what I am building is right?”</em>. Well, I do not believe there is a silver bullet to be used here, or we probably would see fewer bugs out there. But this is why we created principles in the first place, to show us a direction when things are not exactly clean.</p><p>To the second situation, the <em>&quot;PRs reviewer&quot;</em> situation. Maybe would be better to avoid opinionated discussions and try to elaborate arguments around well-established information. If you bring principles to the conversation at this point, a common ground is placed, and the chances are everything will be handled easier, and with better results.</p><p>About the third situation, the <em>“let time proves I am right”</em> situation. First, let state the obvious, the phrase would be better put this way: “Let time proves or business pay.” There is no reason why not to take 5 minutes and check the solution against principles. Sometimes, some of them will not make sense of the situation. But in other, it will be time worth spending.</p><p>About the fourth situation, the <em>“something smells wrong”</em> situation. This is a classical one, and I let you with <a href="https://sites.google.com/site/unclebobconsultingllc/getting-a-solid-start"><em>this article</em></a> from Uncle Bob answering it. He explains it better than I ever could, and the link is for sure a worth reading.</p><p>And finally the last one, the <em>“business”</em> situation. Business wants to iterate faster, so flexibility is a requirement. In terms of programming, flexibility means low coupling here. And all the point around SOLID principles is that they were designed to dodge well-known traps and to make it easy to apply changes in your code.</p><h3>Conclusion</h3><p>It is important to understand that SOLID Principles do not represent an absolute truth, and to every case, there is always an exception. Adhering to them will not turn you instantly into a skilled programmer, neither the code you write immediately in a good one. But they represent a solid step in the right direction and a vaccine against different classes of daily problems when they are not forgotten in your skillset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c1e99f56dd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>