<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sahdeep Singh</title>
    <description>The latest articles on DEV Community by Sahdeep Singh (@iamsahdeep).</description>
    <link>https://dev.to/iamsahdeep</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F351288%2F89a8dc88-9c74-4655-841f-57988d720268.jpeg</url>
      <title>DEV Community: Sahdeep Singh</title>
      <link>https://dev.to/iamsahdeep</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamsahdeep"/>
    <language>en</language>
    <item>
      <title>Custom cursor in Flutter Web...</title>
      <dc:creator>Sahdeep Singh</dc:creator>
      <pubDate>Tue, 21 Jul 2020 19:04:14 +0000</pubDate>
      <link>https://dev.to/iamsahdeep/custom-cursor-in-flutter-web-1k4l</link>
      <guid>https://dev.to/iamsahdeep/custom-cursor-in-flutter-web-1k4l</guid>
      <description>&lt;p&gt;So for the 3rd week of Codepen's flutter challenge we had to use &lt;a href="https://flutter.dev/docs/codelabs/implicit-animations"&gt;implicit animations&lt;/a&gt; in flutter, using them I kind of made a custom cursor for the website. &lt;br&gt;
We are not actually changing the system cursor to another like &lt;a href="https://medium.com/@aflutterdev/handcursor-for-flutter-web-6552bed19f91"&gt;in this blog&lt;/a&gt;, rather its a trick, we are hiding the real one and adding a widget to the current hover position.&lt;/p&gt;
&lt;h2&gt;
  
  
  Lets get started
&lt;/h2&gt;

&lt;p&gt;First we need to wrap our scaffold's body with &lt;a href="https://api.flutter.dev/flutter/widgets/MouseRegion-class.html"&gt;MouseRegion&lt;/a&gt; widget, with it we can get the cursor position in real-time and it also have property named &lt;code&gt;cursor&lt;/code&gt; through which we can change the actual cursor or replace with other system cursors.&lt;br&gt;
In our case we will hide cursor and set pointer on Hover, like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body: MouseRegion(
          cursor: SystemMouseCursors.none,
          onHover: (eve) {
            setState(() {
              pointer = eve.position;
            });
          },
          child: ...
      ),
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Second step is to add a widget at the &lt;code&gt;pointer&lt;/code&gt;'s position. For that we will use &lt;code&gt;Stack&lt;/code&gt; widget and &lt;code&gt;Positioned&lt;/code&gt; widget to position our custom made cursor in the stack. Make sure your stack have full width and height.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Stack(
   children: [
       Positioned(
           left : ...
           top : ...
          ),
       OtherWidgets(),
     ],
   )
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we need to add child to &lt;code&gt;Positioned&lt;/code&gt; widget, I made the simple Cursor (its just a circular ring).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
           borderRadius: BorderRadius.all(Radius.circular(100)),
           border: Border.all(
                 width: 4,
                 color: Colors.white,
                 style: BorderStyle.solid)),
     ),
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now just one this is left i.e., to position this cursor. For that we will just use the &lt;code&gt;dx&lt;/code&gt; and &lt;code&gt;dy&lt;/code&gt; from the pointer offset. So the complete code will look like :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      Positioned(
         left: pointer.dx - 100,
         top: pointer.dy - 100,
         child: Container(
           height: 200,
           width: 200,
           decoration: BoxDecoration(
               borderRadius: BorderRadius.all(Radius.circular(100)),
               border: Border.all(
                   width: 4,
                   color: Colors.white,
                   style: BorderStyle.solid)),
          ),
       ),
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Why &lt;code&gt;-100&lt;/code&gt; ? you know it :)  &lt;/p&gt;

&lt;p&gt;Here we go, you got yourself a custom Cursor in flutter web. But there is something missing? cursor movement is kind of stiff, right? Here comes the implicit animations part.&lt;/p&gt;

&lt;p&gt;Just simply use &lt;code&gt;AnimatedPositioned&lt;/code&gt; widget instead of &lt;code&gt;Positioned&lt;/code&gt; and add duration to it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Result
&lt;/h1&gt;

