<?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 Om Londhe on Medium]]></title>
        <description><![CDATA[Stories by Om Londhe on Medium]]></description>
        <link>https://medium.com/@omlondhe?source=rss-88254678ca85------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8qJRskgqHPI8KrM_yeNvFQ.jpeg</url>
            <title>Stories by Om Londhe on Medium</title>
            <link>https://medium.com/@omlondhe?source=rss-88254678ca85------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:33:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omlondhe/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[Sliding a Container in and out while navigating in Flutter Pokedex]]></title>
            <link>https://medium.com/@omlondhe/sliding-a-container-in-and-out-while-navigating-in-flutter-pokedex-17a7d0829ce6?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/17a7d0829ce6</guid>
            <category><![CDATA[flutter-om-londhe]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-animation]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Sun, 02 Jan 2022 12:37:55 GMT</pubDate>
            <atom:updated>2022-01-02T12:37:55.775Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-D3AAtIsaXGDc_7-hJ3Ig.jpeg" /></figure><p>We are done with all things on the <strong>Home</strong> screen as of now. This is the time to make changes to the <strong>Details</strong> screen. Here too we did a lot of changes, we have to make some more changes now. The first one is animating the <strong>Container</strong> in and out while navigating. If you just want to learn this thing then directly follow the article ignoring some specific things that I am explaining considering the Pokedex app that we are building, and if you want to follow along with the <strong>Pokedex</strong> application that we are building, you can just the code below.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-6">GitHub - Om-Londhe/FlutterPokedex at part-6</a></p><p>The container from the <strong>Details</strong> screen which we are going to animate is present in another file. Thus we have to do all the changes in the <strong>detail_data.dart</strong> file. So open that file to follow along. What we are doing is just adding an animation to the <strong>Container </strong>so that it will come up when we go to the <strong>Details</strong> screen and go down when we try to go back.</p><p>First of all, use the following code to convert the current stateless class to the stateful class so that we can add a <strong>SingleTickerProviderStateMixin </strong>to it for our transition.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre><strong>class DetailData extends StatefulWidget {<br>  final int id;<br>  const DetailData({Key? key, required this.id}) : super(key: key);</strong></pre><pre><strong>@override<br>  State&lt;DetailData&gt; createState() =&gt; _DetailDataState();<br>}</strong></pre><pre><strong>class _DetailDataState extends State&lt;DetailData&gt; with SingleTickerProviderStateMixin {</strong><br>  @override<br>  Widget build(BuildContext context) {<br>    return Container(<br>      constraints: BoxConstraints(<br>        minWidth: MediaQuery.of(context).size.width,<br>        minHeight: 500,<br>      ),<br>      decoration: const BoxDecoration(<br>        color: Colors.white,<br>        borderRadius: BorderRadius.only(<br>          topLeft: Radius.circular(51),<br>          topRight: Radius.circular(51),<br>        ),<br>      ),<br>      child: Column(<br>        children: const [Text(&quot;To be continued....&quot;)],<br>      ),<br>    );<br>  }<br>}</pre><p>Now we will wrap our <strong>Container </strong>with the <strong>SlideTransition widget</strong>, and as we know, this widget accepts the <strong>position </strong>as an argument so that the widget will be animated for the given position interpolation. Thus we have to create an <strong>AnimationController </strong>and an <strong>Offset animation interpolator</strong> to drive the animation over the desired positions.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailData extends StatefulWidget {<br>  final int id;<br>  const DetailData({Key? key, required this.id}) : super(key: key);</pre><pre>@override<br>  State&lt;DetailData&gt; createState() =&gt; _DetailDataState();<br>}</pre><pre>class _DetailDataState extends State&lt;DetailData&gt; with SingleTickerProviderStateMixin {<br>  <strong>late final AnimationController _slideAnimationController = AnimationController(vsync: this, duration: const Duration(milliseconds: 750));<br>  late final Animation&lt;Offset&gt; _slideAnimation = Tween&lt;Offset&gt;(begin: const Offset(0, 1), end: Offset.zero).animate(_slideAnimationController);</strong></pre><pre>@override<br>  Widget build(BuildContext context) {<br>    return <strong>SlideTransition(<br>      position: _slideAnimation,</strong><br>      child: Container(<br>        constraints: BoxConstraints(<br>          minWidth: MediaQuery.of(context).size.width,<br>          minHeight: 500,<br>        ),<br>        decoration: const BoxDecoration(<br>          color: Colors.white,<br>          borderRadius: BorderRadius.only(<br>            topLeft: Radius.circular(51),<br>            topRight: Radius.circular(51),<br>          ),<br>        ),<br>        child: Column(<br>          children: const [Text(&quot;To be continued....&quot;)],<br>        ),<br>      ),<br>    <strong>);</strong><br>  }<br>}</pre><p>Now, our <strong>Container</strong> is no longer visible, and this is not what we wanted. The reason behind this is the <strong>Offset </strong>given to the <strong>Tween</strong> of type <strong>Offset</strong>. As it is initially 0 for x and 1 for the y-axis, the container is at the bottom of the screen. The following code will drive it forward and backward upon navigational changes. It is just running the animation forward when the widget is initialized and running it reverses when the user presses the back button, for this purpose the <strong>WillPopScope</strong> widget is used which allows us to override the back button action.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailData extends StatefulWidget {<br>  final int id;<br>  const DetailData({Key? key, required this.id}) : super(key: key);</pre><pre>@override<br>  State&lt;DetailData&gt; createState() =&gt; _DetailDataState();<br>}</pre><pre>class _DetailDataState extends State&lt;DetailData&gt;<br>    with SingleTickerProviderStateMixin {<br>  late final AnimationController _slideAnimationController =<br>      AnimationController(<br>          vsync: this, duration: const Duration(milliseconds: 500));<br>  late final Animation&lt;Offset&gt; _slideAnimation =<br>      Tween&lt;Offset&gt;(begin: const Offset(0, 1), end: Offset.zero)<br>          .animate(_slideAnimationController);</pre><pre><strong>@override<br>  void initState() {<br>    super.initState();<br>    _slideAnimationController.forward();<br>  }</strong></pre><pre><strong>@override<br>  void dispose() {<br>    super.dispose();<br>    _slideAnimationController.dispose();<br>  }</strong></pre><pre>@override<br>  Widget build(BuildContext context) {<br>    return <strong>WillPopScope(<br>      onWillPop: () {<br>        _slideAnimationController.reverse();<br>        return Future.delayed(const Duration(milliseconds: 100))<br>            .then((value) =&gt; true);<br>      },</strong><br>      child: SlideTransition(<br>        position: _slideAnimation,<br>        child: Container(<br>          constraints: BoxConstraints(<br>            minWidth: MediaQuery.of(context).size.width,<br>            minHeight: 500,<br>          ),<br>          decoration: const BoxDecoration(<br>            color: Colors.white,<br>            borderRadius: BorderRadius.only(<br>              topLeft: Radius.circular(51),<br>              topRight: Radius.circular(51),<br>            ),<br>          ),<br>          child: Column(<br>            children: const [Text(&quot;To be continued....&quot;)],<br>          ),<br>        ),<br>      ),<br>    <strong>);</strong><br>  }<br>}</pre><p>That’s all for this article. Click the link below for code.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-7">GitHub - Om-Londhe/FlutterPokedex at part-7</a></p><h3>Thank you and Happy New Year!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17a7d0829ce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ScrollPhysics management in Flutter]]></title>
            <link>https://medium.com/@omlondhe/scrollphysics-management-in-flutter-7e62036d31b2?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e62036d31b2</guid>
            <category><![CDATA[flutter-om-londhe]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-scroll-physics]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Sat, 01 Jan 2022 18:06:51 GMT</pubDate>
            <atom:updated>2022-01-01T18:06:51.800Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*VThhWQuAU8gQijnGNe6g9g.png" /></figure><p><strong>Happy New year,</strong> first of all, we were building a Flutter Pokedex last year and this year we are taking it ahead. The first thing that we are going to learn and implement is the <strong>ScrollPhysics</strong>. Let me bombard some theory on you.</p><p><strong>ScrollPhysics</strong> is the physics for scrollable widgets like <strong>GridView</strong>,<strong> ListView</strong>, <strong>SingleChildScrollView</strong>, etc. The <strong>ScrollPhysics </strong>can be passed to the scrollable widgets in their <strong>physics</strong> attribute so that the given physics will be applied to their scroll behaviour.</p><p>For our case, we want to make use of this in our <strong>detail.dart</strong> file. Currently the <strong>BouncingScrollPhysics</strong> is applied to the <strong>physics</strong> attribute of our <strong>SingleChildScrollView</strong> of the <strong>Details</strong> widget. But, this does not look that great. It would be nice if we could find a way to make its scroll physics <strong>bouncing</strong> for the top edge scrolling and <strong>clamping</strong> for bottom edge scrolling.</p><p>For the above scenario, we have to make our <strong>Details </strong>widget a <strong>stateful</strong> widget so that we can attach the <strong>ScrollController</strong> to the <strong>SingleChildScrollView</strong> and change the <strong>physics </strong>property on the go when it could be the case that user will overscroll to the top. Use the following code in your <strong>details.dart </strong>file.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_back_button.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_data.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_image.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_title.dart&#39;;</pre><pre><strong>class Details extends StatefulWidget {<br>  final int? id;<br>  final String? name;<br>  final String? image;<br>  const Details({Key? key, this.id, this.name, this.image}) : super(key: key);</strong></pre><pre><strong>@override<br>  State&lt;Details&gt; createState() =&gt; _DetailsState();<br>}</strong></pre><pre><strong>class _DetailsState extends State&lt;Details&gt; {<br>  final _controller = ScrollController();</strong></pre><pre><strong>ScrollPhysics _physics = const BouncingScrollPhysics();</strong></pre><pre><strong>@override<br>  void initState() {<br>    super.initState();<br>    _controller.addListener(() {<br>      if (_controller.position.pixels &lt;= 56) {<br>        setState(() =&gt; _physics = const BouncingScrollPhysics());<br>      } else {<br>        setState(() =&gt; _physics = const ClampingScrollPhysics());<br>      }<br>    });<br>  }</strong></pre><pre><strong>@override<br>  void dispose() {<br>    super.dispose();<br>    _controller.removeListener(() {});<br>  }</strong></pre><pre>@override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      backgroundColor: Colors.black,<br>      body: SingleChildScrollView(<br>        <strong>controller: _controller,</strong><br>        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),<br>      <strong>  physics: _physics,</strong><br>        child: Column(<br>          children: [<br>            DetailImage(id: widget.id!, image: widget.image!),<br>            DetailTitle(id: widget.id!, name: widget.name!),<br>            DetailData(id: widget.id!),<br>          ],<br>        ),<br>      ),<br>      floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,<br>      floatingActionButton: const DetailBackButton(),<br>    );<br>  }<br>}</pre><p>Congratulations! we achieved the behaviour we want. Now it’s time for some bug fixes.</p><p>If you have seen neatly, in the detail screen of the Pokemon, the card which shows the <strong>id </strong>and the <strong>name </strong>of Pokemon is buggy. For the <strong>id</strong> part, which is basically the the <strong>CircleAvatar</strong> widget passed to the <strong>Chip </strong>widget as an <strong>avatar </strong>attribute, is causing a problem when the id of Pokemon crosses the mark of 99. We have to fix this problem. Along with that we have to add the animation to the <strong>id</strong> too. So use the following code in <strong>detail_title.dart</strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailTitle extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  const DetailTitle({Key? key, required this.id, required this.name})<br>      : super(key: key);</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return <strong>Container(<br>      padding: const EdgeInsets.fromLTRB(11, 4, 11, 4),<br>      margin: const EdgeInsets.symmetric(vertical: 14),<br>      decoration: BoxDecoration(<br>        color: Colors.white24,<br>        borderRadius: BorderRadius.circular(51),<br>      ),<br>      child: Row(<br>        mainAxisAlignment: MainAxisAlignment.center,<br>        mainAxisSize: MainAxisSize.min,<br>        children: [<br>          Hero(<br>            tag: &quot;$id&quot;,<br>            child: Material(<br>              color: Colors.red[100],<br>              type: MaterialType.transparency,<br>              shape: const RoundedRectangleBorder(<br>                borderRadius: BorderRadius.all(<br>                  Radius.circular(21),<br>                ),<br>              ),<br>              child: Container(<br>                height: 40,<br>                width: 40,<br>                margin: const EdgeInsets.only(right: 7),<br>                decoration: BoxDecoration(<br>                  borderRadius: BorderRadius.circular(51),<br>                  color: Colors.red[100],<br>                ),<br>                child: Center(<br>                  child: Text(<br>                    id.toString(),<br>                    textAlign: TextAlign.center,<br>                    style: const TextStyle(<br>                      fontSize: 21,<br>                      fontWeight: FontWeight.w600,<br>                    ),<br>                  ),<br>                ),<br>              ),<br>            ),<br>          ),</strong><br>          Hero(<br>            tag: &quot;name-$id&quot;,<br>            child: Material(<br>              color: Colors.white,<br>              type: MaterialType.transparency,<br>              shape: const RoundedRectangleBorder(<br>                borderRadius: BorderRadius.all(<br>                  Radius.circular(21),<br>                ),<br>              ),<br>              child: Chip(<br>                <strong>labelPadding: const EdgeInsets.fromLTRB(14, 4, 14, 4),</strong><br>                backgroundColor: Colors.white,<br>                label: Text(<br>                  &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>                  overflow: TextOverflow.fade,<br>                  style: const TextStyle(<br>                    fontSize: 24,<br>                    color: Colors.black,<br>                  ),<br>                ),<br>              ),<br>            ),<br>          ),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>This code will solve the problem of the <strong>id</strong> but it will not animate it from the home screen to the details screen. We have to write the following code in the <strong>pokemon_card_background.dart </strong>file. This code is just adding <strong>Hero</strong> widget to the widget.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class PokemonCardBackground extends StatelessWidget {<br>  final int id;<br>  const PokemonCardBackground({Key? key, required this.id}) : super(key: key);</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return <strong>Hero(<br>      tag: &quot;$id&quot;,<br>      child: Material(<br>        color: Colors.white,<br>        type: MaterialType.transparency,<br>        shape: const RoundedRectangleBorder(<br>          borderRadius: BorderRadius.all(<br>            Radius.circular(21),<br>          ),<br>        ),<br>        child:</strong> Text(<br>          &quot;$id&quot;,<br>          style: TextStyle(<br>            fontSize: 101,<br>            fontWeight: FontWeight.bold,<br>            color: Colors.grey[200],<br>          ),<br>        ),<br>      ),<br>    <strong>);</strong><br>  }<br>}</pre><p>Now, we are animating the GridItems so that they will animate faster and look great. Use the following code in the <strong>pokemon_grid.dart </strong>file.</p><pre>import &#39;package:auto_animated/auto_animated.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_grid_items.dart&#39;;</pre><pre>class PokemonGrid extends StatefulWidget {<br>  final List&lt;Pokemon&gt; pokemon;<br>  const PokemonGrid({Key? key, required this.pokemon}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  _PokemonGridState createState() =&gt; _PokemonGridState();<br>}</pre><pre>class _PokemonGridState extends State&lt;PokemonGrid&gt; {<br>  <a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    final scrollController = ScrollController();<br>    final width = MediaQuery.of(context).size.width;<br>    final crossAxisCount = (width &gt; 1000)<br>        ? 5<br>        : (width &gt; 700)<br>            ? 4<br>            : (width &gt; 450)<br>                ? 3<br>                : 2;</pre><pre>return LiveSliverGrid(<br>      itemCount: 250,<br>      controller: scrollController,<br>      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(<br>        crossAxisCount: widget.pokemon.isEmpty ? 1 : crossAxisCount,<br>        crossAxisSpacing: 4,<br>        mainAxisSpacing: 4,<br>        childAspectRatio: 200 / 244,<br>      ),<br>      showItemInterval: const Duration(milliseconds: <strong>50</strong>),<br>      showItemDuration: const Duration(milliseconds: <strong>1000</strong>),<br>      visibleFraction: 0.001,<br>      itemBuilder: (context, index, animation) {<br>        return pokemonGridItem(context, index, animation, widget.pokemon);<br>      },<br>    );<br>  }<br>}</pre><p>From the <strong>pokemon_grid_items.dart</strong> file you must remove the <strong>SlideTransition</strong> widget. THe following code will help.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card.dart&#39;;</pre><pre>Widget pokemonGridItem(<br>  BuildContext context,<br>  int index,<br>  Animation&lt;double&gt; animation,<br>  List&lt;Pokemon&gt; pokemon,<br>) =&gt;<br>    FadeTransition(<br>      opacity: Tween&lt;double&gt;(<br>        begin: 0,<br>        end: 1,<br>      ).animate(animation),<br>      child: pokemon.isEmpty<br>          ? const Center(child: CircularProgressIndicator())<br>          : PokemonCard(<br>              id: pokemon.elementAt(index).id,<br>              name: pokemon.elementAt(index).name,<br>              image: pokemon.elementAt(index).img,<br>            ),<br>    );</pre><p>That’s it for this article, let’s hustle more in the next one! Till then, use the following code.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-6">GitHub - Om-Londhe/FlutterPokedex at part-6</a></p><h3>Happy New Year once again!</h3><h3>Thank you!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e62036d31b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SliverGrid animations in Flutter]]></title>
            <link>https://medium.com/@omlondhe/slivergrid-animations-in-flutter-99888776f8a7?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/99888776f8a7</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[slivergrid-animation]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 17:42:32 GMT</pubDate>
            <atom:updated>2021-12-31T17:42:32.103Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*WMnSBxzogFUYdFGRSRrX4g.jpeg" /></figure><p>Grid animations are easy to implement in Flutter, the SliverGrid animations are also somewhat similar, what’s tougher is to create our SliverGrid which animates its items when they are visible on the screen. For this purpose we are using a package called <strong>auto_animated</strong>. To install the package, just run the following command in the terminal from the root of your project.</p><pre>flutter pub add auto_animated</pre><p>After doing this, what you have to do is just create a new file inside the <strong>widgets </strong>folder called <strong>pokemon_grid_items.dart.</strong> This file will contain and export a widget called <strong>pokemonGridItem</strong> which takes <strong>BuildContext</strong>, <strong>index</strong>, <strong>animation</strong>, and list of <strong>Pokemon</strong> as a parameter and returns the <strong>PokemonCard</strong> widget wrapped in the <strong>FadeTransition </strong>and <strong>SlideTransition</strong> to show that effect when the item is visible on the screen. The code is given below.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card.dart&#39;;</pre><pre>Widget pokemonGridItem(<br>  BuildContext context,<br>  int index,<br>  Animation&lt;double&gt; animation,<br>  List&lt;Pokemon&gt; pokemon,<br>) =&gt;<br>    FadeTransition(<br>      opacity: Tween&lt;double&gt;(<br>        begin: 0,<br>        end: 1,<br>      ).animate(animation),<br>      child: SlideTransition(<br>        position: Tween&lt;Offset&gt;(<br>          begin: const Offset(0, 0.1),<br>          end: Offset.zero,<br>        ).animate(<br>          CurvedAnimation(<br>            parent: animation,<br>            curve: Curves.easeInOut,<br>          ),<br>        ),<br>        child: pokemon.isEmpty<br>            ? const CircularProgressIndicator()<br>            : PokemonCard(<br>                id: pokemon.elementAt(index).id,<br>                name: pokemon.elementAt(index).name,<br>                image: pokemon.elementAt(index).img,<br>              ),<br>      ),<br>    );</pre><p>Now you may be thinking that where we are gonna use this widget to make our SliverGrid animated. Let’s see that. Remember the <strong>auto_animated</strong> package we installed earlier, here it comes in handy. You just have to replace your <strong>SliverGrid.count</strong> from the file <strong>pokemon_grid.dart </strong>with the <strong>LiveSliverGrid </strong>provided by the <strong>auto_animated </strong>package. The code for that is given below.</p><pre><strong>import &#39;package:auto_animated/auto_animated.dart&#39;;</strong><br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br><strong>import &#39;package:pokedex/widgets/pokemon_grid_items.dart&#39;;</strong></pre><pre>class PokemonGrid extends StatefulWidget {<br>  final List&lt;Pokemon&gt; pokemon;<br>  const PokemonGrid({Key? key, required this.pokemon}) : super(key: key);</pre><pre>@override<br>  _PokemonGridState createState() =&gt; _PokemonGridState();<br>}</pre><pre>class _PokemonGridState extends State&lt;PokemonGrid&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    final scrollController = ScrollController();<br>    final width = MediaQuery.of(context).size.width;<br>    final crossAxisCount = (width &gt; 1000)<br>        ? 5<br>        : (width &gt; 700)<br>            ? 4<br>            : (width &gt; 450)<br>                ? 3<br>                : 2;</pre><pre>return <strong>LiveSliverGrid(<br>      itemCount: 250,<br>      controller: scrollController,<br>      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(<br>        crossAxisCount: widget.pokemon.isEmpty ? 1 : crossAxisCount,<br>        crossAxisSpacing: 4,<br>        mainAxisSpacing: 4,<br>        childAspectRatio: 200 / 244,<br>      ),<br>      showItemInterval: const Duration(milliseconds: 150),<br>      showItemDuration: const Duration(milliseconds: 750),<br>      visibleFraction: 0.001,<br>      itemBuilder: (context, index, animation) {<br>        return pokemonGridItem(context, index, animation, widget.pokemon);<br>      },<br>    );</strong><br>  }<br>}</pre><p>Now, our GridView is animated as expected. And, here we are done with the main screen of the app. We did all the things that we decided. But we are not gonna stop here, we are gonna continue to improve this application while learning more about other aspects of the Flutter framework, so stay tuned in 2022 too!</p><h4>Code</h4><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-5">GitHub - Om-Londhe/FlutterPokedex at part-5</a></p><h3><strong>Happy New Year!</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99888776f8a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fade image loading in Flutter using FadeInImage.]]></title>
            <link>https://medium.com/@omlondhe/fade-image-loading-in-flutter-using-fadeinimage-ab25f1193b54?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab25f1193b54</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-image]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Thu, 30 Dec 2021 00:28:53 GMT</pubDate>
            <atom:updated>2021-12-30T00:28:53.102Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous article, I told you that we are going to add the GridView animation to our Pokemon Grid of our Pokedex. Don’t know what it is? Just click the link below to see and follow along, else just go through this article to just learn this topic of loading images.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-4">GitHub - Om-Londhe/FlutterPokedex at part-4</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*_D3dF78b-CUimG2wPigFpg.png" /></figure><p>To get started with this type of image effect, you must install one package. Use the following command to install the package called <strong>transparent_image</strong>.</p><pre>flutter pub add transparent_image<br></pre><p>Now the package will be installed after running the above command in the terminal. This package lets us generate a transparent image from the memory to use it with the <strong>FadeInImage</strong> widget so that we can fade our images in when images are loaded.</p><p>Now you have to do changes in your <strong>pokemon_card_data.dart</strong> file to make use of <strong>kTransparentImage</strong> from this package and the <strong>FadeInImage widget</strong>. Use the following code which adds the <strong>kTransparentImage </strong>as a placeholder for the Pokemon images and then fades in the original image.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><strong>import &#39;package:transparent_image/transparent_image.dart&#39;;</strong></pre><pre>class PokemonCardData extends StatelessWidget {<br>  final int id;<br>  final String image;<br>  final String name;</pre><pre>const PokemonCardData({<br>    Key? key,<br>    required this.id,<br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Column(<br>      crossAxisAlignment: CrossAxisAlignment.stretch,<br>      children: [<br>        Expanded(<br>          child: Padding(<br>            padding: const EdgeInsets.all(11),<br>            child: Hero(<br>              tag: &quot;image-$id&quot;,<br>              child: <strong>FadeInImage.memoryNetwork(<br>                placeholder: kTransparentImage,<br>                image: image,<br>                fadeInCurve: Curves.easeInOut,</strong><br>                fit: BoxFit.contain,<br>                alignment: Alignment.bottomRight,<br>              ),<br>            ),<br>          ),<br>        ),<br>        const Divider(),<br>        Hero(<br>          tag: &quot;name-$id&quot;,<br>          child: Material(<br>            color: Colors.white,<br>            shape: const RoundedRectangleBorder(<br>              borderRadius: BorderRadius.all(<br>                Radius.circular(21),<br>              ),<br>            ),<br>            child: Center(<br>              child: Text(<br>                &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>                textAlign: TextAlign.center,<br>                style: const TextStyle(<br>                  fontSize: 21,<br>                  color: Colors.black87,<br>                ),<br>              ),<br>            ),<br>          ),<br>        ),<br>      ],<br>    );<br>  }<br>}</pre><p>Let’s do the same changes in the <strong>detail_image.dart</strong> file too.</p><pre>import &#39;package:flutter/material.dart&#39;;<strong><br>import &#39;package:transparent_image/transparent_image.dart&#39;;</strong></pre><pre>class DetailImage extends StatelessWidget {<br>  final int id;<br>  final String image;</pre><pre>const DetailImage({<br>    Key? key,<br>    required this.image,<br>    required this.id,<br>  }) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Container(<br>      constraints: const BoxConstraints(<br>        maxHeight: 500,<br>      ),<br>      color: Colors.black,<br>      child: Center(<br>        child: Stack(<br>          children: [<br>            Container(<br>              height: 500,<br>              width: 500,<br>              decoration: const BoxDecoration(<br>                color: Colors.white10,<br>                shape: BoxShape.circle,<br>              ),<br>            ),<br>            Hero(<br>              tag: &quot;image-$id&quot;,<br>              child: <strong>FadeInImage.memoryNetwork(<br>                placeholder: kTransparentImage,<br>                image: image,<br>                fadeInCurve: Curves.easeInOut,</strong><br>                fit: BoxFit.contain,<br>                alignment: Alignment.center,<br>              <strong>),</strong><br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Now we are done with this new kind of animation. We are ready to add new animations and data now. See you in the next one. Until then you can access the code here.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-5">GitHub - Om-Londhe/FlutterPokedex at part-5</a></p><h3>Thank you and Happy New Year!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab25f1193b54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Splash screen using Flutter Animations in Flutter Pokedex]]></title>
            <link>https://medium.com/@omlondhe/creating-splash-screen-using-flutter-animations-in-flutter-pokedex-f57c29e9ea18?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/f57c29e9ea18</guid>
            <category><![CDATA[flutter-animation]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 08:57:12 GMT</pubDate>
            <atom:updated>2021-12-29T08:57:12.346Z</atom:updated>
            <content:encoded><![CDATA[<p>First of all, if you are not following along, you can click the link below to follow along. Just clone the repository and follow along if you want, else, just learn how you can add <strong>Splash screen</strong> and try in your own app.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-3">GitHub - Om-Londhe/FlutterPokedex at part-3</a></p><p>As you know, I have already posted an article which states that how we can add a Splash screen to our application. You can learn it by clicking the link given below.</p><p><a href="https://medium.com/@omlondhe/splash-screen-in-flutter-2eafd40ba99b">Splash screen in Flutter</a></p><p>But, here we are not following this. We are going to create our own Splash screen code using <strong>Flutter Navigation</strong> just for learning how we can achieve this on our own.</p><p>For this purpose, what you have to do is just create a new file called a <strong>splash.dart</strong> inside the <strong>screens</strong> folder. We are using an image for this splash screen, you can download that image, which is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*uhl8O3bpsG-e2CKJXpfnVg.png" /></figure><p>The first change that we are going to make in our application is in the <strong>main.dart</strong> file. In this file, we just have to target our new file <strong>splash.dart</strong> as the initial route and add it to routes. So, let’s do that first.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/screens/details.dart&#39;;<br>import &#39;package:pokedex/screens/home.dart&#39;;<br><strong>import &#39;package:pokedex/screens/splash.dart&#39;;</strong></pre><pre>void main() {<br>  runApp(const App());<br>}</pre><pre>class App extends StatelessWidget {<br>  const App({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Pokedex&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.red,<br>      ),<br>      initialRoute: &quot;/&quot;,<br>      routes: {<br>        <strong>&quot;/&quot;: (context) =&gt; const SplashScreen(),<br>        &quot;/home&quot;</strong>: <strong>(context) =&gt; const Home(),</strong><br>        &quot;/details&quot;: (context) =&gt; const Details(),<br>      },<br>    );<br>  }<br>}</pre><p>Now, let’s populate our image in the <strong>splash.dart</strong> file by using the following code which is just wrapping our image in the <strong>Center </strong>widget wrapped by a <strong>Scaffold</strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class SplashScreen extends StatefulWidget {<br>  const SplashScreen({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  _SplashScreenState createState() =&gt; _SplashScreenState();<br>}</pre><pre>class _SplashScreenState extends State&lt;SplashScreen&gt; {<br>  <a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      body: Center(<br>        child: Image.asset(&#39;assets/images/splash_icon.png&#39;),<br>      ),<br>    );<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*AswnSBklONA4GdglwXvqHA.jpeg" /></figure><p>But, this doesn’t look good. We have to add some animations to this screen so that it feels amazing while opening this application. So, let’s add the animations.</p><p>Following code is making use of the in-built <strong>transition widgets</strong> along with the animation values which are driven by using <strong>Tweens </strong>and <strong>CurvedAnimation</strong>s. We have declared <strong>AnimationController</strong> for all three types of animations namely <strong>slide, fade,</strong> and <strong>scale</strong>. These animations are implemented using <strong>SlideTransition, FadeTransition, ScaleTransition</strong> respectively. Let me give you the whole code first and then I will talk about each section.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/screens/home.dart&#39;;</pre><pre>class SplashScreen extends StatefulWidget {<br>  const SplashScreen({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  _SplashScreenState createState() =&gt; _SplashScreenState();<br>}</pre><pre>class _SplashScreenState extends State&lt;SplashScreen&gt;<br>    <strong>with TickerProviderStateMixin</strong> {<br>  <strong>late final _slideAnimationController = AnimationController(<br>    vsync: this,<br>    duration: const Duration(seconds: 1),<br>  );<br>  late final Animation&lt;Offset&gt; _slideAnimation =<br>      Tween&lt;Offset&gt;(begin: const Offset(0, -4), end: const Offset(0, 0))<br>          .animate(<br>    CurvedAnimation(<br>      parent: _slideAnimationController,<br>      curve: Curves.elasticInOut,<br>    ),<br>  );<br>  late final _fadeAnimationController = AnimationController(<br>    vsync: this,<br>    duration: const Duration(seconds: 1),<br>  );<br>  late final Animation&lt;double&gt; _fadeAnimation = CurvedAnimation(<br>    parent: _fadeAnimationController,<br>    curve: Curves.easeInOut,<br>  );<br>  late final _scaleAnimationController = AnimationController(<br>    vsync: this,<br>    duration: const Duration(milliseconds: 1500),<br>    reverseDuration: const Duration(milliseconds: 444),<br>  );<br>  late final Animation&lt;double&gt; _scaleAnimation =<br>      Tween&lt;double&gt;(begin: 0.4, end: 4).animate(<br>    CurvedAnimation(<br>      parent: _scaleAnimationController,<br>      curve: Curves.elasticInOut,<br>    ),<br>  );</strong></pre><pre><strong>  @override<br>  void initState() {<br>    super.initState();<br>    _slideAnimationController.forward();<br>    _fadeAnimationController.forward();<br>    Future.delayed(const Duration(milliseconds: 1721)).then((value) {<br>      _fadeAnimationController.reverse();<br>      _scaleAnimationController.forward();<br>    });<br>    Future.delayed(const Duration(seconds: 2)).then(<br>      (value) =&gt; Navigator.pushReplacement(<br>        context,<br>        PageRouteBuilder(<br>          pageBuilder: (context, animation, secondaryAnimation) =&gt; const Home(),<br>          transitionsBuilder: (context, animation, secondaryAnimation, child) {<br>            return FadeTransition(<br>              opacity: animation.drive(Tween(begin: 0, end: 1)),<br>              child: child,<br>            );<br>          },<br>          transitionDuration: const Duration(milliseconds: 571),<br>          reverseTransitionDuration: const Duration(milliseconds: 571),<br>        ),<br>      ),<br>    );<br>  }</strong></pre><pre>  <strong>@override<br>  void dispose() {<br>    _slideAnimationController.dispose();<br>    _fadeAnimationController.dispose();<br>    _scaleAnimationController.dispose();<br>    super.dispose();<br>  }</strong></pre><pre> @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      <strong>backgroundColor: Colors.black,<br>      body: Center(<br>        child: ScaleTransition(<br>          scale: _scaleAnimation,<br>          child: FadeTransition(<br>            opacity: _fadeAnimation,<br>            child: SlideTransition(<br>              position: _slideAnimation,<br>              child: Hero(<br>                tag: &quot;splash&quot;,<br>                child:</strong> Image.asset(&#39;assets/images/splash_icon.png&#39;),<br>              <strong>),<br>            ),<br>          ),<br>        ),<br>      ),</strong><br>    );<br>  }<br>}</pre><p>At the top of the file, there’s a line that is allowing our class to be the <strong>TickerProvider</strong>. This allows us to tell the <strong>AnimationController </strong>that you have to use this class only as its <strong>vsync</strong> attribute.</p><pre>.....<br>class _SplashScreenState extends State&lt;SplashScreen&gt;<br>    <strong>with TickerProviderStateMixin </strong>{<br><strong>......</strong></pre><p>The following code initializes the <strong>AnimationController</strong>s and <strong>Animation </strong>variables. Here we are nothing but setting <strong>this </strong>for the <strong>vsync</strong> attribute of <strong>AnimationController</strong>s<strong> </strong>and the duration that we want animations to run. And the animations are also specified with <strong>CurvedAnimation</strong>. Every variable is <strong>late</strong> initialized as the <strong>TickerProviderStateMixin </strong>with <strong>this </strong>reference is not available without making variables to initialize <strong>late</strong>. In layman&#39;s language, you can say that these variables only get initialized when you start using them in the code.</p><pre><strong>...<br></strong>late final _slideAnimationController = AnimationController(<br>    vsync: this,<br>    duration: const Duration(seconds: 1),<br>  );<br>  late final Animation&lt;Offset&gt; _slideAnimation =<br>      Tween&lt;Offset&gt;(begin: const Offset(0, -4), end: const Offset(0, 0))<br>          .animate(<br>    CurvedAnimation(<br>      parent: _slideAnimationController,<br>      curve: Curves.elasticInOut,<br>    ),<br>  );<br>  late final _fadeAnimationController = AnimationController(<br>    vsync: this,<br>    duration: const Duration(seconds: 1),<br>  );<br>  late final Animation&lt;double&gt; _fadeAnimation = CurvedAnimation(<br>    parent: _fadeAnimationController,<br>    curve: Curves.easeInOut,<br>  );<br>  late final _scaleAnimationController = AnimationController(<br>    vsync: this,<br>    duration: const Duration(milliseconds: 1500),<br>    reverseDuration: const Duration(milliseconds: 444),<br>  );<br>  late final Animation&lt;double&gt; _scaleAnimation =<br>      Tween&lt;double&gt;(begin: 0.4, end: 4).animate(<br>    CurvedAnimation(<br>      parent: _scaleAnimationController,<br>      curve: Curves.elasticInOut,<br>    ),<br>  );<br>....</pre><p>The following code is a life-cycle function that is starting our animations, running them sequentially in a fixed order, and navigating to the home screen when all the animations are done. Here, the <strong>Future.delayed</strong> function is used to make the part of code wait till a specified time.</p><pre>@override<br>  void initState() {<br>    super.initState();<br>    _slideAnimationController.forward();<br>    _fadeAnimationController.forward();<br>    Future.delayed(const Duration(milliseconds: 1721)).then((value) {<br>      _fadeAnimationController.reverse();<br>      _scaleAnimationController.forward();<br>    });<br>    Future.delayed(const Duration(seconds: 2)).then(<br>      (value) =&gt; Navigator.pushReplacement(<br>        context,<br>        PageRouteBuilder(<br>          pageBuilder: (context, animation, secondaryAnimation) =&gt; const Home(),<br>          transitionsBuilder: (context, animation, secondaryAnimation, child) {<br>            return FadeTransition(<br>              opacity: animation.drive(Tween(begin: 0, end: 1)),<br>              child: child,<br>            );<br>          },<br>          transitionDuration: const Duration(milliseconds: 571),<br>          reverseTransitionDuration: const Duration(milliseconds: 571),<br>        ),<br>      ),<br>    );<br>  }</pre><p>Following code is also a life cycle method that is disposing of all the animation variables when the widget is unmounted from the tree.</p><pre>@override<br>  void dispose() {<br>    _slideAnimationController.dispose();<br>    _fadeAnimationController.dispose();<br>    _scaleAnimationController.dispose();<br>    super.dispose();<br>  }</pre><p>The rest of the code is just nesting of widgets which does the corresponding work as their name suggests. So don&#39;t with adding splash screen. In the next article, we will add animations to the GridView items.</p><h3>Thank you and Happy New Year!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f57c29e9ea18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Slivers in Flutter Pokedex]]></title>
            <link>https://medium.com/@omlondhe/adding-slivers-in-flutter-pokedex-587c80a25aab?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/587c80a25aab</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 06:09:51 GMT</pubDate>
            <atom:updated>2021-12-27T06:09:51.137Z</atom:updated>
            <content:encoded><![CDATA[<p>First of all, <strong>Happy New Year</strong> to you. <br>Yesterday, we saw that how we can add the <strong>Hero Animations </strong>to the Pokedex, and the app is rocking now. But we must change the <strong>AppBar </strong>of our app to make our Home screen look good. So for this purpose, as discussed earlier, we are adding <strong>SliverAppBar </strong>and <strong>SliverGridView</strong>to our app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2fYtdnyjPMTwOtpC1c_mg.png" /></figure><p>The <strong>SliverAppBar</strong> will create an expandable app bar that will contain an image that will give a great effect. We have to make our app such that it will access the local image. Let’s make changes in our app considering this scenario.</p><p>First of all, you have to create a folder called <strong>assets </strong>in your root directory that will contain a folder called <strong>images</strong> containing all our images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*6qiMuIc8hSpKO5hgdZNc5A.png" /></figure><p>Then you have to head over to <strong>pubspec.yaml </strong>file and make the changes. The expected lines are bold in font style.</p><pre><em>name: pokedex<br>description: A new Flutter project.</em></pre><pre><em># The following line prevents the package from being accidentally published to<br># pub.dev using `flutter pub publish`. This is preferred for private packages.<br>publish_to: &#39;none&#39; # Remove this line if you wish to publish to pub.dev</em></pre><pre><em># The following defines the version and build number for your application.<br># A version number is three numbers separated by dots, like 1.2.43<br># followed by an optional build number separated by a +.<br># Both the version and the builder number may be overridden in flutter<br># build by specifying --build-name and --build-number, respectively.<br># In Android, build-name is used as versionName while build-number used as versionCode.<br># Read more about Android versioning at </em><a href="https://developer.android.com/studio/publish/versioning"><em>https://developer.android.com/studio/publish/versioning</em></a><em><br># In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.<br># Read more about iOS versioning at<br># </em><a href="https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html"><em>https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html</em></a><em><br>version: 1.0.0+1</em></pre><pre><em>environment:<br>  sdk: &quot;&gt;=2.12.0 &lt;3.0.0&quot;</em></pre><pre><em># Dependencies specify other packages that your package needs in order to work.<br># To automatically upgrade your package dependencies to the latest versions<br># consider running `flutter pub upgrade --major-versions`. Alternatively,<br># dependencies can be manually updated by changing the version numbers below to<br># the latest version available on pub.dev. To see which dependencies have newer<br># versions available, run `flutter pub outdated`.<br>dependencies:<br>  flutter:<br>    sdk: flutter</em></pre><pre><em># The following adds the Cupertino Icons font to your application.<br>  # Use with the CupertinoIcons class for iOS style icons.<br>  cupertino_icons: ^1.0.2<br>  http: ^0.13.4</em></pre><pre><em>dev_dependencies:<br>  flutter_test:<br>    sdk: flutter</em></pre><pre><em># The &quot;flutter_lints&quot; package below contains a set of recommended lints to<br>  # encourage good coding practices. The lint set provided by the package is<br>  # activated in the `analysis_options.yaml` file located at the root of your<br>  # package. See that file for information about deactivating specific lint<br>  # rules and activating additional ones.<br>  flutter_lints: ^1.0.0</em></pre><pre><em># For information on the generic Dart part of this file, see the<br># following page: </em><a href="https://dart.dev/tools/pub/pubspec"><em>https://dart.dev/tools/pub/pubspec</em></a></pre><pre><em># The following section is specific to Flutter.<br>flutter:</em></pre><pre><em># The following line ensures that the Material Icons font is<br>  # included with your application, so that you can use the icons in<br>  # the material Icons class.<br>  uses-material-design: true</em></pre><pre><em># To add assets to your application, add an assets section, like this:</em><br>  <strong>assets:<br>    - assets/images/</strong></pre><pre><em># An image asset can refer to one or more resolution-specific &quot;variants&quot;, see<br>  # </em><a href="https://flutter.dev/assets-and-images/#resolution-aware"><em>https://flutter.dev/assets-and-images/#resolution-aware</em></a><em>.</em></pre><pre><em># For details regarding adding assets from package dependencies, see<br>  # </em><a href="https://flutter.dev/assets-and-images/#from-packages"><em>https://flutter.dev/assets-and-images/#from-packages</em></a></pre><pre><em># To add custom fonts to your application, add a fonts section here,<br>  # in this &quot;flutter&quot; section. Each entry in this list should have a<br>  # &quot;family&quot; key with the font family name, and a &quot;fonts&quot; key with a<br>  # list giving the asset and other descriptors for the font. For<br>  # example:<br>  # fonts:<br>  #   - family: Schyler<br>  #     fonts:<br>  #       - asset: fonts/Schyler-Regular.ttf<br>  #       - asset: fonts/Schyler-Italic.ttf<br>  #         style: italic<br>  #   - family: Trajan Pro<br>  #     fonts:<br>  #       - asset: fonts/TrajanPro.ttf<br>  #       - asset: fonts/TrajanPro_Bold.ttf<br>  #         weight: 700<br>  #<br>  # For details regarding fonts from package dependencies,<br>  # see </em><a href="https://flutter.dev/custom-fonts/#from-packages"><em>https://flutter.dev/custom-fonts/#from-packages</em></a></pre><p>Just copy and paste the following code in your <strong>home.dart</strong> file to create a <strong>SliverAppBar</strong>. After that, we will change the <strong>pokemon_grid.dart</strong> file.</p><pre>import &#39;dart:convert&#39;;</pre><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/api/pokeapi.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<strong><br>import &#39;package:pokedex/widgets/home_app_bar.dart&#39;;</strong><br>import &#39;package:pokedex/widgets/pokemon_grid.dart&#39;;</pre><pre>class Home extends StatefulWidget {<br>  const Home({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  State&lt;Home&gt; createState() =&gt; _HomeState();<br>}</pre><pre>class _HomeState extends State&lt;Home&gt; {<br>  List&lt;Pokemon&gt; pokemon = List.empty();</pre><pre><a href="http://twitter.com/override">@override</a><br>  void initState() {<br>    super.initState();<br>    getPokemonFromPokeApi();<br>  }</pre><pre>void getPokemonFromPokeApi() async {<br>    PokeAPI.getPokemon().then((response) {<br>      List&lt;Map&lt;String, dynamic&gt;&gt; data =<br>          List.from(json.decode(response.body)[&#39;results&#39;]);<br>      setState(() {<br>        pokemon = data.asMap().entries.map&lt;Pokemon&gt;((element) {<br>          element.value[&#39;id&#39;] = element.key + 1;<br>          element.value[&#39;img&#39;] =<br>              &quot;<a href="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/$%7Belement.key">https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/${element.key</a> + 1}.png&quot;;<br>          return Pokemon.fromJson(element.value);<br>        }).toList();<br>      });<br>    });<br>  }</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      backgroundColor: Colors.white,<br>      body: <strong>CustomScrollView(<br>        physics: const BouncingScrollPhysics(),<br>        slivers: [</strong><br>          <strong>const HomeAppBar(),</strong><br>          <strong>const SliverPadding(padding: EdgeInsets.all(4)),</strong><br>          PokemonGrid(pokemon: pokemon)<br>        <strong>],<br>      ),</strong><br>      floatingActionButton: FloatingActionButton(<br>        heroTag: &quot;fab&quot;,<br>        onPressed: () {},<br>        tooltip: &#39;Share&#39;,<br>        child: const Icon(<br>          Icons.share_rounded,<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>We need to create a file called <strong>home_app_bar.dart </strong>in the <strong>widgets</strong> folder so that we can return the <strong>SliverAppBar</strong> from it. Copy and paste the following code in that file.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class HomeAppBar extends StatelessWidget {<br>  const HomeAppBar({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return SliverAppBar(<br>      pinned: true,<br>      stretch: true,<br>      centerTitle: true,<br>      expandedHeight: 251,<br>      title: const Text(<br>        &quot;Pokedex&quot;,<br>        style: TextStyle(fontSize: 24),<br>      ),<br>      flexibleSpace: FlexibleSpaceBar(<br>        background: Image.asset(<br>          &quot;assets/images/logo.jpg&quot;,<br>          fit: BoxFit.cover,<br>        ),<br>        collapseMode: CollapseMode.parallax,<br>        stretchModes: const [<br>          StretchMode.fadeTitle,<br>          StretchMode.zoomBackground,<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>As we all know, the sliver parent cannot contain other widgets, so we need to change our <strong>PokemonGrid </strong>to the <strong>SliverGrid</strong>, let’s do this using the following code in <strong>pokemon_grid.dart</strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card.dart&#39;;</pre><pre>class PokemonGrid extends StatefulWidget {<br>  final List&lt;Pokemon&gt; pokemon;<br>  const PokemonGrid({Key? key, required this.pokemon}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  _PokemonGridState createState() =&gt; _PokemonGridState();<br>}</pre><pre>class _PokemonGridState extends State&lt;PokemonGrid&gt; {<br>  <a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    final width = MediaQuery.of(context).size.width;<br>    final crossAxisCount = (width &gt; 1000)<br>        ? 5<br>        : (width &gt; 700)<br>            ? 4<br>            : (width &gt; 450)<br>                ? 3<br>                : 2;</pre><pre>return <strong>SliverGrid.count(</strong><br>      crossAxisCount: crossAxisCount,<br>      crossAxisSpacing: 4,<br>      mainAxisSpacing: 4,<br>      childAspectRatio: 200 / 244,<br>      children: widget.pokemon<br>          .map(<br>            (pokemon) =&gt; PokemonCard(<br>              id: pokemon.id,<br>              name: pokemon.name,<br>              image: pokemon.img,<br>            ),<br>          )<br>          .toList(),<br>    <strong>);</strong><br>  }<br>}</pre><p>Oh yeah, we are done with adding Slivers. In the next article, we will create a Splash/Start Screen of the app. Click the link below to access the code written in this article.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex/tree/part-3">GitHub - Om-Londhe/FlutterPokedex at part-3</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*fvOgaVglLhNKtRQczfbf3Q.jpeg" /></figure><h3>Thank you 🙏 !</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=587c80a25aab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding AppBar animation & Hero animations to Pokedex App]]></title>
            <link>https://medium.com/@omlondhe/adding-appbar-animation-hero-animations-to-pokedex-app-e9e57c8cf8b6?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9e57c8cf8b6</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Sun, 26 Dec 2021 16:17:49 GMT</pubDate>
            <atom:updated>2021-12-26T16:17:49.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urOEC6S8HyeLGemidB0mGQ.png" /></figure><p>First of all, wish you a Merry Christmas and a Happy New Year. After my week-long break from Medium, yesterday, we built an amazing basic application. Hope you followed it along, and if not, then what you are doing man, just click the link below and get your app created in 10–15 minutes 😶‍🌫️.</p><p><a href="https://medium.com/@omlondhe/creating-a-flutter-pokedex-23c167cae043">Creating a Flutter Pokedex</a></p><p>At the end of the article, yesterday, I said that this app still looks incomplete. It is not packed with fabulous animations and animations are what create a great user experience. And also the data on the details page is not sufficient. So, we have to add more data afterward. This article is dedicated to adding <strong>Hero animations</strong> and <strong>AppBar animations</strong> only. This will help in making our user interface look more eye-catching. Let’s first start with the <strong>Hero animations</strong>.</p><h3>Adding Hero Animations</h3><p>If you don’t know anything about this type of animations then click the link to know about it.</p><p><a href="https://medium.com/@omlondhe/hero-animation-in-flutter-61eee2651df3">Hero Animation in Flutter</a></p><h4>Why Hero animations?</h4><p>Hero animations are great when we have the same content on two screens. In our application, we are showing the <strong>id</strong>, <strong>name</strong>, and <strong>image</strong> of the Pokemon on the home screen, these same widgets are visible on the details screen too but they are arranged in a different layout. It would be great if users can see how these widgets are traveling across screens to change their positions on the next screen, which is called the details screen in our case.</p><h4>Hero animations in action</h4><p>First of all, we have to go to the <strong>details.dart </strong>file to change the UI of the <strong>Details</strong> screen. Replace the code in that file with the following code.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailData extends StatelessWidget {<br>  final int id;<br>  const DetailData({Key? key, required this.id}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Container(<br>      constraints: BoxConstraints(<br>        minWidth: MediaQuery.of(context).size.width,<br>        minHeight: 500,<br>      ),<br>      decoration: const BoxDecoration(<br>        color: Colors.white,<br>        borderRadius: BorderRadius.only(<br>          topLeft: Radius.circular(51),<br>          topRight: Radius.circular(51),<br>        ),<br>      ),<br>      child: Column(<br>        children: const [Text(&quot;To be continued....&quot;)],<br>      ),<br>    );<br>  }<br>}</pre><p>Let’s add <strong>Hero animation </strong>to our floating action buttons. This will transition our S<strong>hare button</strong> from the <strong>Home</strong> screen to the <strong>Back button</strong> of the <strong>Details</strong> screen. Just you have to add the bold lines from the snippet below.</p><p>Changes to do in <strong><em>home.dart</em></strong></p><pre>import &#39;dart:convert&#39;;</pre><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/api/pokeapi.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_grid.dart&#39;;</pre><pre>class Home extends StatefulWidget {<br>  const Home({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  State&lt;Home&gt; createState() =&gt; _HomeState();<br>}</pre><pre>class _HomeState extends State&lt;Home&gt; {<br>  List&lt;Pokemon&gt; pokemon = List.empty();</pre><pre><a href="http://twitter.com/override">@override</a><br>  void initState() {<br>    super.initState();<br>    getPokemonFromPokeApi();<br>  }</pre><pre>void getPokemonFromPokeApi() async {<br>    PokeAPI.getPokemon().then((response) {<br>      List&lt;Map&lt;String, dynamic&gt;&gt; data =<br>          List.from(json.decode(response.body)[&#39;results&#39;]);<br>      setState(() {<br>        pokemon = data.asMap().entries.map&lt;Pokemon&gt;((element) {<br>          element.value[&#39;id&#39;] = element.key + 1;<br>          element.value[&#39;img&#39;] =<br>              &quot;<a href="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/$%7Belement.key">https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/${element.key</a> + 1}.png&quot;;<br>          return Pokemon.fromJson(element.value);<br>        }).toList();<br>      });<br>    });<br>  }</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: const Text(&quot;Pokedex&quot;),<br>      ),<br>      body: PokemonGrid(pokemon: pokemon),<br>      floatingActionButton: FloatingActionButton(<br>        <strong>heroTag: &quot;fab&quot;,</strong><br>        onPressed: () {},<br>        tooltip: &#39;Share&#39;,<br>        child: const Icon(<br>          Icons.share_rounded,<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Changes to do in <strong><em>detail_back_button.dart</em></strong></p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailBackButton extends StatelessWidget {<br>  const DetailBackButton({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return FloatingActionButton.extended(<br>      <strong>heroTag: &quot;fab&quot;,</strong><br>      onPressed: () =&gt; Navigator.pop(context),<br>      tooltip: &#39;Share&#39;,<br>      label: const Text(<br>        &quot;Back&quot;,<br>      ),<br>      icon: const Icon(Icons.arrow_back_ios_new_rounded),<br>    );<br>  }<br>}</pre><p>As you can see, the <strong>FloatingActionButton</strong> widget has an attribute called <strong>heroTag</strong> which allows us to create <strong>Hero</strong> animation.</p><p>Now, we are going to add the same animation to the <strong>image</strong>, <strong>name, </strong>and <strong>id</strong>. The procedural is different than what we used for floating action buttons. For this case we have to use a widget called <strong>Hero </strong>widget. The code is given below.</p><p>Paste the following code in the <strong>pokemon_card.dart</strong> file. Here we just passed <strong>id </strong>to the <strong>PokemonCardData </strong>widget.<strong> </strong>The new code is bold in style.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/pokemon_screen_data.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_background.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_data.dart&#39;;</pre><pre>class PokemonCard extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  final String image;</pre><pre>const PokemonCard({<br>    Key? key,<br>    required this.id,<br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre>BoxDecoration getContainerDecoration() =&gt; BoxDecoration(<br>        borderRadius: BorderRadius.circular(24),<br>        border: Border.all(<br>          color: Colors.grey.withOpacity(0.24),<br>          width: 1,<br>        ),<br>      );</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Material(<br>      color: Colors.white,<br>      borderRadius: BorderRadius.circular(24),<br>      child: InkWell(<br>        borderRadius: BorderRadius.circular(24),<br>        enableFeedback: true,<br>        splashColor: Colors.red[50],<br>        onTap: () =&gt; {<br>          Navigator.pushNamed(<br>            context,<br>            &quot;/details&quot;,<br>            arguments: PokemonScreenData(id, name, image),<br>          )<br>        },<br>        child: Container(<br>          padding: const EdgeInsets.all(7),<br>          decoration: getContainerDecoration(),<br>          child: Stack(<br>            children: [<br>              PokemonCardBackground(id: id),<br>              PokemonCardData(<strong>id: id, </strong>name: name, image: image),<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Paste the following code in the <strong>pokemon_card_data.dart</strong> file. Here, we are accepting the <strong>id </strong>as a required parameter from <strong>PokemonCard </strong>widget and added some <strong>Hero widgets </strong>with <strong>tags</strong>.<strong> </strong>The new code is bold in style.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class PokemonCardData extends StatelessWidget {<br>  <strong>final int id;</strong><br>  final String image;<br>  final String name;</pre><pre>const PokemonCardData({<br>    Key? key,<br>    <strong>required this.id,</strong><br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre>@override<br>  Widget build(BuildContext context) {<br>    return Column(<br>      children: [<br>        Expanded(<br>          child: Padding(<br>            padding: const EdgeInsets.all(11),<br>            child: <strong>Hero(<br>              tag: &quot;image-$id&quot;,</strong><br>              child: Image.network(<br>                image,<br>                fit: BoxFit.contain,<br>                alignment: Alignment.bottomRight,<br>              ),<br>            <strong>),</strong><br>          ),<br>        ),<br>        const Divider(),<br>        <strong>Hero(<br>          tag: &quot;name-$id&quot;,</strong><br>          <strong>child: Material(<br>            color: Colors.white,<br>            shape: const RoundedRectangleBorder(<br>              borderRadius: BorderRadius.all(<br>                Radius.circular(21),<br>              ),<br>            ),</strong><br>            <strong>child:</strong> Text(<br>              &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>              style: const TextStyle(<br>                fontSize: 21,<br>                color: Colors.black87,<br>              ),<br>            ),<br>          <strong>),</strong><br>        <strong>),</strong><br>      ],<br>    );<br>  }<br>}</pre><p>Our code for animations for the home screen is done, now it’s time to make our hands dirty on animations for details page. Paste the following code in the <strong>detail_image.dart </strong>file. This widget is changed to accept the <strong>id</strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailImage extends StatelessWidget {<br>  <strong>final int id;</strong><br>  final String image;</pre><pre>const DetailImage({<br>    Key? key,<br>    required this.image,<br>    required this.id,<br>  }) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Container(<br>      constraints: const BoxConstraints(<br>        maxHeight: 500,<br>      ),<br>      color: Colors.black,<br>      child: Center(<br>        child: Stack(<br>          children: [<br>            Container(<br>              height: 500,<br>              width: 500,<br>              decoration: const BoxDecoration(<br>                color: Colors.white10,<br>                shape: BoxShape.circle,<br>              ),<br>            ),<br>            <strong>Hero(<br>              tag: &quot;image-$id&quot;,<br>              child:</strong> Image.network(<br>                image,<br>                fit: BoxFit.contain,<br>                alignment: Alignment.center,<br>              ),<br>            <strong>),</strong><br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Paste the following code in the <strong>detail_title.dart</strong> file.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailTitle extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  const DetailTitle({Key? key, required this.id, required this.name})<br>      : super(key: key);</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return <strong>Hero(<br>      tag: &quot;name-$id&quot;,<br>      child: Material(<br>        color: Colors.white,<br>        type: MaterialType.transparency,<br>        shape: const RoundedRectangleBorder(<br>          borderRadius: BorderRadius.all(<br>            Radius.circular(21),<br>          ),<br>        ),<br>        child:</strong> Chip(<br>          backgroundColor: Colors.white,<br>          label: Text(<br>            &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>            overflow: TextOverflow.fade,<br>            style: const TextStyle(<br>              fontSize: 24,<br>              color: Colors.black,<br>            ),<br>          ),<br>          avatar: CircleAvatar(<br>            child: Text(<br>              id.toString(),<br>            ),<br>          ),<br>        ),<br>      ),<br>    <strong>);</strong><br>  }<br>}</pre><p>Oh yeah,our animations are done! But don’t you thing these animations are so fast? Let’s make them slow by using <strong>PageRouteBuilder</strong>. Let’s do that by using the following code in the file <strong>pokemon_card.dart</strong>. But before that, we should delete the file <strong>pokemon_screen_data.dart</strong> as it is not necessary.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/screens/details.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_background.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_data.dart&#39;;</pre><pre>class PokemonCard extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  final String image;</pre><pre>const PokemonCard({<br>    Key? key,<br>    required this.id,<br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre><strong>void navigate(BuildContext context) {<br>    Navigator.push(<br>      context,<br>      PageRouteBuilder(<br>        pageBuilder: (context, animation, secondaryAnimation) =&gt; Details(<br>          id: id,<br>          name: name,<br>          image: image,<br>        ),<br>        transitionsBuilder: (context, animation, secondaryAnimation, child) {<br>          return FadeTransition(<br>            opacity: animation.drive(Tween(begin: 0, end: 1)),<br>            child: child,<br>          );<br>        },<br>        transitionDuration: const Duration(milliseconds: 521),<br>        reverseTransitionDuration: const Duration(milliseconds: 444),<br>      ),<br>    );<br>  }</strong></pre><pre>BoxDecoration getContainerDecoration() =&gt; BoxDecoration(<br>        borderRadius: BorderRadius.circular(24),<br>        border: Border.all(<br>          color: Colors.grey.withOpacity(0.24),<br>          width: 1,<br>        ),<br>      );</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return Material(<br>      color: Colors.white,<br>      borderRadius: BorderRadius.circular(24),<br>      child: InkWell(<br>        borderRadius: BorderRadius.circular(24),<br>        enableFeedback: true,<br>        splashColor: Colors.red[50],<br>        onTap: <strong>() =&gt; navigate(context)</strong>,<br>        child: Container(<br>          padding: const EdgeInsets.all(7),<br>          decoration: getContainerDecoration(),<br>          child: Stack(<br>            children: [<br>              PokemonCardBackground(id: id),<br>              PokemonCardData(id: id, name: name, image: image),<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Now changing the <strong>details.dart</strong> file with the following code will help us to achieve what we want.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_back_button.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_data.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_image.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_title.dart&#39;;</pre><pre>class Details extends StatelessWidget {<br>  <strong>final int? id;<br>  final String? name;<br>  final String? image;</strong><br>  const Details({Key? key<strong>, this.id, this.name, this.image</strong>}) : super(key: key);</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      backgroundColor: Colors.black,<br>      body: SingleChildScrollView(<br>        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),<br>        physics: const BouncingScrollPhysics(),<br>        child: Column(<br>          children: [<br>            DetailImage(id: id!, image: image!),<br>            DetailTitle(id: id!, name: name!),<br>            DetailData(id: id!),<br>          ],<br>        ),<br>      ),<br>      floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,<br>      floatingActionButton: const DetailBackButton(),<br>    );<br>  }<br>}</pre><p>Now, our animations are working fine. But still there is a problem in the text widget’s animation. Let’s fix it. Use the following code in the <strong>pokemon_card_dara.dart</strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class PokemonCardData extends StatelessWidget {<br>  final int id;<br>  final String image;<br>  final String name;</pre><pre>const PokemonCardData({<br>    Key? key,<br>    required this.id,<br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return Column(<br>      <strong>crossAxisAlignment: CrossAxisAlignment.stretch,</strong><br>      children: [<br>        Expanded(<br>          child: Padding(<br>            padding: const EdgeInsets.all(11),<br>            child: Hero(<br>              tag: &quot;image-$id&quot;,<br>              child: Image.network(<br>                image,<br>                fit: BoxFit.contain,<br>                alignment: Alignment.bottomRight,<br>              ),<br>            ),<br>          ),<br>        ),<br>        const Divider(),<br>        Hero(<br>          tag: &quot;name-$id&quot;,<br>          child: Material(<br>            color: Colors.white,<br>            shape: const RoundedRectangleBorder(<br>              borderRadius: BorderRadius.all(<br>                Radius.circular(21),<br>              ),<br>            ),<br>            child: <strong>Center(<br>              child:</strong> Text(<br>                &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>                textAlign: TextAlign.center,<br>                style: const TextStyle(<br>                  fontSize: 21,<br>                  color: Colors.black87,<br>                ),<br>              ),<br>            <strong>),</strong><br>          ),<br>        ),<br>      ],<br>    );<br>  }<br>}</pre><p>Hushhh! Done with the <strong>Hero animations</strong>, let’s start with the <strong>AppBar animations</strong> now.</p><h3>Adding AppBar animations</h3><p>Remember the <strong>Sliver article </strong>that I wrote? If no, then read it by clicking the below link.</p><p><a href="https://medium.com/@omlondhe/slivers-in-flutter-62d7b54e4275">Slivers in Flutter</a></p><p>Now we are going to add <strong>SliverAppBar </strong>in our application and thus as a <strong>Sliver sibling</strong>, we are gonna add <strong>SliverGrid. </strong>But, in the next article, till then, Bye!</p><h3><strong>Thank you 🙏!</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9e57c8cf8b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Flutter Pokedex]]></title>
            <link>https://medium.com/@omlondhe/creating-a-flutter-pokedex-23c167cae043?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/23c167cae043</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Sat, 25 Dec 2021 15:26:56 GMT</pubDate>
            <atom:updated>2021-12-25T15:26:56.260Z</atom:updated>
            <content:encoded><![CDATA[<p>Merry Christmas to everyone, as I promised, we are creating our first Flutter application which is, as you know, a Pokedex. Initially, I thought that I should create different parts of this article for us and then provide them all day by day on Medium, but, due to my college admissions, this plan failed and I am now writing this single article which contains the procedure and code to create this whole application. So, without this b**shit talk, let’s get started with the app itself.</p><h3>Introduction and Theme</h3><p>We have created the application, and now is the time to make changes to the default Flutter application that we have to make it amazing. As we all know, the Pokedex has the color combination of <strong>Red &amp; White</strong>, and we are following the same convection.</p><h3>Starting with the app</h3><p>To start creating an application, the first thing that we have to do is to just remove all the comments. After that, we have to create a new folder inside the <strong>lib</strong> folder called <strong>screens</strong> and this is where all our screens will be stored, here screens mean all the widgets that we can navigate to. <br>The next thing that we have to do is to create a new folder inside the <strong>lib </strong>folder called <strong>widgets</strong> which is the sibling of our newly created <strong>screens </strong>folder and this will contain all the reusable <strong>widgets </strong>that we are gonna create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*ePCPQfStVM5LTl5ukAFhCg.png" /></figure><p>After all these additions, we have to go for creating a new file in the <strong>screens</strong> folder. Let’s call it <strong>home.dart</strong> as this file contains the <strong>Home </strong>widget. This widget is accessed by the <strong>App </strong>widget that is created inside <strong>main.dart.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*9mad-udUpljgGLl2lUfoYA.png" /></figure><p>This is for the basic setup, but we have to change the code of the <strong>Home </strong>widget afterward.</p><h3>Fetching first 250 Pokemon</h3><p>We have discussed in the previous article that we can fetch data, pokemon for this context from the link given below.</p><p><a href="https://pokeapi.co/api/v2/pokemon?limit=250"><em>https://pokeapi.co/api/v2/pokemon?limit=250</em></a></p><p>The link above returns the first 250 Pokemon starting from <strong>Bulbasaur</strong> to <strong>Ho-oh</strong>. Initially, we are gonna just fetch these Pokemon and print them. This will help us to check if our API is working correctly.</p><p>For fetching data from an API we must have permission from the device and this permission can be obtained from the following statement. We have to paste the bold statement at the correct position as shown in the code below.</p><pre>&lt;manifest xmlns:android...&gt;<br> ...<br>     <strong>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</strong><br>     &lt;application ...<br>&lt;/manifest&gt;</pre><p>Now that we have permission to access the internet from our application, we can move forward to make a network call from our application. But, for that purpose, we need to install the <strong>http</strong> package, type in the following command in the terminal to do so.</p><pre> flutter pub add http</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*culbH-h8ZLRq-tkJ8upciw.png" /></figure><p>The package is now installed and this is the time to create a new folder inside the <strong>lib</strong> folder which we can use to store our <strong>model classes</strong>. This folder must contain the file called <strong>poke_model.dart </strong>with a <strong>model class</strong> called <strong>Pokemon</strong> which stores the Pokemon data to show inside the <strong>GridView</strong>. Let’s create this folder and the file containing the class too. It will look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*7Kh4sEt26xZ1R-1FdF_6gA.png" /></figure><p>According to our use case, this file should contain the following code. It is useful to create a <strong>Pokemon</strong> object containing parameters like <strong>id, name, </strong>and <strong>img</strong>. This class also contains two methods called <strong>fromJson </strong>and <strong>toJson </strong>to parse the JSON data from and to <strong>Pokemon </strong>object.</p><pre>class Pokemon {<br>    int id;<br>    String name;<br>    String img;</pre><pre>    Pokemon.fromJson(Map&lt;String, dynamic&gt; data)<br>        : id = data[&#39;id&#39;],<br>          name = data[&#39;name&#39;],<br>          img = data[&#39;img&#39;];</pre><pre>    Map&lt;String, dynamic&gt; toJson() =&gt; {&#39;id&#39;: id, &#39;name&#39;: name, &#39;img&#39;: img};<br>}</pre><p>Now, we have to create a new folder inside the <strong>lib </strong>folder named <strong>API </strong>and in this folder, we will store all our API classes. Here we are creating a file called <strong>pokeapi.dart </strong>to keep all our APIs. The code in this file should look something like this.</p><pre>import &#39;dart:async&#39;;<br>import &#39;package:http/http.dart&#39; as http;</pre><pre>class PokeAPI {<br>    static Future&lt;http.Response&gt; getPokemon() =&gt;   <br>        http.get(Uri.parse(&quot;https://pokeapi.co/api/v2/pokemon?limit=250&quot;));<br>}</pre><p>This file contains a class called <strong>PokeAPI</strong> which has a <em>static asynchronous </em>method called <strong>getPokemon</strong> which returns <strong>Future&lt;http.Response&gt;</strong> and is a static method. The main objective of this method is to fetch all 250 Pokemons from the URL we saw earlier.</p><p>In the <strong>home.dart </strong>file, we can create a method called <strong>getPokemonFromPokeApi </strong>which is calling the <em>static asynchronous</em> method <strong>getPokemon </strong>to get <strong>Pokemon </strong>in the <strong>Home </strong>widget. This function looks something like this.</p><pre>void getPokemonFromPokeApi() async {<br>    PokeAPI.getPokemon().then((response) {<br>    List&lt;Map&lt;String, dynamic&gt;&gt; data =<br>        List.from(json.decode(response.body)[&#39;results&#39;]);</pre><pre>    setState(() {<br>        pokemon = data.asMap().entries.map&lt;Pokemon&gt;((element) {<br>                element.value[&#39;id&#39;] = element.key + 1;<br>                element.value[&#39;img&#39;] = &quot;https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/${element.key + 1}.png&quot;;<br>                return Pokemon.fromJson(element.value);<br>            }).toList();<br>        });<br>    });<br>}</pre><p>The value that this function is updating is of a type <strong>List&lt;Pokemon&gt; </strong>which is defined at the top of the state class <strong>_HomeState</strong>. And the above method is called inside <strong>initState</strong> function which <em>must be overridden to use</em>. The code for this purpose should look something like this.</p><pre>class _HomeState extends State&lt;Home&gt; {<br>    <strong>List&lt;Pokemon&gt; pokemon = List.empty();<br>    <br>    @override<br>    void initState() {<br>        super.initState();<br>        getPokemonFromPokeApi();<br>    }</strong></pre><pre>    void getPokemonFromPokeApi() async {<br>        .....</pre><h3>Showing data in GridView</h3><p>To show data in <strong>GridView</strong>, we must render the <strong>GridView</strong> on the screen. Among the different types of constructors of the <strong>GridView</strong>, we are going to use the <strong>GridView.count(…)</strong> constructor. But, we won’t directly render this widget in <strong>home.dart </strong>file, we will create a new file inside the <strong>widgets</strong> folder called <strong>pokemon_grid.dart</strong> exporting the <strong>PokemonGrid </strong>widget that looks like this.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/poke_model.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card.dart&#39;;</pre><pre>class PokemonGrid extends StatefulWidget {<br>  final List&lt;Pokemon&gt; pokemon;<br>  const PokemonGrid({Key? key, required this.pokemon}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  _PokemonGridState createState() =&gt; _PokemonGridState();<br>}</pre><pre>class _PokemonGridState extends State&lt;PokemonGrid&gt; {<br>  <a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    final width = MediaQuery.of(context).size.width;<br>    final crossAxisCount = (width &gt; 1000)<br>        ? 5<br>        : (width &gt; 700)<br>            ? 4<br>            : (width &gt; 450)<br>                ? 3<br>                : 2;</pre><pre>return GridView.count(<br>      padding: const EdgeInsets.all(7),<br>      crossAxisCount: crossAxisCount,<br>      crossAxisSpacing: 4,<br>      mainAxisSpacing: 4,<br>      semanticChildCount: 250,<br>      childAspectRatio: 200 / 244,<br>      physics: const BouncingScrollPhysics(),<br>      children: widget.pokemon<br>          .map(<br>            (pokemon) =&gt; PokemonCard(<br>              id: pokemon.id,<br>              name: pokemon.name,<br>              image: pokemon.img,<br>            ),<br>          )<br>          .toList(),<br>    );<br>  }<br>}</pre><p>The above code is a basic code which is taking an array of <strong>Pokemon </strong>objects as a parameter and we are looping over it to show a widget called <strong>PokemonCard</strong> with the required data. You may be wondering about the following two lines.</p><pre>final width = MediaQuery.of(context).size.width;<br>final crossAxisCount = (width &gt; 1000)<br>    ? 5<br>    : (width &gt; 700)<br>        ? 4<br>        : (width &gt; 450)<br>            ? 3<br>            : 2;</pre><p>These lines are just asking for the width of your device and storing the same in the variable called <strong>width</strong>. Then it is conditionally changing the <strong>crossAxisCount</strong> of the <strong>GridView</strong> and this makes our <strong>GridView</strong> responsive for all screen sizes. The <strong>physics</strong> property <strong>BouncingScrollPhysics</strong> is allowing us to give a nice bouncing effect when the user over scrolls.</p><p>To show the data in <strong>GridView</strong> we must have a widget that we can reuse to keep our elements consistent. Thus we have to create a file called <strong>pokemon_card.dart </strong>which will contain our reusable widget. This widget will contain the <strong>image</strong> of Pokemon with its <strong>name</strong> and <strong>id</strong>. The code for this widget will look something like this.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_background.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_data.dart&#39;;</pre><pre>class PokemonCard extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  final String image;</pre><pre>const PokemonCard({<br>    Key? key,<br>    required this.id,<br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre>BoxDecoration getContainerDecoration() =&gt; BoxDecoration(<br>        color: Colors.white,<br>        borderRadius: BorderRadius.circular(7),<br>        border: Border.all(<br>          color: Colors.grey.withOpacity(0.24),<br>          width: 1,<br>        ),<br>      );</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Container(<br>      padding: const EdgeInsets.all(7),<br>      decoration: getContainerDecoration(),<br>      child: Stack(<br>        children: [<br>          PokemonCardBackground(id: id),<br>          PokemonCardData(name: name, image: image),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>The above code is just decorating the <strong>Container</strong> widget and showing two widgets named <strong>PokemonCardBackground </strong>and <strong>PokemonCardData </strong>in a <strong>Stack</strong> widget so that we can achieve a stacked effect. Let’s see these two widgets.</p><p>The widget <strong>PokemonCardBackground </strong>is created in a file called <strong>pokemon_card_background.dart</strong>, which is stored in the <strong>widgets</strong> folder. This file contains a class <strong>PokemonCardBackground</strong> which returns just a <strong>Text</strong> widget with some styles. The code for this is given below. The widget only accepts an <strong>id</strong> as a parameter and renders it in the <strong>Stack</strong> widget from <strong>PokemonCard</strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class PokemonCardBackground extends StatelessWidget {<br>  final int id;<br>  const PokemonCardBackground({Key? key, required this.id}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Text(<br>      &quot;$id&quot;,<br>      style: TextStyle(<br>        fontSize: 101,<br>        fontWeight: FontWeight.bold,<br>        color: Colors.grey[200],<br>      ),<br>    );<br>  }<br>}</pre><p>But this is just rendering the numbers on the cards but not the Pokemon name and images so let’s see how we can show this data as well. For this purpose, we have to create another file called <strong>pokemon_card_data.dart </strong>in the <strong>widgets </strong>folder. This file contains a class <strong>PokemonCardData</strong> which returns a column containing an <strong>Image</strong>, <strong>Divider,</strong> and <strong>Text</strong> widget. That is just rendering the image and text with a separator in between them. The code looks like this.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class PokemonCardData extends StatelessWidget {<br>  final String image;<br>  final String name;<br>  const PokemonCardData({<br>    Key? key,<br>    required this.name,<br>    required this.image,<br>  }) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Column(<br>      children: [<br>        Expanded(<br>          child: Image.network(<br>            image,<br>            fit: BoxFit.contain,<br>          ),<br>        ),<br>        const Divider(),<br>        Text(<br>          &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>          style: const TextStyle(<br>            fontSize: 21,<br>            color: Colors.black87,<br>          ),<br>        ),<br>      ],<br>    );<br>  }<br>}</pre><p>If you have followed all the steps I mentioned, then you will see a list containing Pokemon on the screen something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*aYKNf-7xD5_1pZdPUvZ9RQ.jpeg" /></figure><p>Now that we are done with the basic first page, this is the time to set up our routing so that we can navigate to the details page to see the details of the Pokemon we clicked on. So, let’s go.</p><h3>Adding navigation to the application</h3><p>For enabling the navigation in Flutter, we must use the <strong>routes</strong> provided by the <strong>MaterialApp</strong> widget. The following code is written in the <strong>main.dart</strong> file and you just have to enter consider the bold text from the following snippet. You have to remove the line home: const Home() and add the bolded code from the following code snippet.</p><pre>import &#39;package:pokedex/screens/details.dart&#39;;<br>import &#39;package:pokedex/screens/home.dart&#39;;</pre><pre>void main() {<br>  runApp(const App());<br>}</pre><pre>class App extends StatelessWidget {<br>  const App({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Pokedex&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.red,<br>      ),<br>      <strong>initialRoute: &quot;/&quot;,<br>      routes: {<br>        &quot;/&quot;: (context) =&gt; const Home(),<br>        &quot;/details&quot;: (context) =&gt; const Details(),<br>      },</strong><br>    );<br>  }<br>}</pre><p>Now that we have added our routes, this is time to expose them to the user so that he can navigate through the app. In our application, we want the user to be able to navigate to the details screen from the main screen, and for this, we will allow him to click on <strong>PokemonCards</strong>. This can be achieved using <strong>InkWell</strong> widget with the following code. Here we are just navigating the user when he clicks the <strong>PokemonCard</strong> and along with the navigation, we are passing the data too. Following is the code to allow users to click on <strong>PokemonCard</strong> and navigate to the details screen. The code below is from the file called <strong>pokemon_card.dart</strong>. We just have to consider the bold lines to add.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/pokemon_screen_data.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_background.dart&#39;;<br>import &#39;package:pokedex/widgets/pokemon_card_data.dart&#39;;</pre><pre>class PokemonCard extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  final String image;</pre><pre>    const PokemonCard({<br>        Key? key,<br>        required this.id,<br>        required this.name,<br>        required this.image,<br>    }) : super(key: key);</pre><pre>    BoxDecoration getContainerDecoration() =&gt; BoxDecoration(<br>        borderRadius: BorderRadius.circular(7),<br>        border: Border.all(<br>          color: Colors.grey.withOpacity(0.24),<br>          width: 1,<br>        ),<br>      );</pre><pre>  @override<br>  Widget build(BuildContext context) {<br>    return <strong>Material(<br>      color: Colors.white,<br>      child: InkWell(<br>        borderRadius: BorderRadius.circular(7),<br>        enableFeedback: true,<br>        splashColor: Colors.red[50],<br>        onTap: () =&gt; {<br>          Navigator.pushNamed(<br>            context,<br>            &quot;/details&quot;,<br>            arguments: PokemonScreenData(id, name, image),<br>          )<br>        },<br>        child:</strong> Container(<br>          padding: const EdgeInsets.all(7),<br>          decoration: getContainerDecoration(),<br>          child: Stack(<br>            children: [<br>              PokemonCardBackground(id: id),<br>              PokemonCardData(name: name, image: image),<br>            ],<br>          ),<br>        ),<br>     <strong> ),<br>    );<br></strong>  }<br>}</pre><p>Now, there is a problem, we are trying to navigate to the widget called <strong>Details </strong>and this is not yet created by us. We have to create a file named <strong>details.dart </strong>with the class <strong>Details </strong>as our widget and this is the screen of our app thus in the <strong>screens </strong>folder. This file contains the same data as we have already populated but in a different layout. The code is given below which will help you to get to know, how you can access data passed while navigating.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:pokedex/models/pokemon_screen_data.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_back_button.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_data.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_image.dart&#39;;<br>import &#39;package:pokedex/widgets/detail_title.dart&#39;;</pre><pre>class Details extends StatelessWidget {<br>  const Details({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    final arguments =<br>        ModalRoute.of(context)!.settings.arguments as PokemonScreenData;</pre><pre>return Scaffold(<br>      backgroundColor: Colors.black,<br>      body: SingleChildScrollView(<br>        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),<br>        physics: const BouncingScrollPhysics(),<br>        child: Column(<br>          children: [<br>            DetailImage(image: arguments.image),<br>            DetailTitle(id: arguments.id, name: arguments.name),<br>            DetailData(id: arguments.id),<br>          ],<br>        ),<br>      ),<br>      floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,<br>      floatingActionButton: const DetailBackButton(),<br>    );<br>  }<br>}</pre><p>In the above code, the line <strong>final arguments =<br> ModalRoute.of(context)!.settings.arguments as PokemonScreenData; </strong>is theone which is getting the data from the navigation parameters.</p><p>The widgets <strong>DetailImage</strong>, <strong>DetailTitle</strong>, and <strong>DetailData</strong> are populated here. For these widgets, we are creating files called <strong>detail_image.dart, detail_title.dart,</strong> and <strong>detail_data.dart</strong> in the <strong>widgets</strong> folder respectively. They are doing nothing but showing the given data in the different forms of the layout.</p><p>The <strong>detail_image.dart </strong>looks like this.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailImage extends StatelessWidget {<br>  final String image;<br>  const DetailImage({Key? key, required this.image}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Container(<br>      constraints: const BoxConstraints(<br>        maxHeight: 500,<br>      ),<br>      color: Colors.black,<br>      child: Center(<br>        child: Stack(<br>          children: [<br>            Container(<br>              height: 500,<br>              width: 500,<br>              decoration: const BoxDecoration(<br>                color: Colors.white10,<br>                shape: BoxShape.circle,<br>              ),<br>            ),<br>            Image.network(<br>              image,<br>              fit: BoxFit.contain,<br>              alignment: Alignment.center,<br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>The <strong>detail_title.dart </strong>looks like this.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailTitle extends StatelessWidget {<br>  final int id;<br>  final String name;<br>  const DetailTitle({Key? key, required this.id, required this.name})<br>      : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Chip(<br>      backgroundColor: Colors.white,<br>      label: Text(<br>        &quot;${name[0].toUpperCase()}${name.substring(1)}&quot;,<br>        style: const TextStyle(<br>          fontSize: 24,<br>          color: Colors.black,<br>        ),<br>      ),<br>      avatar: CircleAvatar(<br>        child: Text(<br>          id.toString(),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>The <strong>detail_data.dart </strong>looks like this.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailData extends StatelessWidget {<br>  final int id;<br>  const DetailData({Key? key, required this.id}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return Container(<br>      constraints: BoxConstraints(<br>        minWidth: MediaQuery.of(context).size.width,<br>        minHeight: 500,<br>      ),<br>      decoration: const BoxDecoration(<br>        color: Colors.white,<br>        border: Border(<br>          top: BorderSide(<br>            width: 2,<br>            color: Colors.grey,<br>          ),<br>        ),<br>        borderRadius: BorderRadius.only(<br>          topLeft: Radius.circular(71),<br>          topRight: Radius.circular(71),<br>        ),<br>      ),<br>      child: Column(<br>        children: [],<br>      ),<br>    );<br>  }<br>}</pre><p>Except these files, we also have a file called <strong>detail_back_button.dart</strong> containing a floating action button to go back to the <strong>Home widget</strong>. This file contains the following code.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class DetailBackButton extends StatelessWidget {<br>  const DetailBackButton({Key? key}) : super(key: key);</pre><pre><a href="http://twitter.com/override">@override</a><br>  Widget build(BuildContext context) {<br>    return FloatingActionButton.extended(<br>      onPressed: () =&gt; Navigator.pop(context),<br>      tooltip: &#39;Share&#39;,<br>      label: const Text(<br>        &quot;Back&quot;,<br>      ),<br>      icon: const Icon(Icons.arrow_back_ios_new_rounded),<br>    );<br>  }<br>}</pre><p>After this navigation setup and the creation of a new screen, we are almost done. Our details screen looks like this now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*ogVYspwZESjfiev_fw-lfw.jpeg" /></figure><p>Don’t you think that this app is not done yet? The details screen looks blank and we have to make it look good. We will add animations in the whole app and also feed it some extra data to fill in the blank spaces. So, this was the basic application. We will continue this app in the next article. Till then you can see the code on my GitHub. The branch for it is called Part 1. Click the link below.</p><p><a href="https://github.com/Om-Londhe/FlutterPokedex">GitHub - Om-Londhe/FlutterPokedex: Pokedex in Flutter for Medium blogs</a></p><h3><strong>Thank You 🙏and Merry Christmas 🎄!</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23c167cae043" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Flutter Pokedex]]></title>
            <link>https://medium.com/@omlondhe/creating-a-flutter-pokedex-a384a5bf2248?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/a384a5bf2248</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-pokedex]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-om-londhe]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Fri, 17 Dec 2021 03:24:31 GMT</pubDate>
            <atom:updated>2021-12-17T03:24:31.123Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1: Introduction, Information, and Resources</h4><p>Now that we have our basics of Flutter cleared as crystal, we can go ahead to create a new Flutter application that will help us to integrate all those things that we learned. From today till <strong><em>Christmas</em></strong>, we will create a new Flutter application, basically, a Pokedex using Flutter. The goal is to create a basic Pokedex by <strong><em>Christmas </em></strong>and then <strong><em>Optimize</em></strong> and <strong><em>Publish </em></strong>it to the <strong><em>Play Store </em></strong>by <strong><em>New Year</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*eZxDui5jRHnyvPXmsb25_g.jpeg" /></figure><p>As this is the basic application, we will just use normal Flutter stuff along with an API to fetch data and show it in our application. This application will help us to kickstart our Flutter development journey. Here we will understand the following things-</p><ol><li>How to call an API using Flutter (Dart).</li><li>How to show the API results in widgets.</li><li>How to use a ListView/GridView.</li><li>How to design a Splash screen.</li><li>How to add animations to the application.</li><li>How to create reusable widgets.</li><li>How to use navigator.</li><li>How to send data while navigating.</li><li>How to separate the code.</li><li>How to optimize the code.</li><li>How to scale an application.</li><li>How to publish app to Google Play Store.</li><li>How to show ads in an application to get paid by Google itself.</li><li>etc.</li></ol><p>The list is quite large and we have to complete all of this as early as New Year. But we will complete all of these things.</p><p>As we know, we can use a command to create a flutter application, we must create out Flutter application using the following command that we have seen earlier.</p><pre>flutter create pokedex</pre><p>The output of this command will be something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*UL2mOL72eW9_k7eBKnYDpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gm55SIJTYyrC2SmBW_I26A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*Jgd6zomjEmoYS_dMqALgmg.png" /></figure><p>After this, we must go to the application and open it in VS Code using the commands below.</p><pre>cd pokedex<br>code .</pre><p>These commands will fire up your VS Code in the folder from which you ran the command.</p><p>So this was about the application, but <em>which API we are gonna use?<br></em>We are gonna use <strong><em>PokeAPI</em></strong> you can read about this by clicking on the following link.</p><p><a href="https://pokeapi.co/">PokéAPI</a></p><p>The following will be the first link that we will use to get a list of pokemon.</p><p><a href="https://pokeapi.co/api/v2/pokemon?limit=150">https://pokeapi.co/api/v2/pokemon?limit=150</a></p><p>So this was an introduction, information, and resources that we need for this application. I’ll catch you in the next one!</p><h3>Thank you 🙏</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a384a5bf2248" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Text widget in Flutter]]></title>
            <link>https://medium.com/@omlondhe/all-about-text-widget-in-flutter-45998e54e84?source=rss-88254678ca85------2</link>
            <guid isPermaLink="false">https://medium.com/p/45998e54e84</guid>
            <category><![CDATA[flutter-om-londhe]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-text]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <dc:creator><![CDATA[Om Londhe]]></dc:creator>
            <pubDate>Thu, 16 Dec 2021 06:04:26 GMT</pubDate>
            <atom:updated>2021-12-16T06:04:26.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*iObEmvxyG6iX6-tLEVCcxg.png" /></figure><p>So, we are done with the <strong><em>Row</em></strong> widget and <strong><em>Column </em></strong>widget. Now we will see how the <strong><em>Text</em></strong><em> </em>widget works. As we have seen yesterday, in the article explaining the <strong><em>Row </em></strong>and<strong><em> Column </em></strong>widget, that we can use the <strong><em>Column </em></strong>and <strong><em>Row </em></strong>widget to render the text on the screen. But, if you remember, before that, we were having a default code that was rendering the text at the center position of the screen. There were two <strong><em>Text</em></strong> widgets, but from these two, we are just considering the last text widget. The widget which is showing the counter. The code was looking something like follows.</p><pre>Text(<br>    &#39;$_counter&#39;,<br>    style: Theme.of(context).textTheme.headline4,<br>)</pre><p>The widget is keeping track of the value of the variable <strong><em>_counter</em></strong> which is incrementing the value when we click the floating action button. Here, the <strong><em>style </em></strong>attribute is also set. This widget has more attributes, let’s take a look at them with the help of constructor with named parameters.</p><pre>Text(<br>  String data, {<br>  Key? key,<br>  TextStyle? style,<br>  StrutStyle? strutStyle,<br>  TextAlign? textAlign,<br>  TextDirection? textDirection,<br>  Locale? locale,<br>  bool? softWrap,<br>  TextOverflow? overflow,<br>  double? textScaleFactor,<br>  int? maxLines,<br>  String? semanticsLabel,<br>  TextWidthBasis? textWidthBasis,<br>  TextHeightBehavior? textHeightBehavior,<br>})</pre><p>This description is quite different from other. The parameter <strong><em>data </em></strong>is required and it must be passed so that we do not get any error. The named non-required parameters are also there. The arrtibute <strong><em>style</em></strong> is one of them. Other attributes are very self explanatory. But still let’s see what they do.</p><h3>Attributes and their description</h3><h4>style</h4><p>This attribute takes object of type <strong><em>TextStyle </em></strong>in which we can define styles for our text.</p><h4>strutStyle</h4><p>The strut style to use. Strut style defines the strut, which sets minimum vertical layout metrics.</p><h4>textAlign</h4><p>This is used to set the alignment of the text.</p><h4>textDirection</h4><p>This is used to set the direction of the text.</p><h4>locale</h4><p>Used to select a font when the same Unicode character can be rendered differently, depending on the locale.</p><h4>softWrap</h4><p>To tell whether the text should break at soft line breaks.</p><h4>overflow</h4><p>To tell how visual overflow should be handled.</p><h4>textScaleFactor</h4><p>To specify the number of font pixels for each logical pixel.</p><h4>maxLines</h4><p>To set the maximum number of lines to render in the <strong><em>Text</em></strong> widget.</p><h4>semanticsLabel</h4><p>To specify an alternative semantics label for this text.</p><h4>textWidthBasis</h4><p>Defines how to measure the width of the rendered text.</p><h4>textHeightBehaviour</h4><p>Defines how the paragraph will apply <a href="https://api.flutter.dev/flutter/painting/TextStyle/height.html"><strong><em>TextStyle.height</em></strong></a><strong><em> </em></strong>to the ascent of the first line and descent of the last line.</p><h3>Example</h3><p>We are modifying our <strong><em>Text</em></strong> widget to make it look nicer. You just have to copy the following code and replace the code in your <strong><em>_MyHomePageState</em></strong>’s <strong><em>build</em></strong> method’s <strong><em>Scaffold</em></strong> widget’s <strong><em>body</em></strong> attribute with the one you copied.</p><h4>Code</h4><pre>Center(<br>    child: SizedBox(<br>        width: MediaQuery.of(context).size.width,<br>        child: Text(<br>            &#39;$_counter&#39;,<br>                textAlign: TextAlign.center,<br>                style: const TextStyle(<br>                    fontSize: 71,<br>                    color: Colors.pink,<br>                    fontWeight: FontWeight.bold,<br>                    fontStyle: FontStyle.italic,<br>                    letterSpacing: 2,<br>                    decoration: TextDecoration.underline,<br>                    decorationThickness: 0.4,<br>                    decorationStyle: TextDecorationStyle.wavy,<br>                    decorationColor: Colors.white,<br>                    shadows: [<br>                        Shadow(<br>                            color: Colors.orangeAccent,<br>                            offset: Offset(4, 4),<br>                            blurRadius: 11,<br>                        )<br>                    ],<br>                ),<br>            ),<br>        ),<br>    ),<br>)   </pre><h4>output</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*IO8hh2WRZc4KBoPA8hfe3g.jpeg" /></figure><p>This was about <strong><em>Text</em></strong> widget, I’ll catch you in the next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45998e54e84" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>