• Stars
    star
    195
  • Rank 192,887 (Top 4 %)
  • Language
    Dart
  • License
    BSD 2-Clause "Sim...
  • Created about 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

filterList is a flutter package which provide utility to search/filter data from provided dynamic list.

filter_list

pub package Likes Popularity Pub points Hits GitHub stars GitHub forks

FilterList is a flutter package which provide utility to search/filter on the basis of single/multiple selection from provided dynamic list.

Download Demo App GitHub All Releases

Getting Started

  1. Add library to your pubspec.yaml
dependencies:
  filter_list: ^<latest_version>
  1. Import library in dart file
import 'package:filter_list/filter_list.dart';
  1. Create a list of Strings / dynamic object
class User {
  final String? name;
  final String? avatar;
  User({this.name, this.avatar});
}

List<User> userList = [
 User(name: "Jon", avatar: ""),
  User(name: "Lindsey ", avatar: ""),
  User(name: "Valarie ", avatar: ""),
  User(name: "Elyse ", avatar: ""),
  User(name: "Ethel ", avatar: ""),
  User(name: "Emelyan ", avatar: ""),
  User(name: "Catherine ", avatar: ""),
  User(name: "Stepanida  ", avatar: ""),
  User(name: "Carolina ", avatar: ""),
  User(name: "Nail  ", avatar: ""),
  User(name: "Kamil ", avatar: ""),
  User(name: "Mariana ", avatar: ""),
  User(name: "Katerina ", avatar: ""),
];

Filter list offer 3 ways to filter data from list

  • FilterListDialog
  • FilterListWidget
  • FilterListDelegate

Below is a example of using filter list widgets with minimal code however there is a lot more inside the widget for you to fully customize the widget.

How to use FilterListDialog

1. Create a function and call FilterListDialog.display

  void openFilterDialog() async {
    await FilterListDialog.display<User>(
      context,
      listData: userList,
      selectedListData: selectedUserList,
      choiceChipLabel: (user) => user!.name,
      validateSelectedItem: (list, val) => list!.contains(val),
      onItemSearch: (user, query) {
        return user.name!.toLowerCase().contains(query.toLowerCase());
      },
      onApplyButtonClick: (list) {
        setState(() {
          selectedUserList = List.from(list!);
        });
        Navigator.pop(context);
      },
    );
  }

If Apply button is pressed without making any selection it will return empty list of items.

2. Call openFilterDialog function on button tap to display filter dialog

@override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: openFilterDialog,
        child: Icon(Icons.add),
      ),
      body: selectedUserList == null || selectedUserList!.length == 0
          ? Center(child: Text('No user selected'))
          : ListView.builder(
              itemBuilder: (context, index) {
                return ListTile(
                  title: Text(selectedUserList![index].name!),
                );
              },
              itemCount: selectedUserList!.length,
            ),
    );
  }

How to use FilterListWidget.

class FilterPage extends StatelessWidget {
  const FilterPage({Key? key, this.selectedUserList})
      : super(key: key);
  final List<User>? selectedUserList;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FilterListWidget<User>(
        listData: userList,
        selectedListData: selectedUserList,
        onApplyButtonClick: (list) {
          // do something with list ..
        },
        choiceChipLabel: (item) {
          /// Used to display text on chip
          return item!.name;
        },
        validateSelectedItem: (list, val) {
          ///  identify if item is selected or not
          return list!.contains(val);
        },
        onItemSearch: (user, query) {
          /// When search query change in search bar then this method will be called
          ///
          /// Check if items contains query
          return user.name!.toLowerCase().contains(query.toLowerCase());
        },
      ),
    );
  }
}

How to use FilterListDelegate.

Create a function and call FilterListDelegate.open() on button tap.

 void openFilterDelegate() async {
   await FilterListDelegate.open<User>(
      context: context,
      list: userList,
      onItemSearch: (user, query) {
        return user.name!.toLowerCase().contains(query.toLowerCase());
      },
      tileLabel: (user) => user!.name,
      emptySearchChild: Center(child: Text('No user found')),
      searchFieldHint: 'Search Here..',
      onApplyButtonClick: (list) {
        // Do something with selected list
      },
    );
  }

Screenshots

Empty screen FilterListDialog Selected chip Result from dialog

Customized Dialog Header

Customized Choice chip

FilterListWidget

Default Customized customized

FilterListDelegate

Single selection Multiple selection Multiple selection
Search through list Customized Tile

Parameters

Parameter Type Description
height double Set height of filter dialog.
width double Set width of filter dialog.
hideCloseIcon bool Hide close Icon.
hideHeader bool Hide complete header section from filter dialog.
headerCloseIcon Widget Widget to close the dialog.
hideSelectedTextCount bool Hide selected text count.
hideSearchField bool Hide search text field.
headlineText String Set header text of filter dialog.
backgroundColor Color Set background color of filter color
listData List<T>() Populate filter dialog with text list.
selectedListData List<T>() Marked selected text in filter dialog.
choiceChipLabel String Function(T item) Display text on choice chip.
validateSelectedItem bool Function(List<T>? list, T item) Identifies weather a item is selected or not
onItemSearch List<T> Function(List<T>? list, String text) Perform search operation and returns filtered list
choiceChipBuilder Widget Function(BuildContext context, T? item, bool? isSelected) The choiceChipBuilder is a builder to design custom choice chip.
onApplyButtonClick Function(List<T> list) Returns list of items when apply button is clicked
validateRemoveItem List<T> Function(List<T>? list, T item) Function Delegate responsible for delete item from list
resetButtonText String Reset button text to customize or translate
allButtonText String All button text to customize or translate
selectedItemsText String Selected items text to customize or translate
controlButtons List<ControlButtonType> configure which control button needs to be display on bottom of dialog along with 'Apply' button.
insetPadding EdgeInsets The amount of padding added to the outside of the dialog.
themeData FilterListThemeData Configure theme of filter dialog and widget.
choiceChipTheme ChoiceChipThemeData Configure theme of choice chip.
controlButtonBarTheme ControlButtonBarThemeData Configure theme of control button bar
controlButtonTheme ControlButtonThemeData Configure theme of control button.
headerTheme HeaderThemeData Configure theme of filter header.