&lt;p&gt;I have added other animations as well using the same criteria in the following pen. &lt;br&gt;
Preview : &lt;a href="https://flutteranimations.netlify.app/#/"&gt;https://flutteranimations.netlify.app/#/&lt;/a&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/iamSahdeep/embed/JjGxoRd?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Thanks for reading :)&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>flutter</category>
      <category>dart</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Submarine - Flutter Stack Challenge</title>
      <dc:creator>Sahdeep Singh</dc:creator>
      <pubDate>Thu, 09 Jul 2020 16:20:24 +0000</pubDate>
      <link>https://dev.to/iamsahdeep/submarine-flutter-stack-challenge-4gfm</link>
      <guid>https://dev.to/iamsahdeep/submarine-flutter-stack-challenge-4gfm</guid>
      <description>&lt;p&gt;Here is another codepen, for Weekly Flutter CodePen challenge in July. For the first week we have to use one of the most foundational building blocks in Flutter - "Stack" &lt;/p&gt;

&lt;p&gt;You can get more details about this challenge at : &lt;a href="https://codepen.io/challenges/2020/july/"&gt;https://codepen.io/challenges/2020/july/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I am calling it Submarine, you can dive deep into the ocean using this submarine xD&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Use Live preview for better performance in web that too on PC or Laptop.&lt;/p&gt;

&lt;p&gt;Live Preview at : &lt;a href="https://iamsahdeep.github.io/Submarine-FlutterStackChallenge/#/"&gt;https://iamsahdeep.github.io/Submarine-FlutterStackChallenge/#/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github Source : &lt;a href="https://github.com/iamSahdeep/Submarine-FlutterStackChallenge"&gt;https://github.com/iamSahdeep/Submarine-FlutterStackChallenge&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Codepen Preview&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/iamSahdeep/embed/vYLRdqz?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Some Tricks in Code :)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Widget Tree :&lt;/p&gt;

&lt;p&gt;Scaffold&lt;br&gt;
--Stack&lt;br&gt;
----SingleChildScrollView (Background)&lt;br&gt;
------TopView&lt;br&gt;
------MiddleView&lt;br&gt;
------BottomView&lt;br&gt;
------DeepestView&lt;br&gt;
----MoonView&lt;br&gt;
----SubMarine&lt;br&gt;
----LightHouse&lt;br&gt;
----SingleChildScrollView (invisible)&lt;/p&gt;

&lt;p&gt;Here I have to use another SingleChildScrollView, which is invisible and that too in front of all the View in Stack. Reason for this scrollView is, that all other views in the same Stack, like moon, lighthouse, submarine, were blocking the gesture while Scrolling. So we need another ScrollView and sync its offset with Background ScrollView. How to sink it?  its simple, see the code below :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;invisibleScrollController.addListener(() {
      if (scrollController.offset != invisibleScrollController.offset) {
        scrollController.jumpTo(invisibleScrollController.offset);
      }
    });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Another Trick, for those animations is to use the scroll offset and pass it to every child Widget and make them rebuild on every scroll change. I have not used any state management like bloc or provider, just simply using setState() to change it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scrollController.addListener(() {
      setState(() {
        scrollOffset = scrollController.offset / 100;
      });
    });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In code above offset is reduced by dividing it by 100 as offset can go from 0 - 1000 or much more, depends upon the height of the SingleChildScrollView and we usually don't need that high value for small animations.&lt;/p&gt;

&lt;p&gt;That offset, than can be use with "Transfrom" widget for scaling and rotation. And offset is also used with "Positioned" widget to make child widget animated w.r.t scroll.&lt;/p&gt;

&lt;p&gt;Thanks :)&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>codepen</category>
      <category>flutterchallenge</category>
    </item>
    <item>
      <title>Liquid Button in Flutter</title>
      <dc:creator>Sahdeep Singh</dc:creator>
      <pubDate>Sat, 27 Jun 2020 17:01:28 +0000</pubDate>
      <link>https://dev.to/iamsahdeep/liquid-button-in-flutter-1m3n</link>
      <guid>https://dev.to/iamsahdeep/liquid-button-in-flutter-1m3n</guid>
      <description>&lt;p&gt;Hey, Check out my Experiment for Liquid Button in flutter.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/iamSahdeep/embed/GRovBMO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If above preview is not working, link to pen is &lt;a href="https://codepen.io/iamSahdeep/pen/GRovBMO"&gt;https://codepen.io/iamSahdeep/pen/GRovBMO&lt;/a&gt;&lt;br&gt;
And it only works on laptop or pc.&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>flutter</category>
      <category>dart</category>
    </item>
  </channel>
</rss>
