{"id":7365,"date":"2020-03-16T05:36:32","date_gmt":"2020-03-16T05:36:32","guid":{"rendered":""},"modified":"2024-11-14T11:57:45","modified_gmt":"2024-11-14T11:57:45","slug":"flutter-search-bar-widgets","status":"publish","type":"post","link":"https:\/\/www.getwidget.dev\/blog\/flutter-search-bar-widgets\/","title":{"rendered":"Build a Custom Autocomplete Flutter Searchbar Widget for Your App"},"content":{"rendered":"<p>A <a href=\"https:\/\/docs.getwidget.dev\/gf-searchbar\/\" target=\"_blank\" rel=\"noopener\"><strong>Flutter search bar<\/strong><\/a> is an input field that is used to get the needed information from a collection of data through typing the words &amp; keys related to that. Search bars are the most commonly used component in online shopping apps to find the stuff from a collection of stuff. The search bar is very much helpful to the user in such cases. Not only in shopping apps, but the search bar is also used everywhere having some dynamic information.<\/p>\n<p>In technical terms there are 2 commonly search algorithms:<\/p>\n<h3 id=\"linear-search\">Linear Search<\/h3>\n<p><strong>Linear search<\/strong> is a very simple search algorithm. In Linear search, we search an element or the value in a given array by traversing the array from the starting, till the desired element or value is found.<\/p>\n<h3 id=\"binary-search\">Binary Search<\/h3>\n<p><strong>Binary Search<\/strong> is useful when there is a large number of elements in an array and they are sorted. So a necessary condition for Binary search to work is that the array should be sorted.<\/p>\n<h3 id=\"flutter-search-bar-with-gfwidget\">Flutter Search Bar with GFWidget<\/h3>\n<p><strong>GF SearchBar<\/strong> is a <strong>GetWidget<\/strong> component that is used to build a <strong>flutter search bar<\/strong> in a flutter project. It represents a text field that can be used to search through a group. <strong>Flutter SearchBar<\/strong> can be used inside the app bar or in any page component wherever needed. It is very easy &amp; simple to customize the <strong>GF SearchBar<\/strong>.<\/p>\n<p><strong>searchList: <\/strong>List of [text] or [widget] reference for users<\/p>\n<p><strong>overlaySearchListItemBuilder: <\/strong>Defines how the [searchList] items look like in overlayContainer<\/p>\n<p><strong>hideSearchBoxWhenItemSelected: <\/strong>If true, it will hide the [searchBox]<\/p>\n<p><strong>overlaySearchListHeight: <\/strong>Defines the height of [searchList] overlay container<\/p>\n<p><strong>searchQueryBuilder: <\/strong>Can search and filter the [searchList]<\/p>\n<p>and much more property customization can be done.<\/p>\n<h3 id=\"how-to-get-started\">How to Get Started<\/h3>\n<p>If you are new with <strong>GetWidget<\/strong> then you should go ahead with <a href=\"https:\/\/docs.getwidget.dev\/getting-started\/\" target=\"_blank\" rel=\"noopener\"><strong>Getting started<\/strong><\/a> will guide you on how to start building a beautiful flutter application with the <strong>GetWidget<\/strong> UI library. You have to install the package from <strong>pub.dev<\/strong>, import the package in your Flutter project.<\/p>\n<blockquote><p><em>Install Package from pub.dev :<\/em><\/p><\/blockquote>\n<p><a href=\"https:\/\/pub.dev\/packages\/getwidget\/\" target=\"_blank\" rel=\"noopener\"><strong>https:\/\/pub.dev\/packages\/getwidget<\/strong><\/a><\/p>\n<h3 id=\"import-full-package\">Import full package:<\/h3>\n<p>import &#8216;package:getwidget\/getwidget.dart&#8217;;<\/p>\n<p><strong>Note: dependencies: getwidget: ^4.0.0<\/strong><\/p>\n<blockquote><p><em>Keep playing with the pre-built UI components.<\/em><\/p><\/blockquote>\n<p><strong>GFSearchBar<\/strong> is a search bar input field where the user presses some keys in order to get the relevant options from the list in the search bar that is provided. The below example shows a simple search bar and the result of the code is as shown in the image below.<\/p>\n<figure class=\"kg-card kg-code-card\">\n<pre><code class=\"language-javascript\">import 'package:getwidget\/getwidget.dart';\n\nList list = [\n    \"Flutter\",\n    \"Angular\",\n    \"Node js\",\n  ];\n\nGFSearchBar(\n                searchList: list,\n                searchQueryBuilder: (query, list) =&gt; list\n                    .where((item) {\n                      return item!.toString().toLowerCase().contains(query.toLowerCase());\n                })\n                    .toList(),\n                overlaySearchListItemBuilder: (dynamic item) =&gt; Container(\n                      padding: const EdgeInsets.all(8),\n                      child: Text(\n                        item,\n                        style: const TextStyle(fontSize: 18),\n                      ),\n                    ),\n                onItemSelected: (dynamic item) {\n                  setState(() {\n                    print('$item');\n                  });\n                }),<\/code><\/pre><figcaption><span style=\"white-space: pre-wrap;\">Flutter Searchbar autocomplete Code example snippet<\/span><\/p>\n<\/figcaption><\/figure>\n<h3 id=\"gf-search-bar-widget-custom-properties\">GF Search Bar Widget Custom Properties<\/h3>\n<p>The look and feel of the <strong>GFSearhBar<\/strong> can be customized accordingly by using the below-listed properties.<\/p>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>searchList<\/strong><\/td>\n<td>List of [text] or [widget] reference for users<\/td>\n<\/tr>\n<tr>\n<td><strong>overlaySearchListItemBuilder<\/strong><\/td>\n<td>defines how the [searchList] items look like in overlayContainer<\/td>\n<\/tr>\n<tr>\n<td><strong>hideSearchBoxWhenItemSelected<\/strong><\/td>\n<td>if true, it will hide the [searchBox]<\/td>\n<\/tr>\n<tr>\n<td><strong>overlaySearchListHeight<\/strong><\/td>\n<td>defines the height of [searchList] overlay container<\/td>\n<\/tr>\n<tr>\n<td><strong>searchQueryBuilder<\/strong><\/td>\n<td>can search and filter the [searchList]<\/td>\n<\/tr>\n<tr>\n<td><strong>noItemsFoundWidget<\/strong><\/td>\n<td>displays the [widget] when the search item failed<\/td>\n<\/tr>\n<tr>\n<td><strong>onItemSelected<\/strong><\/td>\n<td>defines what to do with onSelect [SearchList] item<\/td>\n<\/tr>\n<tr>\n<td><strong>searchBoxInputDecoration<\/strong><\/td>\n<td>defines the input decoration of [searchBox]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"flutter-search-bar-inside-the-appbar\">Flutter Search Bar inside the AppBar<\/h3>\n<p>The <strong>GFSearchar<\/strong> can be used inside the <strong>GFAppbar<\/strong> that does the searching operation just like a normal search but with minimum lines of code in the appbar. If the search bar is <code>true<\/code>then it displays a search bar text field with <strong>leading<\/strong>, <strong>trailing<\/strong> options.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" class=\"kg-image lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--114--1.png\" alt=\"\" width=\"635\" height=\"105\" \/><noscript><img decoding=\"async\" class=\"kg-image lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/getwidget\/\/2023\/04\/MicrosoftTeams-image--114--1.png\" alt=\"\" width=\"635\" height=\"105\" \/><\/noscript><\/figure>\n<p>The below code shows how a search bar should be passed in the appbar code.<\/p>\n<figure class=\"kg-card kg-code-card\">\n<pre><code class=\"language-javascript\">import 'package:getwidget\/getwidget.dart';\n\nGFAppBar(\n  leading:  GFIconButton(\n    icon: Icon(\n      Icons.message,\n      color: Colors.white,\n    ),\n    onPressed: () {},\n    type: GFButtonType.transparent,\n  ),\n  searchBar: true,\n  title: Text(\"GF Appbar\"),\n  actions: [\n    GFIconButton(\n      icon: Icon(\n        Icons.favorite,\n        color: Colors.white,\n      ),\n      onPressed: () {},\n      type: GFButtonType.transparent,\n    ),\n  ],\n),\n<\/code><\/pre><figcaption><span style=\"white-space: pre-wrap;\">Flutter Searchbar in appbar<\/span><\/p>\n<\/figcaption><\/figure>\n<h3 id=\"why-use-gf-flutter-search-bar\"><strong>Why use GF Flutter Search Bar?<\/strong><\/h3>\n<p>You will get a pre-designed Search Bar that can be used for searching data in your app. It is very easy to customize &amp; will save your time of development.<\/p>\n<h3 id=\"can-we-customize-gf-search-bar\">Can we customize GF Search Bar?<\/h3>\n<p>Yes, You can customize the shape, border, position of the Search Bar according to need. Some custom properties are :<\/p>\n<blockquote><p><em>searchList<\/em><\/p><\/blockquote>\n<blockquote><p><em>overlaySearchListItemBuilder<\/em><\/p><\/blockquote>\n<blockquote><p><em>hideSearchBoxWhenItemSelected<\/em><\/p><\/blockquote>\n<blockquote><p><em>overlaySearchListHeight<\/em><\/p><\/blockquote>\n<blockquote><p><em>searchBoxInputDecoration<\/em><\/p><\/blockquote>\n<h3 id=\"where-can-we-use-gf-search-bar\">Where can we use GF Search Bar?<\/h3>\n<p>GF Search Bar can be used anywhere in your application and in the appbar as well.<\/p>\n<h3 id=\"do-you-update-the-component-in-the-future\">Do you update the component in the future?<\/h3>\n<p><strong>GetFlutter<\/strong> team is very much passionate about the up-gradation of technology and its related modules. The library &amp; components get updated from time to time.<\/p>\n<p><a href=\"https:\/\/docs.getwidget.dev\/\" target=\"_blank\" rel=\"noopener\"><strong>Flutter Get Widget Docs<\/strong><\/a><\/p>\n<figure class=\"kg-card kg-bookmark-card\">\n<div class=\"kg-bookmark-content\">\n<div class=\"kg-bookmark-title\">Flutter GetWidget Docs<\/div>\n<div class=\"kg-bookmark-description\">Get Widget is one of the largest Flutter open-source UI Kit libraries for mobile or web apps. It has more than 1000+ pre-built reusable widgets.<\/div>\n<div class=\"kg-bookmark-metadata\"><img decoding=\"async\" class=\"kg-bookmark-icon lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/favicon_QkjfdlGz1.png\" alt=\"\" \/><noscript><img decoding=\"async\" class=\"kg-bookmark-icon lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/favicon_QkjfdlGz1.png\" alt=\"\" \/><\/noscript><span class=\"kg-bookmark-author\">getwidget<\/span><span class=\"kg-bookmark-publisher\">getwidget<\/span><\/div>\n<\/div>\n<div class=\"kg-bookmark-thumbnail\"><img decoding=\"async\" class=\"lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/docs\/tr:dpr-auto,tr:w-auto\/link-share_aT-cHzGY9.png\" alt=\"\" \/><noscript><img decoding=\"async\" class=\"lazyload\" src=\"https:\/\/ik.imagekit.io\/ionicfirebaseapp\/docs\/tr:dpr-auto,tr:w-auto\/link-share_aT-cHzGY9.png\" alt=\"\" \/><\/noscript><\/div>\n<\/figure>\n<p><a href=\"https:\/\/github.com\/ionicfirebaseapp\/getwidget\/\" target=\"_blank\" rel=\"noopener\"><strong>GitHub Repository<\/strong><\/a>: Please do appreciate our work through Github start<\/p>\n<p><strong>Also Read &#8211; <a href=\"https:\/\/www.getwidget.dev\/blog\/top-10-best-flutter-search-bar-widgets-list\/\" rel=\"noreferrer\"><strong>Top 10 Best Flutter Search Bar Widgets List<\/strong><\/a><\/strong><\/p>\n<h3 id=\"conclusion\">Conclusion:<\/h3>\n<p>Here we discuss, what <strong>Flutter SearchBar<\/strong> Widget is? And how we can use and implement it into our Flutter app through the <strong>GetWidget<\/strong> <strong>SearchBar<\/strong> component. Here, there are options to customize the <strong>SearchBar<\/strong>.<\/p>\n<h3 id=\"about-our-team\">About Our team<\/h3>\n<p>We have been working on Flutter since Flutter launched in beta version in 2017. And our team have been putting hundreds and hundreds of hour to experiment and implementation of Flutter. As well as after successful delivery of enterprise and SAAS applications that have been used by more than 500+ businesses around the 119+ countries. Now we are in love with Flutter development and we are very passionate about Flutter development. Now it is something we are trying to give a small contribution to the <a href=\"https:\/\/www.getwidget.dev\/\" rel=\"noreferrer\">Flutter Dev Community.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Design custom Flutter Search bar in Appbar with autocomplete suggestion feature step by step builds with Example code.","protected":false},"author":1,"featured_media":5200,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":"","footnotes":""},"categories":[139],"tags":[],"class_list":{"0":"post-7365","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-flutter","8":"cs-entry"},"_links":{"self":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts\/7365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/comments?post=7365"}],"version-history":[{"count":3,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts\/7365\/revisions"}],"predecessor-version":[{"id":8309,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/posts\/7365\/revisions\/8309"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/media\/5200"}],"wp:attachment":[{"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/media?parent=7365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/categories?post=7365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.getwidget.dev\/blog\/wp-json\/wp\/v2\/tags?post=7365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}