<?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 Aayush Malhotra on Medium]]></title>
        <description><![CDATA[Stories by Aayush Malhotra on Medium]]></description>
        <link>https://medium.com/@aayushm864?source=rss-af988dfcf882------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pkLtcXGJS_ukfqgAZu27Cw.png</url>
            <title>Stories by Aayush Malhotra on Medium</title>
            <link>https://medium.com/@aayushm864?source=rss-af988dfcf882------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 15 May 2026 16:11:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aayushm864/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[Sketching app- Flutter]]></title>
            <link>https://medium.com/techspace-usict/sketching-app-flutter-1c3674c84f9e?source=rss-af988dfcf882------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c3674c84f9e</guid>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[idroid]]></category>
            <dc:creator><![CDATA[Aayush Malhotra]]></dc:creator>
            <pubDate>Fri, 30 Aug 2019 14:07:40 GMT</pubDate>
            <atom:updated>2019-08-30T14:07:40.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73IgUxPfyXUKZAaIXgutrw.png" /></figure><p>Today we’ll be making a really simple yet fun application on Flutter.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FdUBv1TS8Z35kaGtGCf%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FdUBv1TS8Z35kaGtGCf&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FdUBv1TS8Z35kaGtGCf%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="870" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d2b221cfca2fdfa4ed34e010aaabee/href">https://medium.com/media/b3d2b221cfca2fdfa4ed34e010aaabee/href</a></iframe><p>Flutter is a cross-platform framework that allows you to build apps for both iOS and Android with a single code base. I genuinely love Flutter and cannot get enough of it. I hope this tutorial gives you a new perspective towards this wonderful piece of technology and motivates you to build your own projects on it. Enough chit chat let’s get right into it.</p><h3><strong>Getting Started</strong></h3><p>I assume you have installed Flutter on your device. If you haven’t check out this link(<a href="https://flutter.dev/docs/get-started/install">https://flutter.dev/docs/get-started/install</a>) for step by step guidance.</p><p>Create a new flutter project from your terminal using the command :</p><blockquote><strong>flutter create &lt;your-project-name&gt;</strong></blockquote><p>Once created move to the project directory and open it in your IDE (VS code, Android Studio etc.). I use VS Code and it looks something like this initially:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1rhYt40aJqcIAGgXfriSw.png" /><figcaption>Initial State of the project named “draw”</figcaption></figure><p>Remove the all comments and the code present in MyHomePage widget.</p><p>I have added the theme parameter as well, it is completely OK if you want to skip the dark theme. Now let’s actually build what we had in mind.</p><h3><strong>Coding the sketching part</strong></h3><p>If you are not familiar with it, Flutter has an abstract class called CustomPainter. As the name suggests it is basically used to paint something on the screen and for our project this is exactly what we need. In our _MyHomePageState class we need to declare a list of Offset points. These points would actually be like dots which will connect the paint on screen. You can declare them by using the following line of code :</p><blockquote><em>List&lt;Offset&gt; points = &lt;Offset&gt;[];</em></blockquote><p>Now let’s build the area in which we can detect user input and sketch accordingly. We define a Container() as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96b855526fde693b88aefd989900fb37/href">https://medium.com/media/96b855526fde693b88aefd989900fb37/href</a></iframe><p>We have defined this within our class _MyHomePageState inside of our build function. Feel free to change the color property of the box. I didn’t have time for good UI decisions. Do not be afraid of the CustomPaint function and the Sketcher class, we have to implement them in the next step itself. This code is self explanatory now, we have a box whose child is a paint and the paint would depend on the offsets we provide to it. <strong>Ez Pz.</strong></p><p>Now let us focus on the CustomPaint class.</p><p>Declare a new class in the same file as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5093e9160fd46b587ebef295ab62c8dd/href">https://medium.com/media/5093e9160fd46b587ebef295ab62c8dd/href</a></iframe><p>You will see an error when you put this code in your file which basically says that there are overrides that are missing from this class. In Flutter, CustomPainter class has an override function that checks if the existing paint should be repainted. Add the missing overrides from the Editor itself and let it be as it is for now. We now have two new functions in the class, <em>void paint() </em>and <em>bool shouldRepaint().</em></p><p>Now for our painting part we require only one variable and that is our list of Offset. So we declare a list of Offset and add it to the constructor of this class.</p><p>In the paint function add the following lines of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*NtTu4zqKj9bbbBk7IMSdtA.png" /></figure><p>That might be very new for some of you so allow me to explain. We first declare a Paint object that will be responsible for painting on the screen. Consider it the brush of our app. Using ‘..’ operator in Dart we set the properties of the paint. We set the color to blue, strokeCap to round and strokeWidth to 4.0. We can obviously play around with these values but for now let’s leave them as they are. We then iterate over all the points using the for loop and check if the current point and the next point are not equal to null. If they are not then we draw a line on the canvas using our paint.</p><p>Now in the second function we check if the previously drawn points are same as the currently drawn points. If they are equal then we<strong> return false</strong> and we will not update the screen, however, if they are unequal we<strong> return true</strong> and actually repaint the screen as the function suggests. I hope you understand that the points we are talking about are actually from the list of Offset that we have previously declared. Our class would finally look as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*jsSorCqvznnYx6m6F8ppxg.png" /></figure><p>Cool right? This small little class will allow us to draw stuff on our canvas. Moving on to the next section.</p><h3><strong>Canvas and Clear Button</strong></h3><p>We have our brush ready, we just need a canvas. We now move to the build function of our _MyHomePageState class.</p><p>Add the following lines of code to your build method(ignoring the sketch area which is already there):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*usmwnRnFdEo-hX3QnnwrMg.png" /></figure><p>Allow me to explain again. We create the sketch area as before and return a Scaffold from our build function. <strong>Ez Pz</strong>. Now in the body of the Scaffold we add an Appbar() and specify it’s text. For the body we use a GestureDetector() since we need to update the state of our app based on user inputs, specifically drag. We use the onPanUpdate method to check panning or drag on screen. Inside the setState method we see that we have the core of our application. I’ll explain each and every line of it :</p><ol><li><strong>RenderBox box = context.findRenderObject();</strong></li></ol><p>This line tells the application to find the object that has to be rendered from this context. In our case the object would be our paint from the Sketcher class.In simple words you can imagine a box that encapsulates our sketch area and that would be used to render our paint.</p><p>2. <strong>Offset point = box.globalToLocal(details.globalPosition);</strong></p><p>This line of code converts our worldly movements on screen to local screen coordinates so that an Offset or coordinate can be obtained to start with. This point is the point on this box where it all began or from where it will all continue.</p><p>3. <strong>point = point.translate(0.0, -(AppBar().preferredSize.height));</strong></p><p>This line translates/moves that point to our specified point. This is done in order to ensure that our line that we draw does not go over the Appbar and stays in the sketch area we have specified. This line of code is basically a check that makes sure that our app renders the paint where and as we want it to.</p><p>Lastly we add this point to our list of Offset so that our Sketcher can process it and paint accordingly.</p><p>In our <em>onPanEnd</em> function we just add a <em>null</em> value to our List so that we have nothing to paint.</p><p>We then add our sketch area as a child to this GestureDetector().</p><p>To clear the screen we have a <em>floatingActionButton</em> that removes each point from the list when it is pressed. When the list is empty we would have nothing to see and hence we achieve clarity along with some peace of mind.We specify how our button looks with the remaining properties.</p><p>For the lazy people like myself, the final code is available at:</p><p><a href="https://github.com/AadumKhor/sketch-music/blob/master/lib/main.dart">AadumKhor/sketch-music</a></p><p>Copy paste it in your editor.</p><p>Now the fun part. From your project directory, type flutter run to test this project on a connected device.</p><p><strong>Voilà</strong></p><p>So in this tutorial we learnt about the CustomPainter class and implemented it beautifully in an application.</p><p>I know I should have added GitHub gists but there was some issue with them. Will add them in the next one for sure.</p><p>I hope you all enjoyed my debut blog. Stay tuned for more and keep learning.</p><p>You can check out my GitHub profile at :</p><p><a href="https://github.com/AadumKhor">AadumKhor - Overview</a></p><p>Also checkout these new blog from our publication techspace :</p><ul><li><a href="https://medium.com/techspace-usict/flutter-quick-start-guide-366087410ce4">Flutter Quick Start Guide!</a></li><li><a href="https://medium.com/techspace-usict/swish-a-self-gated-activation-function-3b7e551dacb5">Swish: A self-gated Activation Function</a></li><li><a href="https://medium.com/techspace-usict/the-secret-step-by-step-guide-to-learn-hacking-spoonfed-edition-9bf365161e8a">The Secret step-by-step Guide to learn Hacking — Spoonfed Edition!</a></li><li><a href="https://medium.com/techspace-usict/how-to-create-interactive-maps-in-react-js-ccdfad460fa0">How to create Interactive Maps in React.js</a></li><li><a href="https://medium.com/techspace-usict/how-pythons-list-works-so-dynamically-and-efficiently-amortized-analysis-ee5ea00643fc">How Python’s List works so dynamically and efficiently: Amortized Analysis</a></li></ul><p>Constructive feedback accepted xD.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c3674c84f9e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techspace-usict/sketching-app-flutter-1c3674c84f9e">Sketching app- Flutter</a> was originally published in <a href="https://medium.com/techspace-usict">Techspace</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>