FilterListDialog class

The FilterListDialog.display() is a Dialog 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. The useSafeArea argument is used to indicate if the dialog should only display in 'safe' areas of the screen not used by the operating system (see SafeArea for more details). It is true by default, which means the dialog will not overlap operating system areas. If it is set to false the dialog will only be constrained by the screen size. It can not be null.

The useRootNavigator argument is used to determine whether to push the dialog to the Navigator furthest from or nearest to the given context. By default, useRootNavigator is true and the dialog route created by this method is pushed to the root navigator. It can not be null.

The routeSettings argument is passed to showGeneralDialog, see RouteSettings for details.

This example shows how to use FilterListDialog

void _openFilterDialog() async {
  await FilterListDialog.display<String>(context,
      listData: ["One", "Two", "Three", "Four","five","Six","Seven","Eight","Nine","Ten"],
      selectedListData: ["One", "Three", "Four","Eight","Nine"],
      choiceChipLabel: (item) {
        return item;
      },
      validateSelectedItem: (list, val) {
        return list!.contains(val);
      },
      onItemSearch: (list, text) {
        if (list!.any((element) =>
            element.toLowerCase().contains(text.toLowerCase()))) {
          /// return list which contains text matches
          return list
              .where((element) =>
                  element.toLowerCase().contains(text.toLowerCase()))
              .toList();
        }
        return [];
      },
      height: 480,
      borderRadius: 20,
      headlineText: "Select Count",
      searchFieldHintText: "Search Here",
      onApplyButtonClick: (list) {
        if (list != null) {
          setState(() {
           var selectedList = List.from(list);
          });
          Navigator.pop(context);
        }
      });
}

Constructors

FilterListDialog()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

display<T>(dynamic context, {required List<T> listData, List<T>? selectedListData, required LabelDelegate<T> choiceChipLabel, required ValidateSelectedItem<T> validateSelectedItem, required ItemSearchDelegate<T> onItemSearch, required OnApplyButtonClick<T> onApplyButtonClick, double? height, double? width, double borderRadius = 20, String headlineText = "Select", String searchFieldHintText = "Search here", bool hideSelectedTextCount = false, bool hideSearchField = false, bool hideCloseIcon = false, bool hideheader = false, bool hideHeaderText = false, Color closeIconColor = Colors.black, bool barrierDismissible = true, bool useSafeArea = true, bool useRootNavigator = true, RouteSettings? routeSettings, bool enableOnlySingleSelection = false, Color backgroundColor = Colors.white, Color searchFieldBackgroundColor = const Color(0xfff5f5f5), Color applyButonTextBackgroundColor = Colors.blue, TextStyle? selectedChipTextStyle, TextStyle? unselectedChipTextStyle, TextStyle? controlButtonTextStyle, TextStyle? applyButtonTextStyle, TextStyle? headerTextStyle, TextStyle? searchFieldTextStyle, ChoiceChipBuilder? choiceChipBuilder}) Future