T can be a String or any user defined Model

Other Flutter packages

Name Stars Pub
Empty widget GitHub stars pub package
Add Thumbnail GitHub stars pub package
Country Provider GitHub stars pub package

Pull Requests

I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request.

Created & Maintained By

Sonu Sharma (Twitter) (Youtube) (Insta) Twitter Follow

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of ☕

Visitors Count

Loading

More Repositories

1

flutter_twitter_clone

Fully functional Twitter clone built in flutter framework using Firebase realtime database and storage
Dart
3,429
star
2

flutter_ecommerce_app

E-Commerce App built in flutter
Dart
2,816
star
3

flutter_smart_course

Smart course app built in flutter.
Dart
690
star
4

flutter_login_signup

Basic login and signup screen designed in flutter
Dart
608
star
5

flutter_healthcare_app

Helthcare app built in flutter
Dart
439
star
6

flutter_wallet_app

Wallet app built in flutter
Dart
314
star
7

flutter_pokedex

A digital encyclopedia of Pokemon .
Dart
300
star
8

flutter_news_app

A Simple News App built with Flutter.
Dart
280
star
9

flutter_smart_home_app

Smart home app designed in flutter
Dart
151
star
10

flutter-GitConnect

A Github mobile app built in flutter
Dart
145
star
11

flutter_yatch_booking

Sample yatch booking app designed in flutter
Dart
124
star
12

flutter_SoftUI_watchApp

Basic watch app designed in flutter using soft UI.
Dart
91
star
13

flutter_commun_app

A social media platform where you can build your own community.
Dart
70
star
14

empty_widget

Custom_Empty widget is flutter plugin which is designed to notify user about some event.
Dart
70
star
15

flutter_octo_job_search

Octo Job Search app is a job search app built in flutter framework.
Dart
62
star
16

flutter_plugin_add_thumbnail

Flutter plugin to add thumbnail from given link.
Dart
49
star
17

flutter_mentor_app

Mentor app is built in flutter.
Dart
41
star
18

flutter_job_portal

Dart
37
star
19

flutter_spacexopedia

Flutter app which provide info about space projects of SpaceX company.
Dart
30
star
20

flutter_analog_clock

Analog clock app designed for Flutter Clock Challenge Dec 2019
Dart
27
star
21

FlutterApp

Flutter Food service provider app created from scratch.
Dart
23
star
22

country_provider

A flutter plugin to provide information about countries.
Dart
22
star
23

flutter_chat_app

Chat app built in flutter framework
Dart
21
star
24

pulse

Streamline your work with our all-in-one knowledge, doc, and project management system.
JavaScript
21
star
25

flutter_Planet

Planet info app built in flutter
Dart
17
star
26

unsplash-image-picker

React library to search and select photos from Unsplash
TypeScript
15
star
27

30DaysOfKotlinChallenge

30 Days of Kotlin with Google Developers
Kotlin
14
star
28

flutter_facegram

Facegram app built in flutter framework.
Dart
13
star
29

react-instagram

Instagram clone built in React.
JavaScript
13
star
30

meta-toolkit

Generate meta tags or Preview how your webpage will look on social media
TypeScript
12
star
31

flutter_hack20_cyber_theme

Flutter project submission in flutter hackathon organized by flutter community.
Dart
11
star
32

app_feedback

A Flutter package for getting app feedback from users.
Dart
11
star
33

SwiftUI_iDine_App

IDine app is is a restaurant app that lists items in a menu and helps folks place orders.
Swift
10
star
34

SwiftUI_Landmark_App

Landmark app built in SwiftUI
Swift
8
star
35

Flutter_ml_Vision

Use of FirebaseMLVision library to detect faces in image.
Dart
8
star
36

TheAlphamerc

7
star
37

react-octo-job-search-003

Job Search App created in react.js
JavaScript
6
star
38

flutter_gameTv_app

Dart
6
star
39

SwiftUI_RGBullsEye

RGBullsEye is color vision game app built in SwiftUI
Swift
6
star
40

wordify

Dictionary app built with Nextjs
TypeScript
5
star
41

Events

Event management project
C#
3
star
42

writewise

Blog Template built with Next Js using Notion Content
TypeScript
3
star
43

react-signup-design-001

A dribbble design replicated in react
CSS
3
star
44

react-tenor-gif-picker

React library to search GIF from Tenor
TypeScript
3
star
45

Our-Rights

C#
2
star
46

PharmecyManagement

Small Project on pharmacy management developed in Asp .Net MVC
JavaScript
2
star
47

IAudioApp

Play Music app
Java
2
star
48

react-pricing-section-design-002

JavaScript
2
star
49

audio-to-text

Transcribe multi-lingual audio clips using whisper model
Python
1
star
50

Xamrin

Multiple Xamrin Projects
Java
1
star
51

AndroidNative

C#
1
star
52

UserControl

This Project is about implement User Control in Xamrin form
Java
1
star
53

Kotlin_Calsee

This repository contains Android project which is developed for the #30DaysOfKotlin with Google Developers
Kotlin
1
star