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

feat: Add autoCloseDropdownInSingleSelectMode option to MultiDropdown #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions lib/src/multi_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MultiDropdown<T extends Object> extends StatefulWidget {
/// The [closeOnBackButton] is whether to close the dropdown when the back button is pressed. The default value is false.
/// Note: This option requires the app to have a router, such as MaterialApp.router, in order to work properly.
///
///
/// The [autoCloseDropdownInSingleSelectMode] is whether to close the dropdown when an item is selected/deselected in single select mode.
/// The default value is true.
const MultiDropdown({
required this.items,
this.fieldDecoration = const FieldDecoration(),
Expand All @@ -106,6 +107,7 @@ class MultiDropdown<T extends Object> extends StatefulWidget {
this.onSelectionChange,
this.onSearchChange,
this.closeOnBackButton = false,
this.autoCloseDropdownInSingleSelectMode = true,
Key? key,
}) : future = null,
super(key: key);
Expand Down Expand Up @@ -154,6 +156,7 @@ class MultiDropdown<T extends Object> extends StatefulWidget {
this.onSelectionChange,
this.onSearchChange,
this.closeOnBackButton = false,
this.autoCloseDropdownInSingleSelectMode = true,
Key? key,
}) : items = const [],
super(key: key);
Expand Down Expand Up @@ -225,6 +228,9 @@ class MultiDropdown<T extends Object> extends StatefulWidget {
/// Note: This option requires the app to have a router, such as MaterialApp.router, in order to work properly.
final bool closeOnBackButton;

/// Whether to close the dropdown when an item is selected/deselected in single select mode.
final bool autoCloseDropdownInSingleSelectMode;

@override
State<MultiDropdown<T>> createState() => _MultiDropdownState<T>();
}
Expand Down Expand Up @@ -484,7 +490,7 @@ class _MultiDropdownState<T extends Object> extends State<MultiDropdown<T>> {
}
_formFieldKey.currentState?.didChange(_dropdownController.selectedItems);

if (widget.singleSelect) {
if (widget.singleSelect && widget.autoCloseDropdownInSingleSelectMode) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_dropdownController.closeDropdown();
});
Expand Down