SearchBar widget to handle most of search cases

Overview

flappy_search_bar

A SearchBar widget handling most of search cases.

Usage

To use this plugin, add flappy_search_bar as a dependency in your pubspec.yaml file.

Example

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SearchBar<Post>(
          searchBarPadding: EdgeInsets.symmetric(horizontal: 10),
          headerPadding: EdgeInsets.symmetric(horizontal: 10),
          listPadding: EdgeInsets.symmetric(horizontal: 10),
          onSearch: _getALlPosts,
          searchBarController: _searchBarController,
          placeHolder: Text("placeholder"),
          cancellationWidget: Text("Cancel"),
          emptyWidget: Text("empty"),
          indexedScaledTileBuilder: (int index) => ScaledTile.count(1, index.isEven ? 2 : 1),
          header: Row(
            children: <Widget>[
              RaisedButton(
                child: Text("sort"),
                onPressed: () {
                  _searchBarController.sortList((Post a, Post b) {
                    return a.body.compareTo(b.body);
                  });
                },
              ),
              RaisedButton(
                child: Text("Desort"),
                onPressed: () {
                  _searchBarController.removeSort();
                },
              ),
              RaisedButton(
                child: Text("Replay"),
                onPressed: () {
                  isReplay = !isReplay;
                  _searchBarController.replayLastSearch();
                },
              ),
            ],
          ),
          onCancelled: () {
            print("Cancelled triggered");
          },
          mainAxisSpacing: 10,
          crossAxisSpacing: 10,
          crossAxisCount: 2,
          onItemFound: (Post post, int index) {
            return Container(
              color: Colors.lightBlue,
              child: ListTile(
                title: Text(post.title),
                isThreeLine: true,
                subtitle: Text(post.body),
                onTap: () {
                  Navigator.of(context).push(MaterialPageRoute(builder: (context) => Detail()));
                },
              ),
            );
          },
        ),
      ),
    );
  }

Try it

A sample app is available to let you try all the features ! :)

Warning

If you want to use a SearchBarController in order to do some sorts or filters, PLEASE put your instance of SearchBarController in a StateFullWidget.

If not, it will not work properly.

If you don't use an instance of SearchBarController, you can keep everything in a StateLessWidget !

Parameters

Name Type Usage Required Default Value
onSearch Future<List> Function(String text) Callback giving you the text to look for and asking for a Future yes -
onItemFound Widget Function(T item, int index) Callback letting you build the widget corresponding to each item yes -
suggestions List Potential fist list of suggestions (when no request have been made) no []
searchBarController SearchBarController Enable you to sort and filter your list no default controller
searchBarStyle SearchBarStyle Syle to customize SearchBar no default values on bottom tab
buildSuggestions Widget Function(T item, int index) Callback called to let you build Suggestion item (if not provided, the suggestion will have the same layout as the basic item) no null
minimumChars int Minimum number of chars to start querying no 3
onError Function(Error error) Callback called when an error occur runnning Future no null
debounceDuration Duration Debounce's duration no Duration(milliseconds: 500)
loader Widget Widget that appears when Future is running no CircularProgressIndicator()
emptyWidget Widget Widget that appears when Future is returning an empty list no SizedBox.shrink()
icon Widget Widget that appears on left of the SearchBar no Icon(Icons.search)
hintText String Hint Text no ""
hintStyle TextStyle Hint Text style no TextStyle(color: Color.fromRGBO(142, 142, 147, 1))
iconActiveColor Color Color of icon when active no Colors.black
textStyle TextStyle TextStyle of searched text no TextStyle(color: Colors.black)
cancellationWidget Widget Widget shown on right of the SearchBar no Text("Cancel")
onCancelled VoidCallback Callback triggered on cancellation's button click no null
crossAxisCount int Number of tiles on cross axis (Grid) no 2
shrinkWrap bool Wether list should be shrinked or not (take minimum space) no true
scrollDirection Axis Set the scroll direction no Axis.vertical
mainAxisSpacing int Set the spacing between each tiles on main axis no 10
crossAxisSpacing int Set the spacing between each tiles on cross axis no 10
indexedScaledTileBuilder IndexedScaledTileBuilder Builder letting you decide how much space each tile should take no (int index) => ScaledTile.count(1, index.isEven ? 2 : 1)
searchBarPadding EdgeInsetsGeometry Set a padding on the search bar no EdgeInsets.symmetric(horizontal: 10)
headerPadding EdgeInsetsGeometry Set a padding on the header no EdgeInsets.symmetric(horizontal: 10)
listPadding EdgeInsetsGeometry Set a padding on the list no EdgeInsets.symmetric(horizontal: 10)

