loader_search_bar 1.0.3+3

Loader SearchBar #

This package's been discontinued #

Due to a hacky way this widget uses to display search results, it's become difficult to maintain and add new features. While it won't be developed anymore, you can still fork/use it in your Flutter project. As a replacement, take a look at Flutter framework showSearch method or other community packages.

pub package

Flutter widget integrating search field feature into app bar, allowing to receive query change callbacks and automatically load new data set into ListView. It replaces standard AppBar widget and needs to be placed underneath Scaffold element in the widget tree to work properly.

Loader SearchBar demo

Getting started #

To start using SearchBar insert it in place of an AppBar element in the Scaffold widget. Regardless of the use case, defaultBar named argument has to be specified, which basically is a widget that will be displayed whenever SearchBar is not in activated state:

@override
Widget build(BuildContext context) {
   return Scaffold(
     appBar: SearchBar(
       defaultBar: AppBar(
         leading: IconButton(
           icon: Icon(Icons.menu),
           onPressed: _openDrawer,
         ),
         title: Text('Default app bar title'),
       ),
       ...
     ),
     body: _body,
     drawer: _drawer,
   );
}

Optional attributes #

  • searchHint - hint string being displayed until user inputs any text,
  • initialQuery - query value displayed for the first time in search field,
  • iconified - boolean value indicating way of representing non-activated SearchBar:
    • true if widget should be showed as an action item in defaultBar,
    • false if widget should be merged with defaultBar (only leading icon of the default widget and search input field are displayed in such case),
  • autofocus - boolean value determining if search text field should get focus whenever it becomes visible,
  • autoActive - ,
  • attrs - SearchBarAttrs class instance allowing to specify part of exact values used during widget building (e.g. search bar colors, text size, border radius),
  • controller - SearchBarController object that provides a way of interacing with current state of the widget,
  • searchItem - defining how to build and position search item widget in app bar,
  • overlayStyle - status bar overlay brightness applied when widget is activated.

Query callbacks #

To get notified about user input specify onQueryChanged and/or onQuerySubmitted callback functions that receive current query string as an argument:

appBar: SearchBar(
   ...
   onQueryChanged: (query) => _handleQueryChanged(context, query),
   onQuerySubmitted: (query) => _handleQuerySubmitted(context, query),
),

QuerySetLoader #

By passing QuerySetLoader object as an argument one can additionally benefit from search results being automatically built as ListView widget whenever search query changes:

appBar: SearchBar(
  ...
  loader: QuerySetLoader<Item>(
     querySetCall: _getItemListForQuery,
     itemBuilder: _buildItemWidget,
     loadOnEachChange: true,
     animateChanges: true,
  ),
),

List<Item> _getItemListForQuery(String query) { ... }

Widget _buildItemWidget(Item item) { ... }
  • querySetCall - function transforming search query into list of items being then rendered in ListView (required),
  • itemBuilder - function creating Widget object for received item, called during ListView building for each element of the results set (required),
  • loadOnEachChange - boolean value indicating whether querySetCall should be triggered on each query change; if false query set is loaded once user submits query,
  • animateChanges - determines whether ListView's insert and remove operations should be animated.

SearchItem #

Specifying this parameter allows to customize how search item should be built and positioned in app bar. It can be either action or menu widget. No matter which of these two is picked, two constructor arguments can be passed:

  • builder - function receiving current BuildContext and returning Widget for action or PopupMenuItem for menu item,
  • gravity - can be one of SearchItemGravity values: start, end or exactly. If no arguments are passed, SearchBar will create default item which is search action icon with start gravity.

SearchItem.action

Search action item
appBar: SearchBar(
  // ...
  searchItem: SearchItem.action(
    builder: (_) => Padding(
      padding: EdgeInsets.all(12.0),
      child: Icon(
        Icons.find_in_page,
        color: Colors.indigoAccent,
      ),
    ),
    gravity: SearchItemGravity.exactly(1),
  ),
)

SearchItem.menu

Search menu item
appBar: SearchBar(
  // ...
  searchItem: SearchItem.menu(
    builder: (_) => PopupMenuItem(
      child: Text("Search  🔍"),
      value: "search",
    ),
    gravity: SearchItemGravity.end,
  ),
)

Also, bear in mind that SearchBar will prevent built item widget from receiving tap events and will begin search action rather than that.

[1.0.3]

  • Add initialQuery and autoActive attributes
  • Support interacting with widget's state via SearchBarController
  • Adjust clear query button behavior

[1.0.2]

  • Fix duplicated GlobalKey across multiple pages

[1.0.1] - 09/10/2018

  • Support more adjustable attributes

[1.0.0] - 08/09/2018

  • Release package

[0.0.3] - 08/09/2018

  • Support specifying search item widget and position in AppBar
  • Bug fixes

[0.0.2] - 03/06/2018

  • Update documentation
  • Add dart docs

[0.0.1] - 02/06/2018

  • Implement search bar widget
  • Support query callbacks
  • Support query set loader
  • Include search bar examples

example/README.md

example #

Loader search bar example.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  loader_search_bar: ^1.0.3+3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:loader_search_bar/loader_search_bar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
91
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/SearchBarState.dart. (-2.96 points)

Analysis of lib/src/SearchBarState.dart reported 6 hints, including:

line 97 col 7: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 140 col 11: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 140 col 32: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 147 col 7: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 169 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/QuerySetLoader.dart. (-1 points)

Analysis of lib/src/QuerySetLoader.dart reported 2 hints:

line 26 col 36: This function has a return type of 'List', but doesn't end with a return statement.

line 26 col 57: This function has a return type of 'Widget', but doesn't end with a return statement.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test

Admin