<?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 Kamil Klyta on Medium]]></title>
        <description><![CDATA[Stories by Kamil Klyta on Medium]]></description>
        <link>https://medium.com/@kamilklyta341?source=rss-46b959ee960e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*-SmJl1BIuW3HqIwpXWeLTA.jpeg</url>
            <title>Stories by Kamil Klyta on Medium</title>
            <link>https://medium.com/@kamilklyta341?source=rss-46b959ee960e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:32:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kamilklyta341/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[How to create your own pull to refresh / custom refresh indicator widget in Flutter.]]></title>
            <link>https://medium.com/flutter-community/how-to-create-your-own-pull-to-refresh-custom-refresh-indicator-widget-in-flutter-a3aa4e8bb42d?source=rss-46b959ee960e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3aa4e8bb42d</guid>
            <category><![CDATA[pull-to-refresh]]></category>
            <category><![CDATA[package]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Kamil Klyta]]></dc:creator>
            <pubDate>Mon, 04 May 2020 10:01:01 GMT</pubDate>
            <atom:updated>2022-10-25T09:15:46.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BScXL5iCR2w6gyUxl_Ko4g.png" /></figure><p><strong>TLDR</strong>; <a href="https://pub.dev/packages/custom_refresh_indicator">package</a>, <a href="https://custom-refresh-indicator.klyta.it/#/">online example</a>.</p><p>A few months ago, in a project that I was working on, there was a need to create a custom refresh indicator to replace the default indicator provided with a flutter material library. Back in those days, I found it really hard to find some simple solutions or packages that will provide basic functionality on which I will be able to implement it. The one and only thing that I was able to find was <a href="https://github.com/aagarwal1012/Liquid-Pull-To-Refresh">liquid_pull_to_refresh</a> package which <em>(back then)</em> was just a modification of the default material design refresh indicator widget, and I was like…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F11RIDouEyKZ116%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F11RIDouEyKZ116%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F11RIDouEyKZ116%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="245" frameborder="0" scrolling="no"><a href="https://medium.com/media/efe8cdb2ae6c7a784e9450d118692ede/href">https://medium.com/media/efe8cdb2ae6c7a784e9450d118692ede/href</a></iframe><p>To avoid another: copy, paste, refactor, and forgot why this file has over a thousand lines of code — a type of work that almost always ends in some production f… problems. I have created <a href="https://github.com/gonuit/flutter-custom-refresh-indicator">custom_refresh_indicator_package</a> (available on <a href="https://pub.dev/packages/custom_refresh_indicator">pub.dev</a>).</p><p>The main target of this package was to provide all data needed for pull-to-refresh functionality implementation in an as simple way as possible.</p><p>Below you can see an example indicator created on top of this package — Och wait! and there is also an <a href="https://custom-refresh-indicator.klyta.it/#/plane">ONLINE EXAMPLE</a>?!</p><figure><img alt="Example of the custom refresh indicator widget." src="https://cdn-images-1.medium.com/max/577/1*tqWHadnlTjdVkQ9VIA0bKg.gif" /><figcaption>Example pull to refresh widget build on top of the custom_refresh_indicator package.</figcaption></figure><p>Okey… now we know that someone, sometimes for some reason, might like to implement its own unique pull-to-refresh indicator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*O22Df1nbB5uiW6yYnZ3_oQ.jpeg" /></figure><h3>But how?</h3><p>Let’s imagine that we have a simple screen that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*RA974CeaNEvkdTtJkgM5TA.png" /></figure><p>and which is written like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87f59b5f4e61bed5be011a7d72b3162d/href">https://medium.com/media/87f59b5f4e61bed5be011a7d72b3162d/href</a></iframe><p>To add pull-to-refresh functionality, we must wrap the list widget with the <em>CustomRefreshIndicator</em> widget that is provided by custom_refresh_indicator package:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc9c8e2fef039f6eea0a0b5bf34286bc/href">https://medium.com/media/dc9c8e2fef039f6eea0a0b5bf34286bc/href</a></iframe><h3>Let’s take a look at the changes.</h3><h4>Import</h4><p>First of all, we have added an <strong>import statement</strong> to the custom_refresh_indicator package, because we would like to build our indicator on top of it.</p><h4>onRefresh</h4><p>In the same way, as we are using RefreshIndicator widget we assigned a function that will return Future to the <strong>onRefresh argument</strong>. In the above example, we returned Future.delayed() as we do not want to take any action, instead we just want to wait for a few seconds to simulate asynchronous function behavior, but basically, this is the place when you are doing your API call or other asynchronous functions that will take effect after the pull to refresh gesture is made on your list.</p><h4><strong>child</strong></h4><p>We assigned our scrollable widget to the <strong>child argument</strong> — still the same way as we would like to do this with theRefreshIndicator widget.</p><h4>builder</h4><p>The <strong>builder argument</strong> is new in comparison to RefreshIndicator. This function will be used to build our pull-to-refresh widget. It takes three arguments in turn: the context of type BuildContext, child of type Widget and controller of type IndicatorController.</p><ol><li><strong>BuildContext</strong> — It’s a quite common argument, so I think that I can skip it 😉.</li><li>The<strong> child argument</strong> is basically the scrollable widget we assigned to the child widget argument (quite similar behavior to that known from the AnimatedBuilder widget). So if we, for some reason, do not want to render our list, we can skip the use of it — but it almost always makes no sense 😄.</li><li>The third and most important argument is the <strong>controller </strong>of type IndicatorController. This argument contains all information about the scroll state that we would like to use to build our custom indicator. The controller extends theChangeNotifier class, and thanks to that, we can listen to its changes.</li></ol><p><strong>I̶m̶p̶o̶r̶t̶a̶n̶t̶!̶ ̶<br>̶B̶u̶i̶l̶d̶e̶r̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶ ̶w̶i̶l̶l̶ ̶n̶o̶t̶ ̶b̶e̶ ̶c̶a̶l̶l̶e̶d̶ ̶e̶v̶e̶r̶y̶ ̶c̶o̶n̶t̶r̶o̶l̶l̶e̶r̶ ̶d̶a̶t̶a̶ ̶c̶h̶a̶n̶g̶e̶ ̶s̶o̶ ̶t̶o̶ ̶a̶n̶i̶m̶a̶t̶e̶ ̶y̶o̶u̶r̶ ̶i̶n̶d̶i̶c̶a̶t̶o̶r̶ ̶w̶i̶d̶g̶e̶t̶ ̶y̶o̶u̶ ̶s̶h̶o̶u̶l̶d̶ ̶c̶o̶n̶s̶i̶d̶e̶r̶ ̶u̶s̶i̶n̶g̶ ̶A̶n̶i̶m̶a̶t̶e̶d̶B̶u̶i̶l̶d̶e̶r̶ ̶w̶i̶d̶g̶e̶t̶.̶<br></strong>Hi, it’s me from the future 👋😅 As the custom_refresh_indicator 2.0.0 was released, this is no longer true. Since 2.0.0, the builder function rebuilds automatically. However! if your widget is complex and needs some optimization, it might still be a good choice to restore the old behavior and use <em>AnimatedBuilder</em> widget to decide which part of the widget tree to rebuild. To do so, simply set the autoRebuild argument to false — that was easy, right? 😄</p><p>So… the above example will provide a pull-to-refresh behavior — the user can drag the list to call the onRefresh function — <strong>BUT —</strong> without visual effect because the builder function always returns our list without any changes. Therefore, when talking about user experience…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IevJvIU8HINQhaCEMnMKoQ.jpeg" /></figure><p>But if for some reason we find that our users should suffer a little less, just a little 🤏. We would like to add some effect, so let’s do this!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4538c5b7b94bfa928a0650c69092725/href">https://medium.com/media/e4538c5b7b94bfa928a0650c69092725/href</a></iframe><p>As you can see, we have added a Stack widget with some Transforms in it, and that&#39;s the effect:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*oyVvIdy0lqo5FkN2ncw_-g.gif" /></figure><p>To better understand how controller data changes, let’s look at the example below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*7dNvMKc-vus_6Vd0Z0Vsig.gif" /><figcaption>Presentation of controller data changes</figcaption></figure><h3>In Summary</h3><p>As you can see, to implement your custom refresh indicator widget, you do not need to copy dozens of lines of code that you do not even understand from other libraries to your project codebase. Instead, add a custom refresh indicator package to your pubspec.yaml file and implement a few lines of builder function. That’s it, isn’t it simple 😏?</p><p>Do not wait! Create your <strong>own </strong>custom refresh indicator!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3aa4e8bb42d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/how-to-create-your-own-pull-to-refresh-custom-refresh-indicator-widget-in-flutter-a3aa4e8bb42d">How to create your own pull to refresh / custom refresh indicator widget in Flutter.</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>