<?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: Neat Fastro</title>
    <description>The latest articles on DEV Community by Neat Fastro (@neatfastro).</description>
    <link>https://dev.to/neatfastro</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%2F479750%2Fe95bf522-4f5a-4dd9-8cab-2bf9c28e0cf7.jpg</url>
      <title>DEV Community: Neat Fastro</title>
      <link>https://dev.to/neatfastro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/neatfastro"/>
    <language>en</language>
    <item>
      <title>Pinterest Floating Navigation Bar with Animations in Flutter</title>
      <dc:creator>Neat Fastro</dc:creator>
      <pubDate>Thu, 08 Oct 2020 05:19:04 +0000</pubDate>
      <link>https://dev.to/neatfastro/pinterest-floating-navigation-bar-with-animations-49ga</link>
      <guid>https://dev.to/neatfastro/pinterest-floating-navigation-bar-with-animations-49ga</guid>
      <description>&lt;p&gt;In this short tutorial we will learn how to create the Navigation Bar of Pinterest App with hiding and reappearing behavior on user scroll.&lt;/p&gt;

&lt;p&gt;This how our starting setup up looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return SizedBox(
            height: 260,
            child: Card(
              child: Center(child: Text('Item #$index')),
            ),
          );
        },
      ),
      bottomNavigationBar: SizedBox(
        height: 60,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Icon(Icons.home),
            Icon(Icons.search),
            Icon(Icons.favorite_border),
            Icon(Icons.person_rounded),
          ],
        ),
      ),
    );
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Wrap Scaffold widget in &lt;code&gt;NotificationListener&amp;lt;ScrollUpdateNotification&amp;gt;()&lt;/code&gt; widget with "ScrollUpdateNotification" type,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This gives you a "ScrollUpdateNotification" object in a callBack function which gets executed when the user attempts scrolling on the screen.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now Wrap your BottomNavigationBar in &lt;a href="https://youtu.be/yI-8QHpGIP4"&gt;Animated Container&lt;/a&gt; and specify the transform: property like this:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; AnimatedContainer(
          duration: Duration(milliseconds: 300),
        &amp;gt; transform: Matrix4.translationValues(0, yTransValue,0),
          child: BottomNavBarWidget(),
        ),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make a variable of type "double" with appropriate name (yTransValue) and set it's value to 0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;onNotification callBack check the sign value of scroll delta&lt;br&gt;
if it is equal to 1 then it means user has swiped up on the screen and if it's -1 then user has swiped down on the screen.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;onNotification: (notification) {
        if (notification.scrollDelta.sign == 1) {
          setState(() {
            yTransValue = 100;
          });
        } else if (notification.scrollDelta.sign == -1) {
          setState(() {
            yTransValue = 0;
          });
        }
      },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and we are done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here's the complete code:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Home extends StatefulWidget {
  @override
  _HomeState createState() =&amp;gt; _HomeState();
}

class _HomeState extends State&amp;lt;Home&amp;gt; {
  double yTransValue = 0;

  @override
  Widget build(BuildContext context) {
    return NotificationListener&amp;lt;ScrollUpdateNotification&amp;gt;(
      onNotification: (notification) {
        print(notification.metrics.axisDirection);
        print(notification.metrics.axis);

        if (notification.scrollDelta.sign == 1) {
          setState(() {
            yTransValue = 100;
          });
        } else if (notification.scrollDelta.sign == -1) {
          setState(() {
            yTransValue = 0;
          });
        }
      },
      child: Scaffold(
        body: ListView.builder(
          itemBuilder: (BuildContext context, int index) {
            return SizedBox(
              height: 260,
              child: Card(
                child: Center(child: Text('Item #$index')),
              ),
            );
          },
        ),
        bottomNavigationBar: AnimatedContainer(
          duration: Duration(milliseconds: 300),
          transform: Matrix4.translationValues(0, yTransValue, 0),
          child: SizedBox(
            height: 60,
            child: Card(
              color: Colors.grey,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Icon(Icons.home),
                  Icon(Icons.search),
                  Icon(Icons.favorite_border),
                  Icon(Icons.person_rounded),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;code result &lt;a href="https://youtu.be/-Vg9hmxS74w"&gt;video&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>tips</category>
    </item>
  </channel>
</rss>
