<?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 İsmail Can Şeker on Medium]]></title>
        <description><![CDATA[Stories by İsmail Can Şeker on Medium]]></description>
        <link>https://medium.com/@icanseker?source=rss-a65db72510ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yEonViv23s2RZEiZUP6isA.jpeg</url>
            <title>Stories by İsmail Can Şeker on Medium</title>
            <link>https://medium.com/@icanseker?source=rss-a65db72510ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:22:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@icanseker/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[JSch Client Exec Channel Example with flushing data — run command passwd]]></title>
            <link>https://icanseker.medium.com/jsch-client-exec-channel-example-with-flushing-data-run-command-passwd-dbe582d6b9bf?source=rss-a65db72510ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe582d6b9bf</guid>
            <category><![CDATA[passwd]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jsch]]></category>
            <category><![CDATA[exec]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[İsmail Can Şeker]]></dc:creator>
            <pubDate>Mon, 06 Sep 2021 09:25:43 GMT</pubDate>
            <atom:updated>2021-09-06T09:26:52.764Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*v-4W-uQl2O1i0EcflkHmNQ.png" /></figure><h3>JSch Client Exec Channel Example with flushing data — run command passwd</h3><p>JSch is a pure Java library that implemens SSH2. However, it is poorly documented and finding a good example is difficult. I’ll demonstrate how we can use JSch in a more efficient manner, I chose the “<strong>passwd</strong>” command because it prompts you for a new password when you type it into the shell terminal. Let’s begin by implementing the “<strong>host</strong>” class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d231393a46b17d9c0db192bdaab3cef5/href">https://medium.com/media/d231393a46b17d9c0db192bdaab3cef5/href</a></iframe><p>Continue by implementing auth method classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6909dc4fb7ba95c18159673be4c3357/href">https://medium.com/media/a6909dc4fb7ba95c18159673be4c3357/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d045f37006d3bdd6a22da1f5e7ff2f0/href">https://medium.com/media/3d045f37006d3bdd6a22da1f5e7ff2f0/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ecadb8b2410e8eec61e4a85c7ef81c4/href">https://medium.com/media/7ecadb8b2410e8eec61e4a85c7ef81c4/href</a></iframe><p>Carry on with the implementation of the Authentication class, which has a user name and a corresponding authentication method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fc7a407e01fae71bfcd2693d1cd8915/href">https://medium.com/media/8fc7a407e01fae71bfcd2693d1cd8915/href</a></iframe><p>Let’s implement an enumeration to keep track of different ssh channel types:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48e8904a65d61075e1ab86ae3e0a0ec7/href">https://medium.com/media/48e8904a65d61075e1ab86ae3e0a0ec7/href</a></iframe><p>Carry on with the implementation of the Client Session Operator which takes host name, authentication and preferably the connection port as parameters to init and start session as well as create appropriate ssh channel. (Only the Exec channel will be implemented)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcf1b5a0912914621712c7505fc09143/href">https://medium.com/media/bcf1b5a0912914621712c7505fc09143/href</a></iframe><p>Lets create the most important class that will allow us to operate more efficiently:<br><strong>ExecInteract</strong> is a class that takes an <strong>exec channel</strong> and a <strong>command string</strong> as parameters and runs it on that channel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba41fa9d9946e273c26e1f563b41286/href">https://medium.com/media/eba41fa9d9946e273c26e1f563b41286/href</a></iframe><pre><strong>- executeTimeout</strong> is the amount of time to run commands on channel and get a response. Extended classes have the ability to adjust this as needed.</pre><pre>- If the execute timed out and the channel is yet not closed, the <strong>channelDisconnectTimer</strong> is responsible for disconnecting the channel.</pre><pre>- flushing functions will be explained later.</pre><p>Let’s make StandardExecInteract class that takes a command and executes it on channel exec, then waits for a response.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/065c6bbaf7304c62f3f9149d269f7f95/href">https://medium.com/media/065c6bbaf7304c62f3f9149d269f7f95/href</a></iframe><p>At this stage, see an example of command running using the Standard Interact class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5590a29a8453269b8e4f88280de26f11/href">https://medium.com/media/5590a29a8453269b8e4f88280de26f11/href</a></iframe><p>This is the ide output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndoaJxMLQ5mQzhKbHQK_0Q.png" /></figure><p>When you perform the <strong>passwd</strong> command, the exec channel console <strong>prompts you for a new password</strong> and waits for interact; if no interact occurs after 2000 milliseconds, the channel is <strong>immediately closed</strong>.</p><p>Let’s make a class that runs the passwd command and <strong>flushes the new password (twice) </strong>(systematically) when the exec channel prompts for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6e8739668ed92ba00e612e3a1f7d68a/href">https://medium.com/media/a6e8739668ed92ba00e612e3a1f7d68a/href</a></iframe><p>Try it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37c719c481157a2aa5b69e266ec9a7fa/href">https://medium.com/media/37c719c481157a2aa5b69e266ec9a7fa/href</a></iframe><p>The ide result is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*fjCsZ-d95K7UAD5YqgQb9A.png" /><figcaption>Keep in mind that the Exec channel returns passwd output as an error, but the exit status is 0.</figcaption></figure><p>Best regards…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe582d6b9bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — paint dotted line (both horizontal and vertical axis)]]></title>
            <link>https://icanseker.medium.com/flutter-paint-dotted-line-both-horizontal-and-vertical-axis-7f9dfed8b4da?source=rss-a65db72510ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f9dfed8b4da</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[İsmail Can Şeker]]></dc:creator>
            <pubDate>Sun, 02 May 2021 19:19:26 GMT</pubDate>
            <atom:updated>2021-05-03T22:39:28.296Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*AACzhL1OGN6_A5hi9UkakQ.png" /></figure><h3>Flutter — paint dotted line (both horizontal and vertical axis)</h3><p>Lets create a widget that rendering horizontal or vertical dotted line having these features:</p><ul><li>Paint style will be customizable. User will be able to define its own paint style.</li><li>Dot size and gap size between dots will be customizable.</li><li>And most importantly, the line will be symmetric with respect to the midpoint of line for any size.</li></ul><p>If you interested in dashed line (symmetric formulated), please read this article <a href="https://icanseker.medium.com/flutter-paint-dashed-line-both-horizontal-and-vertical-axis-340eac726ede"><strong>Flutter — paint dashed line (both horizontal and vertical axis)</strong></a></p><p>If you interested in zigzag line, please read this article <a href="https://icanseker.medium.com/flutter-paint-zigzag-line-both-horizontal-and-vertical-axis-723c33400477"><strong>Flutter — paint zigzagline (both horizontal and vertical axis)</strong></a></p><p>Let’s start designing an abstract line class, we will extend line pattern classes from this class:</p><pre><strong>abstract class </strong>Line {}</pre><p>Now, let’s extend two line pattern class: solid and dotted. Our focus will be on dotted line, but in some cases we will use solid line painter which with more performance (always escape from unnecessary calculation).</p><pre><strong>class </strong>SolidLine <strong>extends </strong>Line {}</pre><pre><strong>class </strong>DottedLine <strong>extends </strong>Line {<br>  <strong>final </strong>double <strong>gapSize</strong>;<br><br>  DottedLine({<strong>this</strong>.<strong>gapSize</strong>});<br>}</pre><p>Let’s design our line painter class — Line painter will take line definition (which is solid or dotted) and the paint style as parameter to produce the requested line.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a81133fbd28ebc2c0a63658d07a58cc/href">https://medium.com/media/8a81133fbd28ebc2c0a63658d07a58cc/href</a></iframe><p>Let’s design our AdvancedLine widget. Please notice that, our line painter class rendering only horizontal lines, if user requests vertical line, AdvancedLine widget will rotate the rendered horizontal line 90 degrees.</p><pre><strong>class </strong>AdvancedLine <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>Axis <strong>direction</strong>;<br>  <strong>final </strong>Line <strong>line</strong>;<br>  <strong>final </strong>Paint <strong>paintDef</strong>;<br><br>  <strong>const </strong>AdvancedLine({<br>    Key key,<br>    @required <strong>this</strong>.<strong>direction</strong>,<br>    @required <strong>this</strong>.<strong>line</strong>,<br>    <strong>this</strong>.<strong>paintDef</strong>,<br>  }) : <strong>super</strong>(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <em>// line painter, always rendering horizontal line<br>    // if requested axis is vertical<br>    // send horizontal line with 90 degree rotated<br><br>    </em>Paint paint = <strong>this</strong>.<strong>paintDef </strong>?? Paint();<br><br>    Row lineWrapper = Row(<br>      crossAxisAlignment: CrossAxisAlignment.<strong>start</strong>,<br>      children: [<br>        Expanded(<br>          child: Container(<br>            height: paint.<strong>strokeWidth</strong>,<br>            child: CustomPaint(<br>              painter: LinePainter(line: <strong>line</strong>, paintDef: paint),<br>            ),<br>          ),<br>        ),<br>      ],<br>    );<br><br>    <strong>if </strong>(<strong>direction </strong>== Axis.<strong>horizontal</strong>)<br>      <strong>return </strong>lineWrapper;<br>    <strong>else<br>      return new </strong>RotatedBox(<br>        quarterTurns: 1,<br>        child: lineWrapper,<br>      );<br>  }<br>}</pre><p>Let’s build some dotted line outputs:</p><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 240,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DottedLine(),<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 9.0,<br>          color: Colors.<em>yellow</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DottedLine(),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 3.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 9.0,<br>          color: Colors.<em>yellow</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DottedLine(),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>round</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 12,<br>          height: 160,<br>          color: Colors.<em>yellow</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>vertical</strong>,<br>            line: DottedLine(),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>square</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DottedLine(gapSize: 5.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>round<br>              </strong>..<strong>color </strong>= Colors.<em>black54</em>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DottedLine(gapSize: 5.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 8.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>round<br>              </strong>..<strong>color </strong>= Colors.<em>black54</em>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DottedLine(gapSize: 3.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 20.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>round<br>              </strong>..<strong>color </strong>= Colors.<em>black54</em>,<br>          ),<br>        ),<br>      ],<br>    ),<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaR6oDSLL3nP5wEhp2vD8g.png" /></figure><p>We can provide symmetry with a very simple calculation method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*AACzhL1OGN6_A5hi9UkakQ.png" /></figure><p>Best regards.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f9dfed8b4da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — paint zigzag line (both horizontal and vertical axis)]]></title>
            <link>https://icanseker.medium.com/flutter-paint-zigzag-line-both-horizontal-and-vertical-axis-723c33400477?source=rss-a65db72510ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/723c33400477</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[İsmail Can Şeker]]></dc:creator>
            <pubDate>Wed, 28 Apr 2021 23:37:34 GMT</pubDate>
            <atom:updated>2021-05-02T20:38:31.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4H6-wA6p-DjA8Zj_OFEttg.png" /></figure><h3>Flutter — paint zigzag line (both horizontal and vertical axis)</h3><p>Lets create a widget that rendering horizontal or vertical zigzag line having these features:</p><ul><li>Paint style will be customizable. User will be able to define its own paint style.</li><li>Zigzag depth (height) and angle will be customizable</li></ul><p>If you interested in dashed line (symmetric formulated), please read this article <a href="https://icanseker.medium.com/flutter-paint-dashed-line-both-horizontal-and-vertical-axis-340eac726ede"><strong>Flutter — paint dashed line (both horizontal and vertical axis)</strong></a></p><p>Let’s start designing an abstract line class, we will extend line pattern classes from this class:</p><pre><strong>abstract class </strong>Line {}</pre><p>Now, let’s extend two line pattern class: solid and zigzag. Our focus will be on zigzag line, but in some cases we will use solid line painter which with more performance (always escape from unnecessary calculation).</p><pre><strong>class </strong>SolidLine <strong>extends </strong>Line {}</pre><pre><strong>class </strong>ZigzagLine <strong>extends </strong>Line {<br>  <strong>final </strong>double <strong>depth</strong>;<br>  <strong>final </strong>double <strong>angle</strong>;<br><br>  ZigzagLine({<strong>this</strong>.<strong>depth</strong>, <strong>this</strong>.<strong>angle</strong>});<br>}</pre><p>Let’s design our line painter class — Line painter will take line definition (which is solid or zigzag) and the paint style as parameter to produce the requested line.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e6c53ef5bb6f1727c62bcc42318c7c9/href">https://medium.com/media/9e6c53ef5bb6f1727c62bcc42318c7c9/href</a></iframe><p>Let’s design our AdvancedLine widget. Please notice that, our line painter class rendering only horizontal lines, if user requests vertical line, AdvancedLine widget will rotate the rendered horizontal line 90 degrees.</p><pre><strong>class </strong>AdvancedLine <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>Axis <strong>direction</strong>;<br>  <strong>final </strong>Line <strong>line</strong>;<br>  <strong>final </strong>Paint <strong>paintDef</strong>;<br><br>  <strong>const </strong>AdvancedLine({<br>    Key key,<br>    @required <strong>this</strong>.<strong>direction</strong>,<br>    @required <strong>this</strong>.<strong>line</strong>,<br>    <strong>this</strong>.<strong>paintDef</strong>,<br>  }) : <strong>super</strong>(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <em>// line painter, always rendering horizontal line<br>    // if requested axis is vertical<br>    // send horizontal line with 90 degree rotated<br><br>    </em>Paint paint = <strong>this</strong>.<strong>paintDef </strong>?? Paint();<br>    double spaceDepth = paint.<strong>strokeWidth</strong>;<br><br>    <strong>if </strong>(<strong>line is </strong>ZigzagLine) spaceDepth = (<strong>line as </strong>ZigzagLine).<strong>depth </strong>?? 8.0;<br><br>    Row lineWrapper = Row(<br>      crossAxisAlignment: CrossAxisAlignment.<strong>start</strong>,<br>      children: [<br>        Expanded(<br>          child: Container(<br>            height: spaceDepth,<br>            child: CustomPaint(<br>              painter: LinePainter(line: <strong>line</strong>, paintDef: paint),<br>            ),<br>          ),<br>        ),<br>      ],<br>    );<br><br>    <strong>if </strong>(<strong>direction </strong>== Axis.<strong>horizontal</strong>)<br>      <strong>return </strong>lineWrapper;<br>    <strong>else<br>      return new </strong>RotatedBox(<br>        quarterTurns: 1,<br>        child: lineWrapper,<br>      );<br>  }<br>}</pre><p>Let’s build some zigzag line outputs:</p><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: ZigzagLine(angle: 60, depth: 8.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 1.0<br>              ..<strong>style </strong>= PaintingStyle.<strong>stroke</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>              direction: Axis.<strong>horizontal</strong>,<br>              line: ZigzagLine(angle: 90, depth: 20.0),<br>              paintDef: Paint()..<strong>strokeWidth </strong>= 1.0),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 16.0,<br>          color: Colors.<em>deepOrangeAccent</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: ZigzagLine(angle: 90, depth: 16.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 2.0<br>              ..<strong>style </strong>= PaintingStyle.<strong>stroke</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 48.0,<br>          color: Colors.<em>lightBlueAccent</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: ZigzagLine(angle: 45, depth: 16.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 2.0<br>              ..<strong>style </strong>= PaintingStyle.<strong>stroke</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 320,<br>          height: 60.0,<br>          alignment: Alignment.<em>center</em>,<br>          color: Colors.<em>lightBlueAccent</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: ZigzagLine(angle: 45, depth: 16.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>style </strong>= PaintingStyle.<strong>stroke</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMwNyntlQvka2AC61cG1xg.png" /></figure><ul><li>The first zigzag line defined inside an Expanded Container.</li><li>The second zigzag line defined (inside Expanded) with default paint style which is ‘PaintingStyle.<strong>fill</strong>’. See the difference.</li><li>See the difference between third and fourth zigzag line, zigzag depth and thickness (stroke width) are equal but the <strong>angle is not</strong>.</li></ul><p>Let’s build a vertical zigzag line:</p><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 16.0,<br>          color: Colors.<em>deepOrangeAccent</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: ZigzagLine(angle: 90, depth: 16.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 2.0<br>              ..<strong>style </strong>= PaintingStyle.<strong>stroke</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 24,<br>          height: 240,<br>          color: Colors.<em>lightBlueAccent</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>vertical</strong>,<br>            line: ZigzagLine(angle: 45, depth: 16.0),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 2.0<br>              ..<strong>style </strong>= PaintingStyle.<strong>stroke</strong>,<br>          ),<br>        ),<br>      ],<br>    )<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcGVPVXaTLdHx4xIAPh6Ig.png" /></figure><p>If you wondering how calculating the zigzag aperture (zigzag width), please see image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4H6-wA6p-DjA8Zj_OFEttg.png" /></figure><p>Best regards…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=723c33400477" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — paint dashed line (both horizontal and vertical axis)]]></title>
            <link>https://icanseker.medium.com/flutter-paint-dashed-line-both-horizontal-and-vertical-axis-340eac726ede?source=rss-a65db72510ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/340eac726ede</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[İsmail Can Şeker]]></dc:creator>
            <pubDate>Tue, 27 Apr 2021 00:47:25 GMT</pubDate>
            <atom:updated>2021-05-02T18:29:56.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQMUXVbbVeCKvff6DOoyUA.png" /></figure><h3>Flutter — paint dashed line (both horizontal and vertical axis)</h3><p>Lets create a widget that rendering horizontal or vertical dashed line having these features:</p><ul><li>Paint style will be customizable. User will be able to define its own paint style.</li><li>Length of dash and gap will be customizable.</li><li>And most importantly, the line will be symmetric with respect to the midpoint of line (mathematically formulated) for any size.</li></ul><p>If you interested in zigzag line, please read this article <a href="https://icanseker.medium.com/flutter-paint-zigzag-line-both-horizontal-and-vertical-axis-723c33400477"><strong>Flutter — paint zigzagline (both horizontal and vertical axis)</strong></a></p><p>Let’s start designing an abstract line class, we will extend line pattern classes from this class:</p><pre><strong>abstract class </strong>Line {}</pre><p>Now, let’s extend two line pattern class: solid and dashed. Our focus will be on dashed line, but in some cases we will use solid line painter which with more performance (always escape from unnecessary calculation).</p><pre><strong>class </strong>SolidLine <strong>extends </strong>Line {}</pre><pre><strong>class </strong>DashedLine <strong>extends </strong>Line {<br>  <strong>final </strong>double <strong>dashSize</strong>;<br>  <strong>final </strong>double <strong>gapSize</strong>;<br><br>  DashedLine({<strong>this</strong>.<strong>dashSize</strong>, <strong>this</strong>.<strong>gapSize</strong>});<br>}</pre><p>Let’s design our line painter class — Line painter will take line definition (which is solid or dashed) and the paint style as parameter to produce the requested line.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c928ecac9e1b13f3c60fb05b08f223d5/href">https://medium.com/media/c928ecac9e1b13f3c60fb05b08f223d5/href</a></iframe><p>Let’s design our AdvancedLine widget. Please notice that, our line painter class rendering only horizontal lines, if user requests vertical line, AdvancedLine widget will rotate the rendered horizontal line 90 degrees.</p><pre><strong>class </strong>AdvancedLine <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>Axis <strong>direction</strong>;<br>  <strong>final </strong>Line <strong>line</strong>;<br>  <strong>final </strong>Paint <strong>paintDef</strong>;<br><br>  <strong>const </strong>AdvancedLine({<br>    Key key,<br>    @required <strong>this</strong>.<strong>direction</strong>,<br>    @required <strong>this</strong>.<strong>line</strong>,<br>    <strong>this</strong>.<strong>paintDef</strong>,<br>  }) : <strong>super</strong>(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <em>// line painter, always rendering horizontal line<br>    // if requested axis is vertical<br>    // send horizontal line with 90 degree rotated<br><br>    </em>Paint paint = <strong>this</strong>.<strong>paintDef </strong>?? Paint();<br><br>    Row lineWrapper = Row(<br>      crossAxisAlignment: CrossAxisAlignment.<strong>start</strong>,<br>      children: [<br>        Expanded(<br>          child: Container(<br>            height: paint.<strong>strokeWidth</strong>,<br>            child: CustomPaint(<br>              painter: LinePainter(line: <strong>line</strong>, paintDef: paint),<br>            ),<br>          ),<br>        ),<br>      ],<br>    );<br><br>    <strong>if </strong>(<strong>direction </strong>== Axis.<strong>horizontal</strong>)<br>      <strong>return </strong>lineWrapper;<br>    <strong>else<br>      return new </strong>RotatedBox(<br>        quarterTurns: 1,<br>        child: lineWrapper,<br>      );<br>  }<br>}</pre><p>Let’s build some dashed line outputs:</p><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 240,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(),<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Expanded(<br>          child: Container(<br>            child: AdvancedLine(<br>              direction: Axis.<strong>horizontal</strong>,<br>              line: DashedLine(),<br>              paintDef: Paint()..<strong>strokeWidth </strong>= 2.0,<br>            ),<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 200,<br>          height: 20.0,<br>          color: Colors.<em>yellow</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 12, gapSize: 6),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 5.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYgoUUXND2uUH43fuBAXdw.png" /></figure><ul><li>The first line has been defined horizontally (inside 240 width Container) without custom Paint style, with default dash size and gap size. Flutter says for <strong>stroke width</strong>, <strong>‘Defaults to 0.0, which correspond to a hairline width’</strong>.</li><li>The second line (has wrapped with ‘<strong>Expanded widget</strong>’, thus the width of the dashed line will be the width of the screen) has been defined with custom Paint stroke width. Please notice that<strong> the symmetry</strong> of line starting and ending.</li><li>The last line has been defined (inside 200 width Container) with custom dash size and gap size.</li></ul><p>Lest change the Stroke Cap as round or square. ⚡ You can visit <a href="https://api.flutter.dev/flutter/dart-ui/StrokeCap-class.html"><strong>flutter documentation page</strong></a> about Stroke Cap types.</p><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 20.0,<br>          color: Colors.<em>yellow</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 8, gapSize: 16),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>color </strong>= Colors.<em>redAccent</em>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 240,<br>          height: 20.0,<br>          color: Colors.<em>yellow</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 8, gapSize: 16),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>round</strong>,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Expanded(<br>          child: Container(<br>            alignment: Alignment.<em>center</em>,<br>            child: AdvancedLine(<br>              direction: Axis.<strong>horizontal</strong>,<br>              line: DashedLine(dashSize: 8, gapSize: 16),<br>              paintDef: Paint()<br>                ..<strong>strokeWidth </strong>= 3.0<br>                ..<strong>strokeCap </strong>= StrokeCap.<strong>square</strong>,<br>            ),<br>          ),<br>        ),<br>      ],<br>    ),<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HquDvd5-tiZj06u2AmjZeg.png" /></figure><ul><li>The first line has been defined with default <strong>Stroke Cap which is ‘butt’</strong>.</li><li>The second line is defined by the <strong>Stroke Cap ‘round’</strong>, the gap and dash sizes are equal to those of the first line. See the effect of changing the stroke cap.</li><li>The last line has been defined with Stroke Cap ‘square’ and inside Expanded Container.</li></ul><p>Let’s build a vertical dashed line:</p><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 15, gapSize: 5),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 3.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          color: Colors.<em>yellow</em>,<br>          height: 120,<br>          width: 12.0,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>vertical</strong>,<br>            line: DashedLine(dashSize: 15, gapSize: 10),<br>            paintDef: Paint()<br>              ..<strong>strokeWidth </strong>= 3.0<br>              ..<strong>strokeCap </strong>= StrokeCap.<strong>round</strong>,<br>          ),<br>        )<br>      ],<br>    )<br>  ],<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pe4xNPpITZCm7MUEiuvRHA.png" /></figure><p>If you wonder that how i calculate symmetry of the dashed line, you can continue to read the article.</p><p>Lets see how figure Perfect size and Leap size from given arguments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQMUXVbbVeCKvff6DOoyUA.png" /></figure><pre><strong>Perfect size</strong> = (dash size)*c + (gap size)*(c - 1)<br><strong>c</strong> is dash <strong>count</strong>.</pre><pre>if ( requested size + gap size ) <strong>%</strong> (dash size + gap size) = 0, so<br>the size is <strong>perfect size for requested dashed line</strong>.</pre><pre>Leap size is <strong>requested width - perfect size</strong></pre><pre><strong>if </strong>(leapSize != 0) {<br>  <strong>if </strong>(gapSize &gt; dashSize &amp;&amp; gapSize - leapSize &gt;= dashSize)<br>    position = leapSize / 2;<br>  <strong>else<br>    </strong>firstDashSize = (dashSize - gapSize + leapSize) / 2;<br>}</pre><pre>Now we decide whether to add dashes or spaces at the beginning and end of the line <strong>with leap size</strong>.</pre><pre>Suppose that requested line size is <strong>100</strong>,<br>Dash size = <strong>10</strong>, Gap size = <strong>5</strong>,</pre><pre>(100 + 5) % 15 = 0, <strong>so 100 is perfect size</strong>.</pre><pre>Lets say <strong>Leap Size</strong> is the result of Size % (dash size + gap size)</pre><pre><strong>If requested size is 105, so leap size will be 5</strong>.<br>(105 + gap size) % (dash size + gap size) =&gt; <strong>110 % 15 = 5<br></strong>See image below, <strong>the line is not symmetric</strong>.</pre><pre>Thus, we can say that <strong>if leap size is not zero</strong>, the line would <strong>not be symmetric</strong>. See image below.</pre><pre>So how we will solve the symmetry problem?</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*wVnjpyy3kRrNBHos0RZVQQ.png" /></figure><pre><strong>That is the solution:</strong></pre><pre>If <strong>gap size</strong> <strong>less than or equal to dash size</strong>, we have to calculate that leap is contain how much gap and how much dash.</pre><pre>Split (the sum of the first dash line and dash line inside leap) into <strong>two equal dash line</strong>, place one of them at the beginning and other at the end.</pre><pre>firstDashSize = (dashSize - gapSize + leapSize) / 2;</pre><pre>---</pre><pre>If <strong>gap size</strong> <strong>bigger than dash size </strong>and the difference between gap size and leap size is <strong>less than dash size</strong>, we have to split <strong>the sum of first dash and the last dash </strong>into <strong>two equal dash line</strong>, place one of them at the beginning and other at the end.</pre><pre>If requested size is <strong>285</strong>, dash size is <strong>10</strong> and gap size is <strong>25</strong>, so leap size will be <strong>(285 + 25) % 35 = 30</strong>, <strong>25 - 30 = -5</strong> which is smaller than dash size.</pre><pre>firstDashSize = (dashSize - gapSize + leapSize) / 2 = <strong>7.5</strong></pre><pre>---</pre><pre>If <strong>gap size</strong> <strong>bigger than dash size </strong>and the difference between gap size and leap size is <strong>equal or bigger than dash size</strong>, we have to start the line with a gap which <strong>leap size / 2 </strong>length. Thus, we will split the leap size to be both at the beginning and at the end of line as a gap.</pre><pre>If requested size is <strong>270</strong>, dash size is <strong>10</strong> and gap size is <strong>25</strong>, so leap size will be <strong>(270 + 25) % 35 = 15, 25 - 15 = 10</strong> which is equal or bigger than dash size.<br>Thus we <strong>have to start the line with leap size / 2 = 7.5 gap</strong></pre><pre>---</pre><pre>Column(<br>  children: [<br>    SizedBox(height: 25.0),<br>    Row(<br>      children: [<br>        Container(<br>          width: 290,<br>          <em>// perfect size<br>          </em>height: 25.0,<br>          color: Colors.<em>orangeAccent</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 10, gapSize: 25),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 3.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          height: 25.0,<br>          width: 285,<br>          alignment: Alignment.<em>center</em>,<br>          color: Colors.<em>lightBlueAccent</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 10, gapSize: 25),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 3.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Container(<br>          width: 270,<br>          height: 50.0,<br>          color: Colors.<em>redAccent</em>,<br>          alignment: Alignment.<em>center</em>,<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 10, gapSize: 25),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 3.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>    SizedBox(height: 25.0),<br>    Row(<br>      mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>      children: [<br>        Expanded(<br>          child: AdvancedLine(<br>            direction: Axis.<strong>horizontal</strong>,<br>            line: DashedLine(dashSize: 12, gapSize: 6),<br>            paintDef: Paint()..<strong>strokeWidth </strong>= 4.0,<br>          ),<br>        ),<br>      ],<br>    ),<br>  ],<br>),</pre><pre>// see the output below</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZA_XQPiNZb8w0LD1CFfBg.png" /></figure><p>Best regards…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=340eac726ede" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter horizontal divider]]></title>
            <link>https://icanseker.medium.com/flutter-horizontal-divider-fd6c8277cb8b?source=rss-a65db72510ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd6c8277cb8b</guid>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[İsmail Can Şeker]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 18:58:44 GMT</pubDate>
            <atom:updated>2021-04-24T01:31:24.201Z</atom:updated>
            <content:encoded><![CDATA[<p>Lets design horizontal divider widget having these features:</p><ul><li>Thickness and color selection</li><li>Define left &amp; right indent, margin insets</li><li>Define any widget (maybe icon, maybe text, anything) as label with label alignmet(combination of [top, center, bottom] x [left, center, right]) and label margin insets</li></ul><p>First of all, let’s design a prototype that will wrap the divider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9RlR-kRDt4j0NCTAGgxAA.png" /><figcaption>Divider wrapper design</figcaption></figure><p>Our outer wrapper would be a container, because we could apply margin which to be determined by user as EdgeInsets.</p><p>Place a row widget inside this wrapper container, so we could determine left and right indent as sized boxes. Left sized box width will be left indent amount and the same way right sized box width will be the right indent amount.</p><p>Lastly, we would insert line and label widget inside Expanded widget, to cover up existing space in row, between sized boxes.</p><p>So, our divider widget return will be something like:</p><pre>Container(<br>  margin: <strong>marginInsets </strong>?? EdgeInsets.<em>zero</em>,<br>  child: Row(<br>    children: [<br>      SizedBox(width: <strong>leftIndent </strong>?? 0.0),<br>      Expanded(child: <strong>lineAndLabelColumn</strong>)<br>      SizedBox(width: <strong>rightIndent </strong>?? 0.0),<br>    ],<br>  ),<br>)</pre><p>Notice that our code design perfectly suited to our prototype, anyway always try to make a habit of coding in line with the prototype. lineAndLabelColumn will be created on label, labelAlignment, label margin insets etc.</p><p>Let’s create our horizontal divider class outline with necessary parameters: (this is just an outline, we will design everything below)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/030b74d41b01a741f349f8b5984a8786/href">https://medium.com/media/030b74d41b01a741f349f8b5984a8786/href</a></iframe><p>Please notice that, we creating lineWidget as Expandable Container, its height will be divider thickness and its color will be line color.</p><p>And, labelWidgetWrapper will be an EmptyWidget(see below) if a label widget not defined. Otherwise, we put label widget into a Container (if label margin is defined), because label margin insets would be container parameter.</p><p>Lastly, if we need wrap lineWidget (and we will see why we need it below), we will use lineWidgetWrapper. Now, lets design our prototypes of divider based on label and label alignment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*Kj1k0amQgEyeMZV_-VaK-g.png" /><figcaption>center, center-left, center-right alignment prototypes</figcaption></figure><p>So, lets coding for center alignments:</p><pre><strong>if </strong>(labelPosition == Alignment.<em>center</em>) {<br>  lineWidgetWrapper = Row(children: [<br>    lineWidget,<br>    labelWidgetWrapper,<br>    lineWidget,<br>  ]);<br>} <strong>else if </strong>(labelPosition == Alignment.<em>centerLeft</em>) {<br>  lineWidgetWrapper = Row(children: [<br>    labelWidgetWrapper,<br>    lineWidget,<br>  ]);<br>} <strong>else if </strong>(labelPosition == Alignment.<em>centerRight</em>) {<br>  lineWidgetWrapper = Row(children: [<br>    lineWidget,<br>    labelWidgetWrapper,<br>  ]);<br>}</pre><ul><li>If label alignment is center, please notice that we create a row widget, adding into expandable line around label widget.</li><li>If label alignment is center left, we create a row widget and placed line right side of label widget. Remember that, line widget is expandable.</li><li>If label alignment is center right, we create a row widget and placed line left side of label widget.</li></ul><p>Lets keep going with design top side alignment prototypes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*MzqGHd50JrzQSSlH7UvspA.png" /><figcaption>top center, top-left, top-right alignment prototypes</figcaption></figure><p>So, lets coding for top alignments:</p><pre><strong>if </strong>(labelPosition == Alignment.<em>topCenter</em>) {<br>  lineWidgetWrapper = Column(<br>    children: [<br>      Row(<br>        mainAxisAlignment: MainAxisAlignment.<strong>spaceBetween</strong>,<br>        children: [<br>          SizedBox(width: 25.0),<br>          Flexible(child: labelWidgetWrapper),<br>          SizedBox(width: 25.0),<br>        ],<br>      ),<br>      Row(children: [lineWidget]),<br>    ],<br>  );<br>} <strong>else if </strong>(labelPosition == Alignment.<em>topLeft</em>) {<br>  lineWidgetWrapper = Column(<br>    children: [<br>      Row(<br>        mainAxisAlignment: MainAxisAlignment.<strong>start</strong>,<br>        children: [<br>          Flexible(child: labelWidgetWrapper),<br>          SizedBox(width: 25.0),<br>        ],<br>      ),<br>      Row(children: [lineWidget]),<br>    ],<br>  );<br>} <strong>else if </strong>(labelPosition == Alignment.<em>topRight</em>) {<br>  lineWidgetWrapper = Column(<br>    children: [<br>      Row(<br>        mainAxisAlignment: MainAxisAlignment.<strong>end</strong>,<br>        children: [<br>          SizedBox(width: 25.0),<br>          Flexible(child: labelWidgetWrapper),<br>        ],<br>      ),<br>      Row(children: [lineWidget]),<br>    ],<br>  );<br>}</pre><p>Please notice that, when label alignment is any top or any bottom, our column includes two different row widgets, one wraps line widget and the other is wraps label itself.</p><p>Bottom alignment prototypes will be the same with top alignment prototypes, except line wrapper row and label wrapper row will be upside down.</p><p>So, lets coding for bottom alignments:</p><pre><strong>if </strong>(labelPosition == Alignment.<em>bottomCenter</em>) {<br>  lineWidgetWrapper = Column(<br>    children: [<br>      Row(children: [lineWidget]),<br>      Row(<br>        mainAxisAlignment: MainAxisAlignment.<strong>spaceBetween</strong>,<br>        children: [<br>          SizedBox(width: 25.0),<br>          Flexible(child: labelWidgetWrapper),<br>          SizedBox(width: 25.0),<br>        ],<br>      ),<br>    ],<br>  );<br>} <strong>else if </strong>(labelPosition == Alignment.<em>bottomLeft</em>) {<br>  lineWidgetWrapper = Column(<br>    children: [<br>      Row(children: [lineWidget]),<br>      Row(<br>        mainAxisAlignment: MainAxisAlignment.<strong>start</strong>,<br>        children: [<br>          Flexible(child: labelWidgetWrapper),<br>          SizedBox(width: 25.0),<br>        ],<br>      ),<br>    ],<br>  );<br>} <strong>else if </strong>(labelPosition == Alignment.<em>bottomRight</em>) {<br>  lineWidgetWrapper = Column(<br>    children: [<br>      Row(children: [lineWidget]),<br>      Row(<br>        mainAxisAlignment: MainAxisAlignment.<strong>end</strong>,<br>        children: [<br>          SizedBox(width: 25.0),<br>          Flexible(child: labelWidgetWrapper),<br>        ],<br>      ),<br>    ],<br>  );<br>}</pre><p>And finally, we designed our horizontal divider completely:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dadad607bee2280bb9f0c1f660c925b/href">https://medium.com/media/9dadad607bee2280bb9f0c1f660c925b/href</a></iframe><p>Here is EmptyWidget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a44318aedf70674175be9d6dc1ec538/href">https://medium.com/media/3a44318aedf70674175be9d6dc1ec538/href</a></iframe><p>Let’s create a few example of horizontal divider output, firstly create a widget that we put divider into:</p><pre>Column(<br>    children: [<br>      Align(<br>        child: Text(<br>          <strong>&#39;Example Divider Wrapper&#39;</strong>, style: TextStyle(fontSize: 18),<br>        ),<br>        alignment: Alignment.<em>centerLeft</em>,<br>      ),<br>      Container(<br>        padding: EdgeInsets.symmetric(vertical: 20.0),<br>        decoration: BoxDecoration(<br>          border: Border.all(color: Colors.<em>black</em>26, width: 1.0),<br>        ),<br>        child: Column(<br>          mainAxisAlignment: MainAxisAlignment.<strong>center</strong>,<br>          children: [<br>            <br>          ],<br>        ),<br>      ),<br>    ],<br>  ),<br>)</pre><p>We will put dividers into a Column. Let’s start with unlabeled:</p><pre>HorizontalDivider() // just enough for unlabeled divider</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bidQoHZ8fiVKpMiNRLoBKg.png" /><figcaption>Just a line…</figcaption></figure><p>Lets try define some parameters:</p><pre>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 48.0),<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TO0wQmniUr0kCVh2KUmD5Q.png" /><figcaption>See left indent effect on left side and margin insets effect on right side.</figcaption></figure><p>Add an icon as label:</p><pre>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Icon(Icons.<em>audiotrack_outlined</em>, size: 30,),<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Icon(Icons.<em>audiotrack_outlined</em>, size: 30,),<br>  labelAlignment: Alignment.<em>centerLeft</em>,<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Icon(Icons.<em>audiotrack_outlined</em>, size: 30,),<br>  labelAlignment: Alignment.<em>centerRight</em>,<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbXtaq2t0D-uYwoXDDzwew.png" /></figure><p>Try to place label at top or bottom and see the raction:</p><pre>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Icon(<br>    Icons.<em>audiotrack_outlined</em>,<br>    size: 30,<br>  ),<br>  labelAlignment: Alignment.<em>topLeft</em>,<br>),<br>HorizontalDivider(<br>  marginInsets: EdgeInsets.symmetric(vertical: 25.0),<br>  color: Colors.<em>black38</em>,<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Icon(<br>    Icons.<em>audiotrack_outlined</em>,<br>    size: 30,<br>  ),<br>  labelAlignment: Alignment.<em>topCenter</em>,<br>),<br>HorizontalDivider(<br>  marginInsets: EdgeInsets.symmetric(vertical: 25.0),<br>  color: Colors.<em>black38</em>,<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Icon(<br>    Icons.<em>audiotrack_outlined</em>,<br>    size: 30,<br>  ),<br>  labelAlignment: Alignment.<em>bottomRight</em>,<br>  labelMarginInsets: EdgeInsets.only(right: 36),<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OE7aev-Ht-c1TQwfp-JjQ.png" /><figcaption>see last divider has label margin on right side.</figcaption></figure><p>Lets design label as Text widget:</p><pre>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Text(<strong>&#39;Text Label&#39;</strong>, style: TextStyle(fontSize: 20)),<br>),<br>HorizontalDivider(<br>  marginInsets: EdgeInsets.symmetric(vertical: 25.0),<br>  color: Colors.<em>black38</em>,<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Text(<strong>&#39;Text Label&#39;</strong>, style: TextStyle(fontSize: 20)),<br>  labelMarginInsets: EdgeInsets.symmetric(horizontal: 8.0),<br>),<br>HorizontalDivider(<br>  marginInsets: EdgeInsets.symmetric(vertical: 25.0),<br>  color: Colors.<em>black38</em>,<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Text(<strong>&#39;Text Label&#39;</strong>, style: TextStyle(fontSize: 20)),<br>  labelMarginInsets: EdgeInsets.symmetric(horizontal: 8.0),<br>  labelAlignment: Alignment.<em>topLeft</em>,<br>),<br>HorizontalDivider(<br>  marginInsets: EdgeInsets.symmetric(vertical: 25.0),<br>  color: Colors.<em>black38</em>,<br>),<br>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Text(<strong>&#39;Text Label&#39;</strong>, style: TextStyle(fontSize: 20)),<br>  labelAlignment: Alignment.<em>bottomRight</em>,<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nlTB0AdAmSocRptJvUa_g.png" /></figure><p>See the effect of second text labeled widget’s label margin insets.</p><p>Text label will cause an overflow problem, if it is too long (see how we will fix this):</p><pre>HorizontalDivider(<br>  color: Colors.<em>redAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Text(<strong>&#39;Looooooong Long Long Looooonger Text Label&#39;</strong>,<br>      style: TextStyle(fontSize: 20)),<br>) // will cause an overflow error, see how fix it below</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysvSHpv_hbMxsg1YhBPlfQ.png" /></figure><pre>// If we put Text widget into Container has BoxConstraint<br>// on maxWidth, problem fixed with customisable way<br>// win win<br>// dont forget define text overflow method</pre><pre>Container(<br>  constraints: BoxConstraints(maxWidth: 100.0),<br>  child: Text(<br>    <strong>&#39;Looooooong Long Long Looooonger Text Label&#39;</strong>,<br>    style: TextStyle(fontSize: 20),<br>    overflow: TextOverflow.<strong>ellipsis</strong>,<br>  ),<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cH6amrouv3hTfEgnpr3CAA.png" /><figcaption>fix the overflow problem</figcaption></figure><p>Extra example:</p><pre>HorizontalDivider(<br>  color: Colors.<em>lightBlueAccent</em>,<br>  thickness: 2.0,<br>  leftIndent: 12.0,<br>  marginInsets: EdgeInsets.only(right: 12.0),<br>  label: Container(<br>    child: Icon(<br>      Icons.<em>add</em>,<br>      color: Colors.<em>lightBlueAccent</em>,<br>    ),<br>    decoration: BoxDecoration(<br>      shape: BoxShape.<strong>circle</strong>,<br>      border: Border.all(<br>        width: 2.0,<br>        color: Colors.<em>blueAccent</em>,<br>      ),<br>    ),<br>  ),<br>  labelMarginInsets: EdgeInsets.symmetric(horizontal: 8.0),<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3F4bPFcGOqCcCkfGJU-uaA.png" /></figure><p>I am using this widget on my flutter chat app project (still under development), you can see this in action.</p><p><a href="https://github.com/icanseker/flutter_chapp">https://github.com/icanseker/flutter_chapp</a></p><p>Best regards…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd6c8277cb8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Avatar Widget (example of ChangeNotifier & ValueNotifier & mathematically formulated badge…]]></title>
            <link>https://icanseker.medium.com/flutter-avatar-widget-example-of-changenotifier-valuenotifier-mathematically-formulated-badge-5bcaf824e134?source=rss-a65db72510ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bcaf824e134</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[İsmail Can Şeker]]></dc:creator>
            <pubDate>Wed, 21 Apr 2021 23:33:49 GMT</pubDate>
            <atom:updated>2021-04-22T14:26:02.852Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter Avatar Widget (example of ChangeNotifier &amp; ValueNotifier &amp; mathematically formulated badge positioning)</h3><p>Lets design an avatar widget with badge having these features:</p><ul><li>Avatar widget would be any asking size. And of course the badge also.</li><li>Widget’s shape would be chosen (i will design two shape class: Circle and Square). Square borders’ radius would be changable.</li><li>Avatar badge position would be chosen: combination of [top, center, bottom] x [left, center, right]</li><li>Avatar badge would be positioned on shape line (and yes, no matter shape, border radius, avatar widget size, badge size etc.). But how? Avatar badge position would be calculated with mathematical formulation.</li><li>And the perfect side of this design: Some features would be change notified. An example scenario; when we change the picture, avatar badge would not re-build. (will increase performance)</li></ul><p>Lets start with show widget result and please focus on avatar widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*CQijStj60QO3StkMAyWFMQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e685fe0d7ab54c5541601f24d52244e4/href">https://medium.com/media/e685fe0d7ab54c5541601f24d52244e4/href</a></iframe><p>Lets create a generic class named CustomChangeNotifier which notify listeners when value changed. ChangeNotifier class do the same thing, but we will use a function named as ‘change’, which increase readability and more understandable.</p><p>We’ll use this class on defining variables that have to notify listeners after value changing. Please notice that first initialization would not notify listeners.</p><p>Now, design our abstract avatar shape class and its change notifier. Notice that, we define shape size variable as CustomChangeNotifier. Thus, we can reach change notifier of avatar size or we can use AvatarShapeChangeNotifier class to be notified on any variable change. I re-calculate border radius on size changing with rate of size change amount, so the exact shape will not broken.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eeaf25782dc92a7a08c3153d36917910/href">https://medium.com/media/eeaf25782dc92a7a08c3153d36917910/href</a></iframe><p>Lets design two avatar shape class. Circle and Square. Circle borders’ radius will automatically calculated. But Square shape borders’ radius amount will be changeable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba1e3e828ea62cf797560e05bc8196aa/href">https://medium.com/media/ba1e3e828ea62cf797560e05bc8196aa/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/498ca8fa2eef33119024825b88caeeb4/href">https://medium.com/media/498ca8fa2eef33119024825b88caeeb4/href</a></iframe><p>Then, lets create class of badge model and its change notifier including necessary variable definitions. See that, define color, size, border size and color as CustomChangeNotifier class. And notice that when we design badge model change notifier, we just add notifyListeners function as a listener to changable variables’ notifier. It will trigger badge model notifier on any value change. This design will be perfect, because we can reach every variables’ change notifier and/or the general badge change notifier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4decc57584d5ba698df50d49873fef48/href">https://medium.com/media/4decc57584d5ba698df50d49873fef48/href</a></iframe><p>And now, we can design stateless Avatar Badge widget which takes a Badge model and builds by this model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e79c1aff17d74dfcda49da95cd73f9c/href">https://medium.com/media/1e79c1aff17d74dfcda49da95cd73f9c/href</a></iframe><p>Notice that, ValueListenableBuilder listening to badge change notifier, each notification will cause re-build the widget. And yes, this widget is stateless. You can design your change listeners via your needs. Interventions on badge model class would reflect on the widget instantly, if model change notifier is listening related variable changes.</p><p>Now, we can create avatar model and its change listener.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be9f23be6e465ea09643dd931c3e98e1/href">https://medium.com/media/be9f23be6e465ea09643dd931c3e98e1/href</a></iframe><p>I will explain how calculateBadgePaddingAmount function is working and calculates amount of what, why we need it? What is its’ formulation?</p><p>Firstly, we design avatar widget itself:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42c39367773ea6a0a954ed3592897a50/href">https://medium.com/media/42c39367773ea6a0a954ed3592897a50/href</a></iframe><p>Lets see what we calculated?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JKMunH4w3nWDJFnoqC-n1Q.png" /></figure><p>See avatar widget, we create a stack widget inside a container which has avatar shape width and height. And we decide position of badge with Alignment value (suppose it is top-right)</p><pre><strong>if </strong>(<strong>badgePosition </strong>== Alignment.<em>topRight</em>)<br>  <strong>_badgePaddingAmount </strong>= <strong>shape</strong>.<strong>topRightBorderRadius </strong>* 0.29;<br><strong>else if </strong>(<strong>badgePosition </strong>== Alignment.<em>topLeft</em>)<br>  <strong>_badgePaddingAmount </strong>= <strong>shape</strong>.<strong>topLeftBorderRadius </strong>* 0.29;<br><strong>else if </strong>(<strong>badgePosition </strong>== Alignment.<em>bottomRight</em>)<br>  <strong>_badgePaddingAmount </strong>= <strong>shape</strong>.<strong>bottomRightBorderRadius </strong>* 0.29;<br><strong>else if </strong>(<strong>badgePosition </strong>== Alignment.<em>bottomLeft</em>)<br>  <strong>_badgePaddingAmount </strong>= <strong>shape</strong>.<strong>bottomLeftBorderRadius </strong>* 0.29;<br><br><strong>_badgePaddingAmount </strong>=<br>    <strong>_badgePaddingAmount </strong>- (<strong>badgeModel</strong>.<strong>size </strong>/ 2) + (<strong>borderSize </strong>/ 2) - 1;</pre><ul><li>If badge positioned on a corner, border radius of this corner * 0,29 will give us avatar badge radius position over avatar widget radius.</li><li>If this amount is less than zero, it means no need to move badge, we have to shrink avatar shape (see calculateBadgeContainerPadding function).</li><li>If this amount is bigger than zero, calculateBadgePadding function will calculate which side we have to slide the badge to place badge on the shape line.</li></ul><p>This formula will give us an advantage that we can create more different shaped avatar, like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EFTWuL3jzRITHDHZVwXypg.png" /></figure><p>I am using EmptyWidget class when i need place nothing (some widgets don’t accept ‘null’ variable/widget). If you wonder that how EmptyWidget is designed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3113aa79e8f66f872d4e5b837df9c85f/href">https://medium.com/media/3113aa79e8f66f872d4e5b837df9c85f/href</a></iframe><p>I am using this widget on my flutter chat app project (still under development), you can see this in action.</p><p><a href="https://github.com/icanseker/flutter_chapp">https://github.com/icanseker/flutter_chapp</a></p><p>Best regards…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bcaf824e134" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>