FilterListWidget<T> class

The FilterListWidget is a widget with some filter utilities and callbacks which helps in single/multiple selection from list of data.

The listData should be list of dynamic data which neeeds to filter.

The selectedListData should be subset of listData. The list passed to selectedListData should available in listData.

The choiceChipLabel is a callback which required String value in return. It used this value to display text on choice chip.

The validateSelectedItem used to identifies weather a item is selecte or not.

onItemSearch filter the list on the basis of search field text. It expose search api to permform search operation accoding to requirement. When text change in search text field then return a list of element which contains specific text. if no element found then it should return empty list.

   onItemSearch: (list, text) {
    if (list.any((element) =>
        element.toLowerCase().contains(text.toLowerCase()))) {
      /// return list which contains matches
      return list
          .where((element) =>
              element.toLowerCase().contains(text.toLowerCase()))
          .toList();
    }
  },

The choiceChipBuilder is a builder to design custom choice chip.

The onApplyButtonClick is a callback which return list of all selected items on apply button click. if no item is selected then it will return empty list.

This example shows how to use FilterListWidget

FilterListWidget<String>(
  listData: ["One","Two","Three", "Four","five", "Six","Seven","Eight","Nine","Ten"],
  selectedListData: ["One", "Three", "Four", "Eight", "Nine"],
  hideHeaderText: true,
  height: MediaQuery.of(context).size.height,
  // hideHeaderText: true,
  onApplyButtonClick: (list) {
    Navigator.pop(context, list);
  },
  choiceChipLabel: (item) {
    /// Used to print text on chip
    return item;
  },
  validateSelectedItem: (list, val) {
    ///  identify if item is selected or not
    return list!.contains(val);
  },
  onItemSearch: (list, text) {
    /// When text change in search text field then return list containing that text value
    ///
    ///Check if list has value which matchs to text
    if (list!.any((element) =>
        element.toLowerCase().contains(text.toLowerCase()))) {
      /// return list which contains matches
      return list
          .where((element) =>
              element.toLowerCase().contains(text.toLowerCase()))
          .toList();
    }
    return [];
  },
 )
Inheritance

Constructors

FilterListWidget({Key? key, double? height, double? width, List<T>? listData, required ValidateSelectedItem<T> validateSelectedItem, required LabelDelegate<T> choiceChipLabel, required ItemSearchDelegate<T> onItemSearch, List<T>? selectedListData, double borderRadius = 20, OnApplyButtonClick<T>? onApplyButtonClick, ChoiceChipBuilder? choiceChipBuilder, TextStyle? selectedChipTextStyle, TextStyle? unselectedChipTextStyle, TextStyle? controlButtonTextStyle, TextStyle? applyButtonTextStyle, TextStyle? headerTextStyle, TextStyle? searchFieldTextStyle, String headlineText = "Select", String searchFieldHintText = "Search here", bool hideSelectedTextCount = false, bool hideSearchField = false, bool hideCloseIcon = true, bool? hideHeader = false, bool? hideHeaderText = false, Color? closeIconColor = Colors.black, Color? headerTextColor = Colors.black, Color? applyButonTextBackgroundColor = Colors.blue, Color? backgroundColor = Colors.white, Color? searchFieldBackgroundColor = const Color(0xfff5f5f5), Color? selectedTextBackgroundColor = Colors.blue, Color? unselectedTextbackGroundColor = const Color(0xfff8f8f8), bool? enableOnlySingleSelection = false})
const

Properties

applyButonTextBackgroundColor Color?
final
applyButtonTextStyle TextStyle?
TextStyle for Apply button.
final
backgroundColor Color?
final
borderRadius double
final
choiceChipBuilder ChoiceChipBuilder?
The choiceChipBuilder is a builder to design custom choice chip.
final
choiceChipLabel LabelDelegate<T>
The choiceChipLabel is callback which required String value to display text on choice chip.
final
closeIconColor Color?
final
controlButtonTextStyle TextStyle?
TextStyle for All and Reset button text.
final
enableOnlySingleSelection bool?
if enableOnlySingleSelection is true then it disabled the multiple selection. and enabled the single selection model.
final
hashCode int
The hash code for this object.
no setterinherited
headerTextColor Color?
final
headerTextStyle TextStyle?
TextStyle for header text.
final
headlineText String
final
height double?
final
hideCloseIcon bool
if true then it hides close icon.
final
hideHeader bool?
If true then it hide complete header section.
final
hideHeaderText bool?
If true then it hides the header text.
final
hideSearchField bool
final
hideSelectedTextCount bool
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
listData List<T>?
Pass list containing all data which neeeds to filter
final
onApplyButtonClick OnApplyButtonClick<T>?
The onApplyButtonClick is a callback which return list of all selected items on apply button click. if no item is selected then it will return empty list.
final
onItemSearch ItemSearchDelegate<T>
The onItemSearch is delagate which filter the list on the basis of search field text.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchFieldBackgroundColor Color?
final
searchFieldHintText String
final
searchFieldTextStyle TextStyle?
TextStyle for search field text.
final
selectedChipTextStyle TextStyle?
TextStyle for chip when selected.
final
selectedListData List<T>?
The selectedListData is used to preselect the choice chips. It takes list of object and this list should be subset og listData
final
selectedTextBackgroundColor Color?
final
unselectedChipTextStyle TextStyle?
TextStyle for chip when not selected.
final
unselectedTextbackGroundColor Color?
final
validateSelectedItem ValidateSelectedItem<T>
The validateSelectedItem dentifies weather a item is selecte or not.
final
width double?
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _FilterListWidgetState<T>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited