<?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 Gabriel Moreyra on Medium]]></title>
        <description><![CDATA[Stories by Gabriel Moreyra on Medium]]></description>
        <link>https://medium.com/@gabobrandx?source=rss-407c8b6ee83d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jvEGfaf8leryiqB_Eu3aoA.jpeg</url>
            <title>Stories by Gabriel Moreyra on Medium</title>
            <link>https://medium.com/@gabobrandx?source=rss-407c8b6ee83d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:03:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gabobrandx/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[Finally, I’m Self-Committed to Writing Unit Tests]]></title>
            <link>https://medium.com/codex/finally-im-self-committed-to-write-unit-tests-7ac5768ada04?source=rss-407c8b6ee83d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ac5768ada04</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Gabriel Moreyra]]></dc:creator>
            <pubDate>Fri, 21 May 2021 19:37:00 GMT</pubDate>
            <atom:updated>2022-01-11T16:16:11.224Z</atom:updated>
            <content:encoded><![CDATA[<p>How long has it been since you faced the frustration of fixing bugs or adding new functionalities into a nasty project full of bad code? I’ve started to work on one this week. The thing is that the project itself is fun and innovative, but the code.. oh gosh.. the code is awful, full of thousand lines files, code smells, bad naming and a long etc. Is not like I haven’t written code like that in my first years, but hope you understand my point.</p><p>When I read the code I felt annoyed. At first, I was tempted to make the changes as quickly as possible, keeping the same line of careless coding the previous development team introduced. Then I thought about all the things that could go wrong like introducing new bugs and eternal debugging sessions; keeping in mind that this is a new project for me, I’m just learning about the main domain rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OLuL8ZDZOo-7fQXDgyi3dg.jpeg" /></figure><h4>Refactoring is the way to go?</h4><p>After some deliberation in my thoughts, I came to the conclusion that I should refactor the code before adding new changes. And I know it is so obvious it could not be another way, but I’ve been struggling until I accepted this fact. Anyway, a bigger problem appeared: there was not a single unit test in the solution.</p><p>By chance, have you read “Refactoring: Improving the Design of Existing Code” by Martin Fowler? If you didn’t, I strongly suggest you do! Fowler explains that you can’t refactor code if you have no tests. Because if you happen to do so, you wouldn’t be confident you’re not breaking functionality. And refactoring does not imply breaking the functionality in the process; otherwise is not refactoring, is mostly deleting and redoing.</p><p>So that was my problem: no tests and no possibility of refactoring (at least in the Fowler way). But Fowler considers a situation like mine in his book, only that he recommends reading another book to know how to proceed: “Working Effectively with Legacy Code” by Michael Feathers. This book completely changed my mind about unit tests.</p><p>Along with my career, I’ve had the opportunity of learning how to write good unit tests. I’ve learned about how to identify testing scenarios, testing data boundaries, reducing test fragility, decoupling, mocking vs stubbing, TDD (I’m convinced writing the test first is beneficial for specific reasons), testing the tests, etc. I’ve applied this knowledge in my work, and made an effort to promote it with my colleagues, and the benefits were noticeable. Nevertheless, there were times when I’ve just avoided unit tests, to be honest, and mostly because of laziness or deadlines. But now I’m strongly decided to <em>never push legacy code again</em>.</p><h4>Stop writing legacy code</h4><p>Yes, you’ve read right, I’ve said legacy code. Because Feathers taught me that code without unit tests is legacy code. And it makes a lot of sense when you think about it. What do we generally consider legacy code? Well, we can say is old bad written code we receive from another programmer (and that programmer could be our past self). But that’s not the whole picture. Legacy code is about code you struggle to read and understand. And, more important, legacy code is code you are reluctant of making changes in.</p><p>In other words, as soon as we push our shiny new code (without unit tests) into a repository, it automatically becomes legacy code 🤯.</p><blockquote>“Code without tests is bad code. It doesn’t matter how well written it is; it doesn’t matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don’t know if our code is getting better or worse.” - Michael C. Feathers</blockquote><p>Then, how do we make sure our code does not become legacy? By writing clean code, we do our most to make our code readable for newcomers, to decouple our components by using abstractions so it’s easier to change. All that’s good stuff. But how do we prove our code is free of rot at all? Have we convinced our concept of clean code is the best for everyone? Is clean code assuring by itself that newcomers will be able to introduce new changes with confidence?</p><h4>Unit Tests to the rescue</h4><p>The answer is no. And here is where unit tests come into play. No matter how good we think our code is, it’s not sufficient to give future developers or our future selves peace of mind. Unit tests are the only way of supplying reliance to other people. And we talk specifically about unit tests because they’re fast and can be run frequently in a matter of seconds (a few minutes at most).</p><p>Feathers book talks about the techniques required to go from legacy code to good code. It’s not an easy task, but his advice certainly makes it more bearable. I highly recommend it for anyone who’s facing a situation like mine and sometimes feels overwhelmed. It’s helping me a lot with my new project and is such a pleasure to see how it’s becoming a more robust software day by day.</p><h4>My new commitment</h4><p>I feel bad for those people how had the bad luck of working with any of the code I’ve left behind uncovered because I know how it feels to be in their place. Programming should be joyful work, and I really want to contribute to that goal not only for my future self but for my colleagues. Let’s make a commitment to never write code without tests ever again until there is no more legacy code! As if that were possible 😅</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ac5768ada04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/finally-im-self-committed-to-write-unit-tests-7ac5768ada04">Finally, I’m Self-Committed to Writing Unit Tests</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter challenge #1 — Wg by Sarah-D]]></title>
            <link>https://gabobrandx.medium.com/dribbble-challenge-1-cupertino-widgets-and-a-simple-custom-drawer-for-ios-1c3a2cd4d221?source=rss-407c8b6ee83d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c3a2cd4d221</guid>
            <category><![CDATA[dribbble]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Gabriel Moreyra]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 03:01:09 GMT</pubDate>
            <atom:updated>2020-04-14T14:18:30.277Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter challenge #1 — <em>Wg</em> by <a href="https://dribbble.com/Sarah-D">Sarah-D</a></h3><p>Cupertino widgets and a simple custom Drawer for iOS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ufEPILKHEQvB9hs1FkONLA.jpeg" /></figure><p>This is the first of a series of challenges reproducing Dribbble concepts with Flutter. This time we will be working with <strong>Wg</strong> by <a href="https://dribbble.com/Sarah-D"><em>Sarah-D</em></a><em>.</em></p><h3>First steps</h3><p>Prepare the main.dartfile removing everything, leaving only the MyApp class. You can also remove the debug banner and put HomePage widget as your home.</p><pre><strong>import </strong>&#39;package:flutter/material.dart&#39;;<br><strong>import </strong>&#39;package:wg_by_sarah_d/home_page.dart&#39;;<br><br><strong>void </strong>main() =&gt; runApp(MyApp());</pre><pre><strong>class </strong>MyApp <strong>extends </strong>StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      debugShowCheckedModeBanner: <strong>false</strong>, // Remove the debug banner<br>      theme: ThemeData(<br>        primarySwatch: Colors.<em>blue</em>,<br>      ),<br>      home: HomePage(),<br>    );<br>  }<br>}</pre><p>Then on the home_page.dart file you’ll be creating a StatefulWidget. From the initState() method call SystemChrome.setSystemUIOverlayStyle() for making the status bar transparent.</p><pre>@override<br><strong>void </strong>initState() {  SystemChrome.<em>setSystemUIOverlayStyle</em>(SystemUiOverlayStyle(statusBarColor: Colors.<em>transparent</em>));<br>  <strong>super</strong>.initState();<br>}</pre><p>Finally return a CupertinoPageScaffold on the build method, setting it’s backgroundColor to #2B292A.</p><pre>@override<br>Widget build(BuildContext context) {<br>  <strong>return </strong>CupertinoPageScaffold(<br>    backgroundColor: Color(0xFF2B292A),<br>  );<br>}</pre><p>Now we have a nice black background to start composing our app.</p><h3>Laying out the app</h3><p>Now we’ll start laying out the design on our Flutter app.</p><h4>1. Navigation Bar</h4><p>The child of our scaffold will contain a Stack. The first child will be a CupertinoNavigationBar with the same background color as the scaffold and the menu icon on the left. Wrap it inside a Positioned widget to place it at the top of the screen.</p><p>You may note that the menu icon is not available in CupertinoIcons. Actually, the font file includes it but it’s not being exposed. Therefore we resorted to the Cupertino icons map (you can find it <a href="https://raw.githubusercontent.com/flutter/cupertino_icons/master/map.png">here</a>). Now you can call that icon passing the corresponding hex code to the IconData class.</p><pre>child: Stack(<br>  children: &lt;Widget&gt;[<br>    Positioned(<br>      top: 0.0,<br>      left: 0.0,<br>      right: 0.0,<br>      child: CupertinoNavigationBar(<br>        backgroundColor: Color(0xFF2B292A),<br>        border: Border.all(<br>          style: BorderStyle.none,<br>        ),<br>        actionsForegroundColor: Colors.<em>white</em>,<br>        leading: Icon(IconData(0xF394, fontFamily: CupertinoIcons.<em>iconFont</em>, fontPackage: CupertinoIcons.<em>iconFontPackage</em>)),<br>      ),<br>    ),<br>  ],<br>),</pre><h4>2. Welcome text</h4><p>Next add a Container to the Stack after the navigation bar. Wrap it inside a Positioned widget and give it a distance of 85 dp from the top (that will let room for the navigation bar).</p><p>This Container will have full width, but for the height let’s give it the height of the screen, minus the height of the screen divided by 1.8 (this will be the size of the slides below), minus 120 dp (the height of the bottom red section).</p><p>Inside the Container we have a Column whose first child is the <strong>welcome text</strong>.</p><pre>child: Stack(<br>  children: &lt;Widget&gt;[<br>    Positioned(<br>      top: 90.0,<br>      left: 0.0,<br>      right: 0.0,<br>      child: Container(<br>        width: double.<em>infinity</em>,<br>        height: MediaQuery.<em>of</em>(context).size.height - (MediaQuery.<em>of</em>(context).size.height / 1.8) - 120.0,<br>        child: Padding(<br>          padding: <strong>const </strong>EdgeInsets.symmetric(horizontal: 20.0),<br>          child: Column(<br>            crossAxisAlignment: CrossAxisAlignment.start,<br>            mainAxisSize: MainAxisSize.max,<br>            children: &lt;Widget&gt;[<br>              RichText(<br>                textAlign: TextAlign.start,<br>                text: TextSpan(<br>                  children: [<br>                    TextSpan(<br>                      text: &#39;Welcome! &#39;,<br>                      style: TextStyle(<br>                        fontWeight: FontWeight.<em>w500</em>,<br>                        fontSize: 26.0,<br>                      ),<br>                    ),<br>                    TextSpan(<br>                      text: &#39;Ryan&#39;,<br>                      style: TextStyle(<br>                        fontSize: 20.0,<br>                      ),<br>                    ),<br>                  ]<br>                ),<br>              ),<br>            ],<br>          ),<br>        ),<br>      ),<br>    ),<br>  ],<br>),</pre><p>As you can see on the code, we’re using a RichText widget to be able to use different styles (there are other approaches you can follow too to achieve the same).</p><h4>3. Buttons</h4><p>We will be placing this four buttons in a Row widget. For now we’ll be using the Placeholder widget to quickly mockup this section.</p><p>We’ve created a new StatelessWidget and called it SquareButton. It’s just a Column with a Placeholder for the button and another for the text, with a little space between them.</p><pre><strong>class </strong>SquareButton <strong>extends </strong>StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>Column(<br>      mainAxisSize: MainAxisSize.min,<br>      children: &lt;Widget&gt;[<br>        Placeholder(<br>          color: Colors.<em>red</em>,<br>          fallbackWidth: 60.0,<br>          fallbackHeight: 60.0,<br>        ),<br>        SizedBox(<br>          height: 8.0,<br>        ),<br>        Placeholder(<br>          color: Colors.<em>white</em>,<br>          fallbackWidth: 60.0,<br>          fallbackHeight: 20.0,<br>        ),<br>      ],<br>    );<br>  }<br>}</pre><p>Now we can proceed by adding a Row below the RichText, with four SquareButton inside. We want them to occupy the space proportionally and also to be align to the left and right to make it true to the design. The solution is very simple, just using MainAxisAlignment.spaceBetween.</p><pre>... // RichText here in the same Column<br>Row(<br>  mainAxisSize: MainAxisSize.max,<br>  mainAxisAlignment: MainAxisAlignment.spaceBetween,<br>  children: &lt;Widget&gt;[<br>    SquareButton(),<br>    SquareButton(),<br>    SquareButton(),<br>    SquareButton(),<br>  ],<br>),</pre><h4>4. Service Request</h4><p>This is just a simple Row. The little dot at the start is a Container with a BoxDecoration. Next to it goes a Text and finally an Icon (ellipsis).</p><pre>Padding(<br>  padding: <strong>const </strong>EdgeInsets.only(bottom: 16.0),<br>  child: Row(<br>    crossAxisAlignment: CrossAxisAlignment.center,<br>    mainAxisSize: MainAxisSize.max,<br>    children: &lt;Widget&gt;[<br>      Container(<br>        width: 7.0,<br>        height: 7.0,<br>        decoration: BoxDecoration(<br>          color: Color(0xFFB42827),<br>          borderRadius: BorderRadius.circular(5.0),<br>        ),<br>      ),<br>      SizedBox(<br>        width: 8.0,<br>      ),<br>      Text(<br>        &#39;Service Request&#39;,<br>        style: Theme.<em>of</em>(context).textTheme.subtitle.copyWith(color: Colors.<em>white</em>),<br>      ),<br>      Expanded(child: SizedBox()), // Make a separation between widgets<br>      Icon(<br>        CupertinoIcons.<em>ellipsis</em>,<br>        color: Colors.<em>white</em>,<br>      ),<br>    ],<br>  ),<br>),</pre><p>Finally, let’s change the alignment of the Column for better use of the space.</p><pre>child: Column(<br>  ... // Other properties<br>  mainAxisAlignment: MainAxisAlignment.spaceAround,<br>  ... // Children widgets<br>),</pre><h4>5. Middle and bottom sections containers</h4><p>Next, we should add some containers for the other two sections. Like this:</p><pre>Stack(<br>  children: [<br>    ... // Navigation bar<br>    ... // Welcome text and buttons<br>    Positioned(<br>      bottom: 120.0,<br>      left: 0.0,<br>      right: 0.0,<br>      child: Container(<br>        height: MediaQuery.<em>of</em>(context).size.height / 1.8 - 90.0, // Substracting 90dp to compensate the height of status and navigation bars<br>      ),<br>    ),<br>    Positioned(<br>      bottom: 0.0,<br>      left: 0.0,<br>      right: 0.0,<br>      child: Container(<br>        height: 120.0,<br>        color: Color(0xFFB42827),<br>      ),<br>    ),<br>  ],<br>),</pre><h4>6. Bottom container</h4><p>The content of this bottom container is very simple, by using a Row for placing the items.</p><p>Let’s make the left icon by decorating a Container and placing an Icon centered inside.</p><pre>Container(<br>  width: 45.0,<br>  height: 45.0,<br>  decoration: BoxDecoration(<br>    borderRadius: BorderRadius.circular(25.0),<br>    color: Colors.<em>white</em>.withOpacity(0.1),<br>  ),<br>  child: Center(<br>    child: Icon(<br>      IconData(0xF391, fontFamily: CupertinoIcons.<em>iconFont</em>, fontPackage: CupertinoIcons.<em>iconFontPackage</em>),<br>      color: Colors.<em>white</em>,<br>    ),<br>  ),<br>),</pre><p>The following texts column needs no explanation:</p><pre>Column(<br>  crossAxisAlignment: CrossAxisAlignment.start,<br>  mainAxisSize: MainAxisSize.min,<br>  children: &lt;Widget&gt;[<br>    Text(<br>      &#39;260&#39;,<br>      style: Theme.<em>of</em>(context).textTheme.headline.copyWith(fontWeight: FontWeight.<em>w500</em>, color: Colors.<em>white</em>),<br>    ),<br>    Text(<br>      &#39;My application&#39;,<br>      style: Theme.<em>of</em>(context).textTheme.caption.copyWith(color: Colors.<em>white</em>.withOpacity(0.5)),<br>    ),<br>  ],<br>),</pre><p>Finally the button on the right. I’m placing an Expanded widget to push the button to the right. We’ve also removed some padding from the CupertinoButton to match the design.</p><pre>Expanded(child: SizedBox()),<br>CupertinoButton(<br>  color: Colors.<em>white</em>,<br>  borderRadius: BorderRadius.circular(30.0),<br>  padding: <strong>const </strong>EdgeInsets.symmetric(horizontal: 32.0),<br>  child: Text(<br>    &#39;SUBMISSION&#39;,<br>    style: TextStyle(<br>      color: Color(0xFFB42827),<br>      fontWeight: FontWeight.<em>w500</em>,<br>    ),<br>  ),<br>  onPressed: () {},<br>),</pre><p><strong><em>Please note that the Dribbble design is showing another fonts and icons, which we don’t have</em></strong></p><p>By now we have this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LWDruUQ36EoF_iTLu3y-rA.png" /></figure><h3>Creating the SquareButton widget</h3><p>We’ll be using the <a href="https://pub.dev/packages/font_awesome_flutter#-installing-tab-">font_awesome_flutter</a> package later, so you may want to add it now to your pubspec.yaml.</p><p>First of all, we’ll be adding two parameters to this StatelessWidget: the label String and the Icon.</p><pre><strong>final </strong>String label;<br><strong>final </strong>Icon icon;<br><br>SquareButton({<br>  @required <strong>this</strong>.label,<br>  @required <strong>this</strong>.icon,<br>})  : <strong>assert</strong>(label != <strong>null</strong>),<br>      <strong>assert</strong>(icon != <strong>null</strong>);</pre><p>Then replace the first Placeholder with a SizedBox that will expand the CupertinoButton that it wraps. Remove the padding from the buttton. Finally put the Icon received, resizing it a bit.</p><pre>SizedBox(<br>  width: 60.0,<br>  height: 60.0,<br>  child: CupertinoButton(<br>    padding: EdgeInsets.<em>zero</em>,<br>    borderRadius: BorderRadius.circular(20.0),<br>    onPressed: () {},<br>    color: Color(0xFFB42827),<br>    child: Icon(icon.icon, size: 26.0,),<br>  ),<br>),</pre><p>The label below is wrapped in a Center inside a Container with the previous dimensions of the Placeholder.</p><pre>Container(<br>  width: 60.0,<br>  height: 20.0,<br>  child: Center(<br>    child: Text(<br>      label,<br>      style: Theme.<em>of</em>(context).textTheme.caption.copyWith(color: Colors.<em>white</em>),<br>    ),<br>  ),<br>),</pre><p>You can implement them like this:</p><pre>Row(<br>  mainAxisSize: MainAxisSize.max,<br>  mainAxisAlignment: MainAxisAlignment.spaceBetween,<br>  children: &lt;Widget&gt;[<br>    SquareButton(<br>      icon: Icon(FontAwesomeIcons.<em>search</em>),<br>      label: &#39;Lookup&#39;,<br>    ),<br>    SquareButton(<br>      icon: Icon(FontAwesomeIcons.<em>userAlt</em>),<br>      label: &#39;Customer&#39;,<br>    ),<br>    SquareButton(<br>      icon: Icon(FontAwesomeIcons.<em>headset</em>),<br>      label: &#39;Contacts&#39;,<br>    ),<br>    SquareButton(<br>      icon: Icon(FontAwesomeIcons.<em>solidComments</em>),<br>      label: &#39;Message&#39;,<br>    ),<br>  ],<br>),</pre><p>Now it begins to take shape! 😃</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9xpVUpWwX7iAVQ8nM9jHgQ.png" /></figure><h3>The PageView</h3><p>Start by creating a PageViewCardListTile widget that will be the content of the cards on the PageView.</p><p>This widget receives a title and a content values. Add a biggerContent bool with a default value of false, that will help to handle the <em>David </em>text<em> </em>in the design.</p><pre><strong>class </strong>PageViewCardListTile <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>String title;<br>  <strong>final </strong>String content;<br>  <strong>final </strong>bool biggerContent;<br><br>  PageViewCardListTile({<br>    @required <strong>this</strong>.title,<br>    @required <strong>this</strong>.content,<br>    <strong>this</strong>.biggerContent = <strong>false</strong>,<br>  })  : <strong>assert</strong>(title != <strong>null</strong>),<br>        <strong>assert</strong>(content != <strong>null</strong>);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>Column(<br>      mainAxisSize: MainAxisSize.min,<br>      crossAxisAlignment: CrossAxisAlignment.start,<br>      children: [<br>        Text(<br>          title,<br>          style: Theme.<em>of</em>(context).textTheme.caption,<br>        ),<br>        SizedBox(<br>          height: 4.0,<br>        ),<br>        Text(<br>          content,<br>          style: biggerContent ? Theme.<em>of</em>(context).textTheme.title : Theme.<em>of</em>(context).textTheme.subtitle,<br>        ),<br>      ],<br>    );<br>  }<br>}</pre><p>Next, create a PageViewCard widget that will contain these tiles made before.</p><pre><strong>class </strong>PageViewCard <strong>extends </strong>StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>Padding(<br>      padding: <strong>const </strong>EdgeInsets.symmetric(horizontal: 7.0),<br>      child: Card(<br>        shape: RoundedRectangleBorder(<br>          borderRadius: BorderRadius.circular(15.0),<br>        ),<br>        margin: EdgeInsets.<em>zero</em>,<br>        child: Padding(<br>          padding: <strong>const </strong>EdgeInsets.all(16.0),<br>          child: Column(<br>            crossAxisAlignment: CrossAxisAlignment.start,<br>            mainAxisAlignment: MainAxisAlignment.spaceBetween,<br>            children: &lt;Widget&gt;[<br>              PageViewCardListTile(<br>                title: &#39;Order clerk&#39;,<br>                content: &#39;David&#39;,<br>                biggerContent: <strong>true</strong>,<br>              ),<br>              PageViewCardListTile(<br>                title: &#39;State&#39;,<br>                content: &#39;CSC response&#39;,<br>              ),<br>              PageViewCardListTile(<br>                title: &#39;Order time&#39;,<br>                content: &#39;2019-03-21 04:44&#39;,<br>              ),<br>              PageViewCardListTile(<br>                title: &#39;Condition of judgement&#39;,<br>                content: &#39;CSC Response condition. Lorem ipsum dolor sit amet, consecteture.&#39;,<br>              ),<br>              SizedBox(<br>                child: CupertinoButton(<br>                  padding: <strong>const </strong>EdgeInsets.symmetric(horizontal: 16.0),<br>                  child: Row(<br>                    mainAxisSize: MainAxisSize.max,<br>                    children: &lt;Widget&gt;[<br>                      Text(<br>                        &#39;CSC check&#39;,<br>                        style: TextStyle(<br>                          color: Color(0xFFB42827),<br>                        ),<br>                      ),<br>                      Expanded(child: SizedBox()),<br>                      RotatedBox(<br>                        quarterTurns: 3,<br>                        child: Icon(<br>                          CupertinoIcons.<em>down_arrow</em>,<br>                          color: Color(0xFFB42827),<br>                        ),<br>                      ),<br>                    ],<br>                  ),<br>                  color: Colors.<em>redAccent</em>.withOpacity(0.3),<br>                  onPressed: () {},<br>                ),<br>              )<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>The code above is pretty straightforward. The only thing to mention that it might be new, is the use of a RotatedBox to convert a down arrow icon, into a right arrow.</p><p>Now we need the PageView, wich we will be adding as a child of the Container we defined previously for this purpose.</p><p>So instantiate a PageController setting the viewportFraction to 0.92. This will let you see the borders of the widgets at left and right.</p><pre>PageController _pageController = PageController(<br>  viewportFraction: 0.92,<br>  initialPage: 1,<br>);</pre><p>Then define this PageView and populate it with some PageViewCard widgets. We’re using a Stack because we want to place those <em>position tracking lines</em> above.</p><pre>child: Stack(<br>  children: &lt;Widget&gt;[<br>    Padding(<br>      padding: <strong>const </strong>EdgeInsets.only(bottom: 40.0),<br>      child: PageView(<br>        controller: _pageController,<br>        children: &lt;Widget&gt;[<br>          PageViewCard(),<br>          PageViewCard(),<br>          PageViewCard(),<br>        ],<br>      ),<br>    ),<br>  ],<br>),</pre><p><em>Our interpretation of this widget’s behavior might not be the one the designer thought about. But it should be very close.</em></p><p>Here is this widget’s code:</p><pre><strong>class </strong>TrackingLines <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>int length;<br>  <strong>final </strong>int currentIndex;<br><br>  TrackingLines({<br>    @required <strong>this</strong>.length,<br>    @required <strong>this</strong>.currentIndex,<br>  })  : <strong>assert</strong>(length != <strong>null </strong>&amp;&amp; length &gt; 0),<br>        <strong>assert</strong>(currentIndex != <strong>null </strong>&amp;&amp; currentIndex &lt; length);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>Row(<br>      mainAxisSize: MainAxisSize.min,<br>      children: List.generate(length, (index) {<br>        <strong>return </strong>Padding(<br>          padding: <strong>const </strong>EdgeInsets.all(3.0),<br>          child: Container(<br>            width: currentIndex == index ? 15.0 : 10.0,<br>            height: 3.0,<br>            color: currentIndex == index ? Color(0xFFB42827) : Colors.<em>grey</em>,<br>          ),<br>        );<br>      }),<br>    );<br>  }<br>}</pre><p>It receives a length and the currentIndex and updates when the currentIndex matches the line index.</p><p>For it to be updated, add a listener to the PageController on the initState() method.</p><pre>_pageController.addListener(() {<br>  setState(() =&gt; _currentIndex = _pageController.page.round());<br>});</pre><p>And place the TrackingLines widget inside the same Stack with the PageView.</p><pre>... // PageView here<br>Align(<br>  alignment: Alignment.<em>bottomCenter</em>,<br>  child: Padding(<br>    padding: <strong>const </strong>EdgeInsets.only(bottom: 16.0),<br>    child: TrackingLines(<br>      length: 5,<br>      currentIndex: _currentIndex,<br>    ),<br>  ),<br>),</pre><p>So let’s see how it looks for now!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3htcvm1iXTSTQUwqOX4Vw.png" /></figure><h3>The Drawer</h3><p>We’re very close to the end! But now, we found a little problem. If you look at the CupertinoPageScaffold it doesn’t have a drawer property (like the Material Scaffold widget).</p><p>So, how can we implement this drawer? One option could be to combine the material Scaffold and Drawer widgets, with the other Cupertino widgets. And that wouldn’t be wrong. But we want to show you another way.</p><h4>Creating the drawer layout</h4><p>First of all, let’s create this layout. And we’ll be placing it right in front of what we have now. That means, at the end of our main Stack.</p><p>So, add a Container, give it a full screen height and two thirds of the screen width. And place it at the end of the Stack. Give a white color. Use Positioned to make it occupy the whole height of the screen.</p><pre>Positioned(<br>  top: 0.0,<br>  bottom: 0.0,<br>  left: 0.0,<br>  child: Container(<br>    width: (MediaQuery.<em>of</em>(context).size.width / 3) * 2,<br>    height: double.<em>infinity</em>,<br>    color: Colors.<em>white</em>,<br>  ),<br>),</pre><p>Now we will divide it using the same proportions we’ve been using for the bottom container and the PageView. If you remember we gave the bottom container 120dp on height, and the height of the screen / 1.8 minus 90dp (’cause of the navigation bar) to the PageView. Therefore, we’ll make the red section of the drawer with a height of the screen, minus height of the screen / 1.8, minus 90dp, minus 120dp. And it will match perfectly with the position of the cards on the PageView.</p><p>Of course, we’ll use a Stack again.</p><pre>child: Stack(<br>  children: &lt;Widget&gt;[<br>    Container(<br>      width: double.<em>infinity</em>,<br>      height: MediaQuery.<em>of</em>(context).size.height - (MediaQuery.<em>of</em>(context).size.height / 1.8 - 90.0) - 120.0,<br>      color: Color(0xFFB42827),<br>    ),<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RVYXUPHgIgyTfw6ANC1tXg.png" /></figure><h4>Animating the drawer</h4><p>Before continuing with the content inside the drawer, we’ll implement the animated open/close behavior.</p><p>Start by replacing the Positioned widget with an AnimatedPositioned and give a Duration of 300 ms. Declare a variable _isDrawerOpen of type bool and initialize it with false. Then replace the left property with a ternary operator to change the position based on that variable.</p><pre>AnimatedPositioned(<br>  duration: Duration(milliseconds: 300),<br>  top: 0.0,<br>  bottom: 0.0,<br>  left: _isDrawerOpen ? 0.0 : -(MediaQuery.<em>of</em>(context).size.width / 3) * 2,<br>  child: Container(<br>    ...<br>  ),<br>),</pre><p>This will hide our drawer. Now we only need to change the _isDrawerOpen value when we tap on the menu button.</p><p>On the navigation bar, wrap the Icon with a GestureDetector to be able to tap on it. Then use an anonymous function to change the state of the drawer.</p><pre>leading: GestureDetector(<br>  onTap: () =&gt; setState(() =&gt; _isDrawerOpen = <strong>true</strong>),<br>  child: Icon(<br>    IconData(0xF394, fontFamily: CupertinoIcons.<em>iconFont</em>, fontPackage: CupertinoIcons.<em>iconFontPackage</em>),<br>  ),<br>),</pre><p>Inside the red section of the drawer, add a clear icon to close the drawer.</p><pre>Container(<br>  ... // Width and height<br>  color: Color(0xFFB42827),<br>  child: Stack(<br>    children: &lt;Widget&gt;[<br>      Positioned(<br>        top: 50.0,<br>        left: 10.0,<br>        child: GestureDetector(<br>          onTap: () =&gt; setState(() =&gt; _isDrawerOpen = <strong>false</strong>),<br>          child: Icon(<br>            CupertinoIcons.<em>clear</em>,<br>            color: Colors.<em>white</em>,<br>            size: 40.0,<br>          ),<br>        ),<br>      ),<br>    ],<br>  ),<br>),</pre><p>We have our drawer working! But the animation is too linear. Let’s use a curve.</p><pre>AnimatedPositioned(<br>  duration: Duration(milliseconds: 300),<br>  curve: Curves.<em>easeIn</em>,<br>  ...<br>),</pre><p>Much better! 😄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*ZvvETGkdHatrUVNAbWhV-g.gif" /></figure><h4>Generating the shadow</h4><p>Our drawer is flat. So we’re going to fix that.</p><p>Add a BoxDecoration to the white Container of our drawer, that will hold the BoxShadow for the drawer.</p><pre>... // AnimatedContainer<br>child: Container(<br>  width: (MediaQuery.<em>of</em>(context).size.width / 3) * 2,<br>  height: double.<em>infinity</em>,<br>  decoration: BoxDecoration(<br>    color: Colors.<em>white</em>,<br>    boxShadow: [<br>      BoxShadow(<br>        color: Colors.<em>black</em>.withOpacity(0.3),<br>        blurRadius: 5.0,<br>      ),<br>    ],<br>  ),<br>  ...<br>),</pre><p>Now we’re having a nice shadow that makes the drawer “float” above the main content.</p><h4>The menu items list</h4><p>Create a new widget called MenuItem. It will be used on the menu for showing the navigation options. It’s very simple, just an icon and a text. Declare the parameters for this widget, and the place the content in a Row.</p><pre><strong>class </strong>MenuItem <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>Icon icon;<br>  <strong>final </strong>String label;<br><br>  MenuItem({<br>    @required <strong>this</strong>.icon,<br>    @required <strong>this</strong>.label,<br>  })  : <strong>assert</strong>(icon != <strong>null</strong>),<br>        <strong>assert</strong>(label != <strong>null</strong>);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>Padding(<br>      padding: <strong>const </strong>EdgeInsets.only(bottom: 42.0),<br>      child: Row(<br>        crossAxisAlignment: CrossAxisAlignment.center,<br>        children: &lt;Widget&gt;[<br>          Icon(<br>            icon.icon,<br>            color: Color(0xFFB42827),<br>          ),<br>          SizedBox(<br>            width: 8.0,<br>          ),<br>          Text(<br>            label,<br>            style: TextStyle(<br>              fontWeight: FontWeight.<em>w500</em>,<br>            ),<br>          ),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>You have to add another Container below the red one. There you will be placing this menu options.</p><pre>Align(<br>  alignment: Alignment.<em>bottomCenter</em>,<br>  child: Container(<br>    width: double.<em>infinity</em>,<br>    height: MediaQuery.<em>of</em>(context).size.height / 1.8 + 30.0,<br>    child: Padding(<br>      padding: <strong>const </strong>EdgeInsets.only(left: 46.0, top: 46.0),<br>      child: Column(<br>        children: &lt;Widget&gt;[<br>          MenuItem(<br>            icon: Icon(FontAwesomeIcons.<em>solidBell</em>),<br>            label: &#39;Message center&#39;,<br>          ),<br>          MenuItem(<br>            icon: Icon(FontAwesomeIcons.<em>clipboardList</em>),<br>            label: &#39;Ticket research&#39;,<br>          ),<br>          MenuItem(<br>            icon: Icon(FontAwesomeIcons.<em>shieldAlt</em>),<br>            label: &#39;Suggestion&#39;,<br>          ),<br>          MenuItem(<br>            icon: Icon(Icons.<em>phone</em>),<br>            label: &#39;Contact us&#39;,<br>          ),<br>        ],<br>      ),<br>    ),<br>  ),<br>),</pre><p><strong><em>Note that we’re harcoding everything here. Obviously you won’t want to do that on a real app.</em></strong></p><h4>User information</h4><p>For the user information on the top of the drawer, create a separated StatelessWidget and call it UserInfo.</p><p>We’ll place the elements inside a Column, starting with a Card where we will showing the picture. We can get the rounded corners, by wraping the image in a ClipRRect. The FadeInImage.network will give us a nice transition when loading the image.</p><p>The next elements are just some texts, except fo the little circle icon at the right of the name.</p><pre><strong>class </strong>UserInfo <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>String picture;<br>  <strong>final </strong>String name;<br>  <strong>final </strong>String id;<br>  <strong>final </strong>String company;<br><br>  UserInfo({<br>    @required <strong>this</strong>.picture,<br>    @required <strong>this</strong>.name,<br>    @required <strong>this</strong>.id,<br>    @required <strong>this</strong>.company,<br>  }) : <strong>assert</strong>(picture != <strong>null </strong>&amp;&amp; name != <strong>null </strong>&amp;&amp; id != <strong>null </strong>&amp;&amp; company != <strong>null</strong>);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>Column(<br>      mainAxisSize: MainAxisSize.min,<br>      crossAxisAlignment: CrossAxisAlignment.start,<br>      children: &lt;Widget&gt;[<br>        Card(<br>          margin: EdgeInsets.<em>zero</em>,<br>          elevation: 2.0,<br>          shape: RoundedRectangleBorder(<br>            borderRadius: BorderRadius.circular(12.0),<br>          ),<br>          child: Container(<br>            width: 80.0,<br>            height: 80.0,<br>            child: ClipRRect(<br>              borderRadius: BorderRadius.circular(12.0),<br>              child: FadeInImage.assetNetwork(<br>                placeholder: picture,<br>                image: picture,<br>              ),<br>            ),<br>          ),<br>        ),<br>        SizedBox(<br>          height: 9.0,<br>        ),<br>        Row(<br>          children: &lt;Widget&gt;[<br>            Text(<br>              name,<br>              style: Theme.<em>of</em>(context).textTheme.headline.copyWith(color: Colors.<em>white</em>),<br>            ),<br>            SizedBox(<br>              width: 8.0,<br>            ),<br>            Container(<br>              width: 12.0,<br>              height: 12.0,<br>              decoration: BoxDecoration(<br>                color: Colors.<em>white</em>.withOpacity(0.3),<br>                shape: BoxShape.circle,<br>              ),<br>              child: Center(<br>                child: Icon(<br>                  CupertinoIcons.<em>play_arrow_solid</em>,<br>                  size: 8.0,<br>                  color: Colors.<em>white</em>,<br>                ),<br>              ),<br>            ),<br>          ],<br>        ),<br>        SizedBox(<br>          height: 6.0,<br>        ),<br>        Text(<br>          id,<br>          style: Theme.<em>of</em>(context).textTheme.caption.copyWith(color: Colors.<em>white</em>.withOpacity(0.6)),<br>        ),<br>        SizedBox(<br>          height: 6.0,<br>        ),<br>        Text(<br>          company,<br>          style: Theme.<em>of</em>(context).textTheme.caption.copyWith(color: Colors.<em>white</em>.withOpacity(0.6)),<br>        )<br>      ],<br>    );<br>  }<br>}</pre><p>The last step is to add this new widget, on the same Stack where the clear icon is, on the red section of the drawer.</p><pre>Align(<br>  alignment: Alignment.<em>bottomLeft</em>,<br>  child: Padding(<br>    padding: <strong>const </strong>EdgeInsets.only(left: 46.0, bottom: 46.0),<br>    child: UserInfo(<br>      picture: &#39;https://shopolo.hu/wp-content/uploads/2019/04/profile1-%E2%80%93-kopija.jpeg&#39;,<br>      name: &#39;Ryan&#39;,<br>      id: &#39;0023-Ryan&#39;,<br>      company: &#39;Universal Data Center&#39;,<br>    ),<br>  ),<br>),</pre><p>And that’s it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*jlZyBR1SNtggWdN5nfEzHA.gif" /></figure><p>You can find the complete project on <a href="https://github.com/GaboBrandX/dribbble_challenge_1">https://github.com/GaboBrandX/dribbble_challenge_1</a></p><h3>Conclusion</h3><p>We’re happy with the result. It’s not perfect and there’s room for refactoring. But we hope this little challenge helps some of you to know more about this awesome UI Toolkit called Flutter.</p><p>You can know more about our <a href="https://clarikagroup.com/flutter/">Flutter Development Services</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c3a2cd4d221" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TaskDescription customization with Flutter]]></title>
            <link>https://medium.com/glottery/taskdescription-customization-with-flutter-17d7a1067649?source=rss-407c8b6ee83d------2</link>
            <guid isPermaLink="false">https://medium.com/p/17d7a1067649</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Gabriel Moreyra]]></dc:creator>
            <pubDate>Thu, 27 Jun 2019 01:00:54 GMT</pubDate>
            <atom:updated>2019-07-15T20:48:10.575Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGMJ4NAdQ4jW8Q7igBrFKw.png" /></figure><p>A few days ago, I’ve found myself with this requirement: to change the TaskDescription color on a Flutter app (actually it was an StackOverflow question, but I took it very seriously 😆). After implementing this as I would do on any native Android app it turned out it didn’t worked with Flutter.</p><p>I’ve finally got it to work, so I wanted to share my little story.</p><p><strong>What does TaskDescription do?</strong></p><p>The TaskDescription is visible on the <a href="https://developer.android.com/guide/components/activities/recents">Recents Screen</a> (also called Overview Screen) and it was introduced on Android 5.0 (API 21 Lollipop). And it gives you the ability to customize the icon, the title and bar color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*vn_gHLPxglBCa2tbz4mbow.png" /><figcaption>Recent Screens on Lollipop</figcaption></figure><p>You can find more info about TaskDescription on the <a href="https://developer.android.com/reference/android/app/ActivityManager.TaskDescription">docs</a>.</p><p><strong>TaskDescription customization</strong></p><p>Customizing the TaskDescription is pretty straightforward.</p><ul><li>Check that sdk version is Lollipop or greater.</li><li>Generate a Bitmap with the icon you want to use</li><li>Call setTaskDescription passing a TaskDescription object with the values you want (title, icon and color, respectively).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96af84d498a73f8782ab1e6f9dea5c64/href">https://medium.com/media/96af84d498a73f8782ab1e6f9dea5c64/href</a></iframe><p>And there you go, you have a nice TaskDescription on your app when the user is seeing it on the Recents Screen.</p><p>But… if you copy/paste lines 13 to 16 to the MainActivity of your Flutter app, you’ll see no effect. What to do now?</p><p><strong>How to make it work with Flutter</strong></p><p>Well, after playing a bit with this problem, I came to the conclusion that Flutter is overriding the TaskDescription on some point after the onResume() lifecycle method.</p><p>In fact, if you call setTaskDescription inside onResume() you’ll see changes from the second time you minimize the app. Therefore, you can call this method after some delay (and only once) to make it work.</p><p>Here you can take a look at my solution:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a62c8ccbc8dd3db7a0ab2ec5e373a4ec/href">https://medium.com/media/a62c8ccbc8dd3db7a0ab2ec5e373a4ec/href</a></iframe><p>As you can see I’ve also separated the instantiation of the TaskDescription to be able to call a non-deprecated constructor available since Android P. And the Timer is scheduled to 1 second from the onCreate() call.</p><p>I’m providing here the same example with Java too:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9ee03c669747987c7fe7d7ad9cc3ccd/href">https://medium.com/media/d9ee03c669747987c7fe7d7ad9cc3ccd/href</a></iframe><p>You can see the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XSo2LVT8aPMsd41zMSsOKA.gif" /></figure><p><strong>Conclusion</strong></p><p>This solution is way far from being perfect. But as Flutter is still a young sdk, we’ll find problems like this one now and then.</p><p>There’s an open issue <a href="https://github.com/flutter/flutter/issues/1284">here</a> related with TaskDescription, but it was opened 3 years ago and still no news…</p><p>Anyway, I hope you find this useful.</p><p>If you liked my article, you can <a href="https://www.buymeacoffee.com/IzOUlCqWP">buy me a coffee</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17d7a1067649" width="1" height="1" alt=""><hr><p><a href="https://medium.com/glottery/taskdescription-customization-with-flutter-17d7a1067649">TaskDescription customization with Flutter</a> was originally published in <a href="https://medium.com/glottery">Glottery</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>