SearchBar default SearchBarStyle

Name Type default Value
backgroundColor Color Color.fromRGBO(142, 142, 147, .15)
padding EdgeInsetsGeometry EdgeInsets.all(5.0)
borderRadius BorderRadius BorderRadius.all(Radius.circular(5.0))})
Comments
  • Provide more options to search bar users

    Provide more options to search bar users

    Overview of Changes

    • Moved SearchBarStyle into flappy_search_bar.dart. This enables users of the search bar to use SearchBar while defining their own SearchBarStyle without the need for an additional import statement.
    • Added new options in SearchBarStyle
      • surroundingColor: Color of the search bar area, including the optional leading and trailing widgets
      • searchBarHeight: Allows users to set the height of the search bar
        • Closes #12
    • Added new options in SearchBar
      • centerEmptyWidget: Whether the empty widget should be centered if shown
      • useCancellationWidget: Indicates whether the user wants to use the cancellation widget
      • enableSuggestions: Whether the keyboard should show dictionary suggestions
      • searchOnlyOnSubmit: Whether search should only have when the searched button is pressed.
        • The done button on the keyboard has been changed to search.
        • Closes #14
      • contentPadding: The padding on the searched result
      • leading: Allow users to use a leading widget
        • Closes #13
      • trailing: Allow users to use a trailing widget
      • autoFocus: Whether the search bar should get focus on first launch
        • Closes #15
      • focusNode: Allows users to use pass in their own FocusNode
        • Closes #9
      • textEditingController: Allows users to pass in their own TextEditingController
        • Closes #11

    Misc Changes

    • Upgraded the dart sdk min version to 2.3.0 to use if statements in widgets.
    opened by kylerwsm 17
  • How can i clear the search text editing controller and results?

    How can i clear the search text editing controller and results?

    Hello, i want to clear the search word (text editing controller) and clear the result list, when i tap on a result from that list (reset the searchBar). Is there any way to implement this?

    Thanks!

    opened by movieator 5
  • Feature Request: Expose Cancel Button onTap Listener

    Feature Request: Expose Cancel Button onTap Listener

    I was wondering if you'd be able to expose a way for people to react to a tap event on the Cancel button that animates in after performing a search? I have a screen on which this would be REALLY useful. Awesome plugin by the way!!

    Thanks Scott

    opened by gscottschulz 5
  • Created injectSearch method into SearchBarController

    Created injectSearch method into SearchBarController

    Anyone can now inject search text into the search bar using the SearchBarController you provided by adding new method injectSearch that accepts a search text and a search Function for greater modifiability.

    Use Cases:

    Devs now can add buttons into the placeholder screen for search shortcuts or even add a QR / Barcode reader buttons that obviously read QR / Bar codes and inject the scanned values into the search field to automatically search after the user acquire the data from the reader.

    opened by MohamedEL-Torky 4
  • Textfield Cursor Jitters

    Textfield Cursor Jitters

    I noticed that when focusing in the search bar or moving the cursor into the typed string and back to the start the cursor will jump or change position

    It’s really slight but it’s noticeable. Does anyone know how to fix it?

    opened by tyirvine 2
  • Inicial Data

    Inicial Data

    This plugin is very similar to the search box on the google photos page. But I'm not sure why we don't have a property to charge the initial Data. So the present data since the beginning and then perform some search on that initial Data.

    opened by danieramiz 2
  • Type 'Future<dynamic>' is not a subtype of type 'FutureOr<List<dynamic>>' in type cast

    Type 'Future' is not a subtype of type 'FutureOr>' in type cast

    An error seems to keep being returned despite returning a valid Future<List<T>> type in the onSearch method

    I/flutter (12750): ‼️ SEVERE 2021-06-05 11:22:36.333049 [caller info not available] #0      SearchBarController._search (**package:flappy_search_bar_ns/flappy_search_bar_ns.dart:63:46**)
    I/flutter (12750): #1      _SearchBarState._onTextChanged.<anonymous closure> (package:flappy_search_bar_ns/flappy_search_bar_ns.dart:314:29)
    I/flutter (12750): #2      _SearchBarState._onTextChanged.<anonymous closure> (package:flappy_search_bar_ns/flappy_search_bar_ns.dart:312:48)
    I/flutter (12750): #3      _rootRun (dart:async/zone.dart:1346:47)
    I/flutter (12750): #4      _CustomZone.run (dart:async/zone.dart:1258:19)
    I/flutter (12750): #5      _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
    I/flutter (12750): #6      _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
    I/flutter (12750): #7      _rootRun (dart:async/zone.dart:1354:13)
    I/flutter (12750): #8      _CustomZone.run (dart:async/zone.dart:1258:19)
    I/flutter (12750): #9      _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1186:23)
    I/flutter (12750): #10     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
    I/flutter (12750): #11     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
    I/flutter (12750): #12     
    
    opened by nathanogunleye 1
  • parameter indexedScaledTileBuilder cannot use

    parameter indexedScaledTileBuilder cannot use

    iwant to use parameter indexedScaledTileBuilder in flappy search bar, but its return an error "The argument for the named parameter 'indexedScaledTileBuilder' was already specified."

    please fix it

    opened by marvin46 1
  • the result seach show only one element

    the result seach show only one element

    Hi,

    In my search at I find several elements, but itemFound shows only the first one on the list. Could help?

    thanks

    Future<List<Empregado>> _getALlPosts(String text) async {
        List<Empregado> list = empregados
            .where((element) =>
                element.name.toUpperCase().contains(text.toUpperCase()))
            .toList();
        print("employees quantity ${list.length}");
        return list;
      }
    
    opened by robertoltrocha 1
  • Expouse _searchQueryController so we can inject search data

    Expouse _searchQueryController so we can inject search data

    I'm trying to add a barcode scanner into the search screen your package provided using placeholder property to add the scan barcode button but after I get the result from the scanned barcode I can not inject it into the search bar.

    Screenshot_1581596173

    opened by MohamedEL-Torky 1
  • TextEditingController - SearchBarController.search()

    TextEditingController - SearchBarController.search()

    Implementation of TextEditingController would be great. With the help of a possible SearchBarController.search() function, we can execute search function from outside of the SearchBar widget.

    opened by kasmurat 0
  • onValidation parameter missing ?

    onValidation parameter missing ?

    Hello,

    First I wanted to say that this package is pretty cool, good job and thank you for making it !

    I was wondering if it is actually possible to display a particular widget when the user tap on the "validation button" of his keyboard. I double checked the documentation but I didn't find anything. I'm sorry if I missed something.

    Thank you in advance for your answer.

    opened by MarkAlexanderDev 0
  • No named parameter with the name 'restorationId'

    No named parameter with the name 'restorationId'

    when build app this error appear: No named parameter with the name 'restorationId' Full: /Pub/Cache/hosted/pub.dartlang.org/pub_cache-0.2.3/hosted/pub.dev/flutter_staggered_grid_view-0.3.3/lib/src/widgets/staggered_grid_view.dart:425:11: Error: No named parameter with the name 'restorationId'. restorationId: restorationId,

    this error appear after new update of package flutter_staggered_grid_view to 0.3.3 Add support for state restoration.

    To temporarily solve this problem I added the following in pubspec.yaml file dependency_overrides: flutter_staggered_grid_view: 0.3.2

    DO NOT ADD ^ to lib version number

    opened by mohmdezeldeen 0
  • Add autofocus property to SearchBar

    Add autofocus property to SearchBar

    Hey, thanks so much for creating this widget. It's perfect for what I need!

    In this PR, I expose the "autofocus" property of the underlying TextField by adding it as a property of the SearchBar class and passing it through.

    I just tested it out on the app I'm using this on, and it seems to work fine. When I navigate to the page with autofocus: true, the keyboard immediately opens, ready to type. 🙂

    Let me know if you think this is a useful addition! Feel free to request changes.

    Thanks!

    opened by stephengrice 0
  • search suggestion

    search suggestion

    How to create a dynamic search suggestion by the typed text on the flappy search bar ? i've read inside the flappy-search_bart.dart code, there's only a static search suggestion,

    i need to get typed text on search bar to create a dynamic search suggestion

    please tell me the way

    opened by marvin46 0
