{"id":1124,"date":"2023-10-12T12:15:38","date_gmt":"2023-10-12T12:15:38","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1124"},"modified":"2023-10-12T12:15:40","modified_gmt":"2023-10-12T12:15:40","slug":"adding-a-search-or-filter-feature-to-your-flutter-app","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/","title":{"rendered":"Adding a Search or Filter Feature to Your Flutter App"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png\" alt=\"\" class=\"wp-image-1126\" width=\"408\" height=\"229\"\/><\/figure>\n\n\n\n<p>Filtering and searching are essential functionalities in many mobile apps. we&#8217;ll explore how to implement a search or filter feature in a Flutter app.<\/p>\n\n\n\n<p>Let&#8217;s create a new Flutter project to implement the search or filter feature. Open your terminal and run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>flutter create search_filter_app\r\ncd search_filter_app\r\n<\/code><\/pre>\n\n\n\n<p>This will create a new Flutter project named &#8220;search_filter_app&#8221; and change your working directory to the project folder.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Creating the User Interface<\/h4>\n\n\n\n<p>To keep things simple, we will create a list of items with a search bar at the top. Follow these steps to create the user interface:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the <code>lib\/main.dart<\/code> file.<\/li>\n\n\n\n<li>Replace the contents with the following code:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:flutter\/material.dart';\r\n\r\nvoid main() {\r\n  runApp(SearchFilterApp());\r\n}\r\n\r\nclass SearchFilterApp extends StatelessWidget {\r\n  @override\r\n  Widget build(BuildContext context) {\r\n    return MaterialApp(\r\n      title: 'Search and Filter',\r\n      home: SearchFilterScreen(),\r\n    );\r\n  }\r\n}\r\n\r\nclass SearchFilterScreen extends StatefulWidget {\r\n  @override\r\n  _SearchFilterScreenState createState() => _SearchFilterScreenState();\r\n}\r\n\r\nclass _SearchFilterScreenState extends State&lt;SearchFilterScreen> {\r\n  final List&lt;String> items = List.generate(50, (index) => 'Item $index');\r\n  List&lt;String> filteredItems = &#91;];\r\n\r\n  void filterItems(String query) {\r\n    filteredItems = items\r\n        .where((item) => item.toLowerCase().contains(query.toLowerCase()))\r\n        .toList();\r\n    setState(() {});\r\n  }\r\n\r\n  @override\r\n  Widget build(BuildContext context) {\r\n    return Scaffold(\r\n      appBar: AppBar(\r\n        title: Text('Search and Filter'),\r\n      ),\r\n      body: Column(\r\n        children: &lt;Widget>&#91;\r\n          Padding(\r\n            padding: const EdgeInsets.all(16.0),\r\n            child: TextField(\r\n              onChanged: filterItems,\r\n              decoration: InputDecoration(\r\n                labelText: 'Search',\r\n                border: OutlineInputBorder(\r\n                  borderRadius: BorderRadius.circular(12),\r\n                ),\r\n              ),\r\n            ),\r\n          ),\r\n          Expanded(\r\n            child: ListView.builder(\r\n              itemCount: filteredItems.isNotEmpty ? filteredItems.length : items.length,\r\n              itemBuilder: (context, index) {\r\n                return ListTile(\r\n                  title: Text(filteredItems.isNotEmpty ? filteredItems&#91;index] : items&#91;index]),\r\n                );\r\n              },\r\n            ),\r\n          ),\r\n        ],\r\n      ),\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"591\" height=\"133\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-14.png\" alt=\"\" class=\"wp-image-1125\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-14.png 591w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-14-300x68.png 300w\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In this code, we create a simple Flutter app with a search bar and a list of items. The <code>filterItems<\/code> method is used to filter the items based on the user&#8217;s input. The filtered items are displayed in a <code>ListView<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Filtering or Searching Data<\/h4>\n\n\n\n<p>In the code above, the <code>filterItems<\/code> method is responsible for filtering the items based on the search query. It uses the <code>where<\/code> method to filter the items and converts them into a list. The <code>setState<\/code> method is called to trigger a rebuild of the UI with the updated filtered items.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Displaying Filtered Results<\/h4>\n\n\n\n<p>The filtered results are displayed in a <code>ListView.builder<\/code>. The <code>itemCount<\/code> property is set based on whether there are filtered items. If there are filtered items, the count is set to the number of filtered items; otherwise, it&#8217;s set to the total number of items.<\/p>\n\n\n\n<p>The filtered items or the original items are displayed as <code>ListTile<\/code> widgets in the list.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Styling the Search Bar<\/h4>\n\n\n\n<p>In the code, we&#8217;ve styled the search bar by providing it with rounded borders. We set the <code>borderRadius<\/code> property to achieve the rounded appearance. Adjust the <code>borderRadius<\/code> value to control the roundness of the corners.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Testing and Running the App<\/h4>\n\n\n\n<p>To test the app, open your terminal and navigate to your project directory. Then, run the app with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>flutter run\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Filtering and searching are essential functionalities in many mobile apps. we&#8217;ll explore how to implement a search or filter feature in a Flutter app. Let&#8217;s create a&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[425,426,428,427],"class_list":["post-1124","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-adding-a-search-or-filter-feature-to-your-flutter-app","tag-filter-feature","tag-flutter-app","tag-search"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Adding a Search or Filter Feature to Your Flutter App - DevOps Support<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding a Search or Filter Feature to Your Flutter App - DevOps Support\" \/>\n<meta property=\"og:description\" content=\"Filtering and searching are essential functionalities in many mobile apps. we&#8217;ll explore how to implement a search or filter feature in a Flutter app. Let&#8217;s create a...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps Support\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-12T12:15:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-12T12:15:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png\" \/>\n<meta name=\"author\" content=\"Avinash kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Avinash kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\"},\"author\":{\"name\":\"Avinash kumar\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/ee29c62455ded10b2424fb9ca585e347\"},\"headline\":\"Adding a Search or Filter Feature to Your Flutter App\",\"datePublished\":\"2023-10-12T12:15:38+00:00\",\"dateModified\":\"2023-10-12T12:15:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\"},\"wordCount\":331,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png\",\"keywords\":[\"Adding a Search or Filter Feature to Your Flutter App\",\"Filter Feature\",\"Flutter App\",\"Search\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\",\"url\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\",\"name\":\"Adding a Search or Filter Feature to Your Flutter App - DevOps Support\",\"isPartOf\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png\",\"datePublished\":\"2023-10-12T12:15:38+00:00\",\"dateModified\":\"2023-10-12T12:15:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/ee29c62455ded10b2424fb9ca585e347\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage\",\"url\":\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png\",\"contentUrl\":\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png\",\"width\":299,\"height\":168},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.devopssupport.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding a Search or Filter Feature to Your Flutter App\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/#website\",\"url\":\"https:\/\/www.devopssupport.in\/blog\/\",\"name\":\"DevOps Support\",\"description\":\"DevOps Support | DevSecOps Support | SRE Support | MLOps SRE Support\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.devopssupport.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/ee29c62455ded10b2424fb9ca585e347\",\"name\":\"Avinash kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/db01f522798b98f8f474a1dfdd200df1c0e7ada232088d7a8192e14919e4de0a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/db01f522798b98f8f474a1dfdd200df1c0e7ada232088d7a8192e14919e4de0a?s=96&d=mm&r=g\",\"caption\":\"Avinash kumar\"},\"sameAs\":[\"www.linkedin.com\/in\/avinash-kumar-150791240\"],\"url\":\"https:\/\/www.devopssupport.in\/blog\/author\/avinash\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding a Search or Filter Feature to Your Flutter App - DevOps Support","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/","og_locale":"en_US","og_type":"article","og_title":"Adding a Search or Filter Feature to Your Flutter App - DevOps Support","og_description":"Filtering and searching are essential functionalities in many mobile apps. we&#8217;ll explore how to implement a search or filter feature in a Flutter app. Let&#8217;s create a...","og_url":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/","og_site_name":"DevOps Support","article_published_time":"2023-10-12T12:15:38+00:00","article_modified_time":"2023-10-12T12:15:40+00:00","og_image":[{"url":"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png","type":"","width":"","height":""}],"author":"Avinash kumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Avinash kumar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#article","isPartOf":{"@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/"},"author":{"name":"Avinash kumar","@id":"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/ee29c62455ded10b2424fb9ca585e347"},"headline":"Adding a Search or Filter Feature to Your Flutter App","datePublished":"2023-10-12T12:15:38+00:00","dateModified":"2023-10-12T12:15:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/"},"wordCount":331,"commentCount":0,"image":{"@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png","keywords":["Adding a Search or Filter Feature to Your Flutter App","Filter Feature","Flutter App","Search"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/","url":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/","name":"Adding a Search or Filter Feature to Your Flutter App - DevOps Support","isPartOf":{"@id":"https:\/\/www.devopssupport.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage"},"image":{"@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png","datePublished":"2023-10-12T12:15:38+00:00","dateModified":"2023-10-12T12:15:40+00:00","author":{"@id":"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/ee29c62455ded10b2424fb9ca585e347"},"breadcrumb":{"@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#primaryimage","url":"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png","contentUrl":"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-15.png","width":299,"height":168},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopssupport.in\/blog\/adding-a-search-or-filter-feature-to-your-flutter-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopssupport.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Adding a Search or Filter Feature to Your Flutter App"}]},{"@type":"WebSite","@id":"https:\/\/www.devopssupport.in\/blog\/#website","url":"https:\/\/www.devopssupport.in\/blog\/","name":"DevOps Support","description":"DevOps Support | DevSecOps Support | SRE Support | MLOps SRE Support","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopssupport.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/ee29c62455ded10b2424fb9ca585e347","name":"Avinash kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopssupport.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/db01f522798b98f8f474a1dfdd200df1c0e7ada232088d7a8192e14919e4de0a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/db01f522798b98f8f474a1dfdd200df1c0e7ada232088d7a8192e14919e4de0a?s=96&d=mm&r=g","caption":"Avinash kumar"},"sameAs":["www.linkedin.com\/in\/avinash-kumar-150791240"],"url":"https:\/\/www.devopssupport.in\/blog\/author\/avinash\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=1124"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1124\/revisions"}],"predecessor-version":[{"id":1127,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1124\/revisions\/1127"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}