<?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 David Anderson on Medium]]></title>
        <description><![CDATA[Stories by David Anderson on Medium]]></description>
        <link>https://medium.com/@dander.11.9?source=rss-c126ac705586------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*v7rGc01t0_GKGCFH25_OmA.jpeg</url>
            <title>Stories by David Anderson on Medium</title>
            <link>https://medium.com/@dander.11.9?source=rss-c126ac705586------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 17:56:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dander.11.9/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[Implementing search in Flutter]]></title>
            <link>https://medium.com/shipkaro/implementing-search-in-flutter-17dc5aa72018?source=rss-c126ac705586------2</link>
            <guid isPermaLink="false">https://medium.com/p/17dc5aa72018</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[David Anderson]]></dc:creator>
            <pubDate>Mon, 31 Dec 2018 17:23:34 GMT</pubDate>
            <atom:updated>2019-03-29T16:03:31.620Z</atom:updated>
            <content:encoded><![CDATA[<p>One issue I’ve had to deal with in each Flutter app that I’ve made is search. Originally I was using a third-party package like <a href="https://pub.dartlang.org/packages/material_search">Material Search</a> or <a href="https://pub.dartlang.org/packages/flutter_search_bar">Flutter Search Bar</a>. Until I saw the <a href="https://www.youtube.com/watch?v=Wm3OiFBZ2xI&amp;t=2447s">Boring Flutter Show’s episode on implementing search</a> in the Hacker News app. This led me to using the ShowSearch method in Flutter.</p><h3>ShowSearch</h3><p><a href="https://docs.flutter.io/flutter/material/showSearch.html">ShowSearch </a>is a method in the material library in Flutter. Because of this, it can be accessed from anywhere in your widget tree. Below is an example of a SliverAppBar that contains a title and an IconButton that calls the ShowSeach method when it is pressed. This method takes the build context and a SearchDelegate to handle the actual searching.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2bfaa723a6bcfb142a1d95ee4fd3ae0/href">https://medium.com/media/b2bfaa723a6bcfb142a1d95ee4fd3ae0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*4LJr_32YytdQ2b_DKrXOAA.png" /><figcaption>What the app bar looks like in the example app</figcaption></figure><h3>CustomSearchDelegate</h3><p>To implement a custom search delegate, you need to create a new class that extends the <a href="https://docs.flutter.io/flutter/material/SearchDelegate-class.html">SearchDelegate </a>class. When you first implement that class you will have the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0e3385bfcbc93f7e1b8e16ea284eb5d/href">https://medium.com/media/a0e3385bfcbc93f7e1b8e16ea284eb5d/href</a></iframe><p>For an in depth walkthrough of implementing these methods, I recommend watching the boring flutter show episode starting at 6 minutes in. They talk more in depth about what each method of the delegate does.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWm3OiFBZ2xI%3Fstart%3D360%26feature%3Doembed%26start%3D360&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWm3OiFBZ2xI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWm3OiFBZ2xI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/07545fd7697e25db64d0a428645b3613/href">https://medium.com/media/07545fd7697e25db64d0a428645b3613/href</a></iframe><p>For the sake of brevity, here is my final CustomSearchDelegate class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69c34f30135f0efb68606d607f3afb50/href">https://medium.com/media/69c34f30135f0efb68606d607f3afb50/href</a></iframe><p>I’m using the <a href="https://medium.com/flutterpub/architecting-your-flutter-project-bd04e144a8f1">BLOC pattern</a> with an inherited widget to submit the search term and then using a <a href="https://docs.flutter.io/flutter/widgets/StreamBuilder-class.html">StreamBuilder </a>to build based on the results of that search.</p><p>And this is what it looks like when the search results are shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*2x5MBA3_5vyomOrWhCMn2w.png" /></figure><h3>Customizing the ThemeData of your search page AppBar</h3><p>One thing you may notice is that when the search page is shown, the theme is not the same as the app’s theme. You can see this specifically in the AppBar’s colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*H2kMUwrJHX6brqyVdfAdPw.png" /><figcaption>The AppBar is blue with white text on the main page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*BCfJ4FFvM3IJ9X1cZTRZ6A.png" /><figcaption>On the search page, the AppBar is white with black text</figcaption></figure><p>This won’t work if you need your search page theme to match the rest of your application. And there isn’t an abstract method to override in SearchDelegate. However, there is an implemented method for setting the ThemeData of the AppBar. All you need to do is override that method to set the theme of your AppBar.</p><p>The code below, will just pass the ThemeData from your app directly to the AppBar on the search page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/908779df1e9944408f6a3d2f824cc8be/href">https://medium.com/media/908779df1e9944408f6a3d2f824cc8be/href</a></iframe><p>Now, we have the correct theming on our search page!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*2O3FMP7xE_Dt0vtYoGpngw.png" /><figcaption><em>The search term’s color is set using the theme.textTheme.title</em></figcaption></figure><p>I hope all of this will help you when you try to implement search in your Flutter app!</p><h3>Edits:</h3><p><a href="https://medium.com/@gallegom58?source=responses---------0---------------------">Michael Gallego</a> asked that I share the code for the InheritedBloc class. While that wasn’t part of the initial scope of this article, I figured it wouldn’t hurt. Below is the class code. The way this would be used is by placing your app as the child for this InheritedBloc class, then it could be referenced from any child in your tree.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b6ff29ae0979a85010af6c37eb48236/href">https://medium.com/media/9b6ff29ae0979a85010af6c37eb48236/href</a></iframe><p>The <a href="https://medium.com/flutterpub"><strong>Flutter Pub</strong></a> is a medium publication to bring you the latest and amazing resources such as articles, videos, codes, podcasts etc. about this great technology to teach you how to build beautiful apps with it. You can find us on <a href="https://www.facebook.com/FlutterPub">Facebook</a>, <a href="https://twitter.com/FlutterPub">Twitter</a>, and <a href="https://medium.com/flutterpub">Medium</a> or learn more about us <a href="https://medium.com/flutterpub/welcome-to-flutter-pub-8480678ed212">here</a>. We’d love to connect! And if you are a writer interested in writing for us, then you can do so <a href="https://medium.com/flutterpub/how-to-submit-your-article-s-on-flutterpub-7b6bf37dfc43">through these guidelines</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*kCSr9XbxNRLVG5TtTbIWiQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17dc5aa72018" width="1" height="1" alt=""><hr><p><a href="https://medium.com/shipkaro/implementing-search-in-flutter-17dc5aa72018">Implementing search in Flutter</a> was originally published in <a href="https://medium.com/shipkaro">shipkaro — my journey to $10k</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>