Releases(v1.3.1)
Owner
Smart&Soft
The software agency which stimulates your mobile experience.
Smart&Soft
Help developers build the most beautiful search bar🍹.

fsearch Help developers build the most beautiful search bar ?? . [FSearch] provides developers with a one-stop search bar construction service. Suppor

Fliggy Mobile 70 Oct 28, 2022
Github-search - Allows users to search users on github Uses flutter

Github Search Github Search is a cross-platform mobile application powered by Flutter Framework and Github API. The application was built with simplic

Saul 3 Sep 13, 2022
A google browser clone which is made by using flutter and fetching the google search api for the search requests.

google_clone A new Flutter project. Project Preview Getting Started This project is a starting point for a Flutter application. A few resources to get

Priyam Soni 2 May 31, 2022
Starlight search bar - Starlight search bar with flutter

starlight_search_bar If you find the easiest way to search your item, this is fo

Ye Myo Aung 1 Apr 20, 2022
This repository was created to provide the basics of the Dart programming language and Its use cases.

dart-exercises A collection of source code of the Dart Programming language. How does this repository works? Clone / Fork this repository to make your

Technosoft Labs 2 Oct 28, 2021
A Dart EPUB parser built from the ground up, and designed to support a variety of use cases and custom

A Dart EPUB parser built from the ground up, and designed to support a variety of use cases and custom implementations such as on-device caching and serving content from a server.

