Drawing in Flutter using CustomPainter
<h1>Introduction :</h1>
<p>In Flutter everything revolves around the term <strong>Widget. </strong>Flutter gives you the flexibility to write one code, create some beautiful UI widgets and the app is ready for both iOS and Android.So what actually happens is these widgets that you create are drawn on to your mobile screen Or we can call it as drawn on to the <strong><em>Canvas. </em></strong>Using the same concept we can draw on it and use it as a drawing board.</p>
<p><img alt="" src="https://miro.medium.com/v2/resize:fit:294/1*Qodd3kD22dbhfazsgd0nJw.png" style="height:584px; width:294px" /></p>
<p>We will be using <strong><em>custom painter</em> </strong>for drawing on the canvas, we will have options to change size, opacity and color of the marker.</p>
<p>The code is available at <a href="https://github.com/sharansingh00002/draw" rel="noopener ugc nofollow" target="_blank">https://github.com/sharansingh00002/draw</a></p>
<p>You can also checkout my video with extra code :p to take image for image drawn also :</p>
<p><a href="https://www.youtube.com/watch?v=xHWAE8BNJ1E" rel="noopener ugc nofollow" target="_blank">https://www.youtube.com/watch?v=xHWAE8BNJ1E</a></p>
<p>Now lets have a look at how this is done :)</p>
<p><strong>CODE TIME</strong></p>
<p>So the first information we need to have is the coordinates of the point on the canvas where the user has interacted with, which we can get simply by using Gesture Detector. We will be using <strong>onPanUpdate, onPanStart </strong>and<strong> onPanEnd </strong>properties of gesture detector. <strong><em>onPanStart</em></strong> is used when a user just clicks the screen, that way we can draw a single point but if user drags then the continuous points are obtained using the <strong><em>onPanUpdate </em></strong>and <strong><em>OnPanEnd </em></strong>is to notify user has stopped drawing.</p>
<p>We will be storing the points in a list where each element will have the coordinates as well as paint properties associated with that point.</p>
<p><a href="https://medium.com/flutter-community/drawing-in-flutter-using-custompainter-307a9f1c21f8">Click Here</a></p>