Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX - The filter applies it to the filtered list instead of to all items in the initial list. #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {
tileLabel: (user) => user!.name,
emptySearchChild: const Center(child: Text('No user found')),
// enableOnlySingleSelection: true,
searchFieldHint: 'Search Here..',
searchFieldHint: '',
/*suggestionBuilder: (context, user, isSelected) {
return ListTile(
title: Text(user.name!),
Expand All @@ -76,6 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
choiceChipTheme: ChoiceChipThemeData.light(context),
),
headlineText: 'Select Users',
searchFieldHint: '',
height: 500,
listData: userList,
selectedListData: selectedUserList,
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/Users/sonusharma/Downloads/flutter
FLUTTER_APPLICATION_PATH=/Users/sonusharma/Desktop/workspace/opensource/flutter_plugin_filter_list/example
FLUTTER_ROOT=/home/arakakil/snap/flutter/common/flutter
FLUTTER_APPLICATION_PATH=/home/arakakil/git/flutter_plugin_filter_list/example
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=1.0.0
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Flutter/ephemeral/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/sonusharma/Downloads/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/sonusharma/Desktop/workspace/opensource/flutter_plugin_filter_list/example"
export "FLUTTER_ROOT=/home/arakakil/snap/flutter/common/flutter"
export "FLUTTER_APPLICATION_PATH=/home/arakakil/git/flutter_plugin_filter_list/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
Expand Down
80 changes: 52 additions & 28 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: async
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.10.0"
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
clock:
dependency: transitive
description:
Expand All @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.18.0"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -74,46 +74,62 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
js:
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "3.0.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.13"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.15.0"
path:
dependency: transitive
description:
name: path
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.2"
version: "1.9.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -123,26 +139,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -163,10 +179,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.4.16"
version: "0.7.2"
vector_math:
dependency: transitive
description:
Expand All @@ -175,6 +191,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
sdks:
dart: ">=2.18.0 <4.0.0"
flutter: ">=1.12.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A new Flutter project.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
version: 1.0.2+2
publish_to: none
environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
5 changes: 4 additions & 1 deletion lib/src/filter_list_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ part 'filter_list_widget.dart';
class FilterListDialog {
static Future display<T extends Object>(
BuildContext context, {

/// Filter theme
FilterListThemeData? themeData,

Expand Down Expand Up @@ -117,6 +116,9 @@ class FilterListDialog {
/// Headline text to be display as header of dialog.
String? headlineText,

/// Text to be displayed as a hint in the search field.
String? searchFieldHint,

/// Used to hide selected text count.
bool hideSelectedTextCount = false,

Expand Down Expand Up @@ -208,6 +210,7 @@ class FilterListDialog {
choiceChipLabel: choiceChipLabel,
hideHeader: hideHeader,
headlineText: headlineText,
searchFieldHint: searchFieldHint,
onItemSearch: onItemSearch,
backgroundColor: backgroundColor,
selectedListData: selectedListData,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/filter_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FilterListWidget<T extends Object> extends StatelessWidget {
this.headerCloseIcon,
this.onCloseWidgetPress,
this.headlineText,
this.searchFieldHint,
this.hideSelectedTextCount = false,
this.hideSearchField = false,
this.hideCloseIcon = true,
Expand Down Expand Up @@ -94,6 +95,7 @@ class FilterListWidget<T extends Object> extends StatelessWidget {
final Color? backgroundColor;

final String? headlineText;
final String? searchFieldHint;

final bool hideSelectedTextCount;
final bool hideSearchField;
Expand Down Expand Up @@ -177,6 +179,7 @@ class FilterListWidget<T extends Object> extends StatelessWidget {
Header(
headlineText: headlineText,
hideSearchField: hideSearchField,
searchFieldHint: searchFieldHint,
hideCloseIcon: hideCloseIcon,
headerCloseIcon: headerCloseIcon,
onSearch: (String value) {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/state/filter_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ class FilterState<K> extends ListenableState {
FilterState({List<K>? allItems, List<K>? selectedItems}) {
this.selectedItems = selectedItems;
items = allItems;
_allItems = allItems;
}

static FilterState<T> of<T>(BuildContext context) =>
StateProvider.of<FilterState<T>>(context);

/// List of all items
List<K>? _allItems;
List<K>? _items;
List<K>? get items => _items;
set items(List<K>? value) {
Expand Down Expand Up @@ -57,7 +59,7 @@ class FilterState<K> extends ListenableState {

// perform filter operation
void filter(bool Function(K) filter) {
_items = _items!.where(filter).toList();
_items = _allItems!.where(filter).toList();
notifyListeners();
}

Expand Down
6 changes: 5 additions & 1 deletion lib/src/widget/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Header extends StatelessWidget {
this.headerCloseIcon,
this.hideSearchField = false,
this.onCloseWidgetPress,
this.searchFieldHint,
}) : super(key: key);

final String? headlineText;
Expand All @@ -20,6 +21,8 @@ class Header extends StatelessWidget {
final ValueChanged<String> onSearch;
final void Function()? onCloseWidgetPress;

final String? searchFieldHint;

@override
Widget build(BuildContext context) {
final headerTheme = FilterListTheme.of(context).headerTheme;
Expand Down Expand Up @@ -80,7 +83,8 @@ class Header extends StatelessWidget {
if (!hideSearchField) ...[
Padding(
padding: const EdgeInsets.only(right: 8),
child: SearchFieldWidget(onChanged: onSearch),
child: SearchFieldWidget(
onChanged: onSearch, searchFieldHint: searchFieldHint),
),
]
],
Expand Down
5 changes: 4 additions & 1 deletion lib/src/widget/search_field_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import 'package:flutter/material.dart';

class SearchFieldWidget<T> extends StatelessWidget {
final ValueChanged<String> onChanged;

final String? searchFieldHint;
const SearchFieldWidget({
Key? key,
required this.onChanged,
this.searchFieldHint,
}) : super(key: key);

@override
Expand All @@ -26,7 +29,7 @@ class SearchFieldWidget<T> extends StatelessWidget {
decoration: InputDecoration(
prefixIcon:
Icon(Icons.search, color: headerTheme.searchFieldIconColor),
hintText: headerTheme.searchFieldHintText,
hintText: searchFieldHint ?? headerTheme.searchFieldHintText,
hintStyle: headerTheme.searchFieldHintTextStyle,
border: headerTheme.searchFieldInputBorder,
),
Expand Down
Loading