getBoolean 11 Nov 3, 2022
A Dart package to handle HTTP services

http_services A package to support the creation of Http services in a Dart application. Features convenient methods to perform HTTP requests disposing

Antonello Galipò 5 Jul 27, 2021
A package help you to make api call and handle error faster, also you can check for internet before call api.

http_solver ##not for production use, only for learning purpose. A package help you to make api call and handle error faster, also you can check for i

Abdelrahman Saed 1 Jun 18, 2020
⚡ Cache Manager A tidy utility to handle cache of your flutter app like a Boss.

⚡ Cache Manager A tidy utility to handle cache of your flutter app like a Boss. It provides support for both iOS and Android platforms (offcourse). ??

Abhishek Chavhan 10 Oct 25, 2022
A library to easily handle sequential queueing of futures in dart.

queue Easily queue futures and await their values. This library allows you to send a future to central queue. The queue will execute the futures in th

Ryan Knell 38 Jan 4, 2023
A showcase of the most common Flutter animation APIs.

Flutter Animations Gallery This project is a showcase of the most common Flutter animation APIs. Preview Also available as a Flutter web demo. Setting

Andrea Bizzotto 136 Dec 10, 2022
Flutter The lightest, easiest and most convenient route management!

Language: English | 中文简体 nav_router nav_router is the simplest / lightweight / convenient routing management solution for flutter. It supports various

FlutterCandies 104 Jan 3, 2023
A most easily usable Duolingo API wrapper in Dart. Duolingo4D is an open-sourced Dart library.

A most easily usable Duolingo API wrapper in Dart! 1. About Duolingo4D Duolingo4D is an open-sourced Dart library. With Duolingo4D, you can easily int

Kato Shinya 18 Oct 17, 2022
A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

A most easily usable cookie management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use SweetCookieJar 1

Kato Shinya 9 Oct 27, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Kato Shinya 1 Dec 13, 2021
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Ionicfirebaseapp 3.7k Jan 1, 2023
A most easily usable RESAS API wrapper in Dart. With this library, you can easily integrate your application with the RESAS API.

A most easily usable RESAS API wrapper library in Dart! 1. About 1.1. What Is RESAS? 1.2. Introduction 1.2.1. Install Library 1.2.2. Import It 1.2.3.

Kato Shinya 2 Apr 7, 2022
A most easily usable JSON wrapper library in Dart

A most easily usable JSON response wrapper library in Dart! 1. About 1.1. Introd

Kato Shinya 2 Jan 4, 2022
A most easily usable improvement rate calculator library in Dart.

A most easily usable improvement rate calculator library in Dart. With ImprovementRate, you can easily calculate improvement rate on your application.

Kato Shinya 1 Dec 27, 2021