Skip to content

Commit

Permalink
Added AutoSuggestBox.noResultsFoundBuilder and `AutoSuggestBox.inpu…
Browse files Browse the repository at this point in the history
…tFormatters` (Fixes #542)
  • Loading branch information
bdlukaa committed Sep 27, 2022
1 parent 8189329 commit 4bb2bbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Date format: DD/MM/YYYY
- Ensure `MenuFlyoutItem.onPressed` is called after the flyout is closed if `DropDownButton.closeAfterClick` is true ([#520](/~https://github.com/bdlukaa/fluent_ui/issues/520))
- Ensure the `TimePicker` and `DatePicker` popups will fit if the screen is small ([#544](/~https://github.com/bdlukaa/fluent_ui/issues/544))
- Do not apply padding to `NavigationAppBar.leading` ([#539](/~https://github.com/bdlukaa/fluent_ui/issues/539))
- Added `AutoSuggestBox.noResultsFoundBuilder` ([#542](/~https://github.com/bdlukaa/fluent_ui/issues/542))
- Added `AutoSuggestBox.inputFormatters` ([#542](/~https://github.com/bdlukaa/fluent_ui/issues/542))

## 4.0.0

Expand Down
32 changes: 24 additions & 8 deletions lib/src/controls/form/auto_suggest_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class AutoSuggestBoxItem<T> {
///
/// See also:
///
/// * <https://docs.microsoft.com/en-us/windows/apps/design/controls/auto-suggest-box>
/// * [TextBox], which is used by this widget to enter user text input
/// * [TextFormBox], which is used by this widget by Form
/// * [Overlay], which is used to show the suggestion popup
/// * <https://docs.microsoft.com/en-us/windows/apps/design/controls/auto-suggest-box>
class AutoSuggestBox<T> extends StatefulWidget {
/// Creates a fluent-styled auto suggest box.
const AutoSuggestBox({
Expand All @@ -93,6 +93,7 @@ class AutoSuggestBox<T> extends StatefulWidget {
this.controller,
this.onChanged,
this.onSelected,
this.noResultsFoundBuilder,
this.sorter,
this.leadingIcon,
this.trailingIcon,
Expand All @@ -117,6 +118,7 @@ class AutoSuggestBox<T> extends StatefulWidget {
this.autofocus = false,
this.enableKeyboardControls = true,
this.enabled = true,
this.inputFormatters,
}) : autovalidateMode = AutovalidateMode.disabled,
validator = null,
super(key: key);
Expand All @@ -128,6 +130,7 @@ class AutoSuggestBox<T> extends StatefulWidget {
this.controller,
this.onChanged,
this.onSelected,
this.noResultsFoundBuilder,
this.sorter,
this.leadingIcon,
this.trailingIcon,
Expand All @@ -154,6 +157,7 @@ class AutoSuggestBox<T> extends StatefulWidget {
this.autofocus = false,
this.enableKeyboardControls = true,
this.enabled = true,
this.inputFormatters,
}) : super(key: key);

/// The list of items to display to the user to pick
Expand All @@ -168,6 +172,9 @@ class AutoSuggestBox<T> extends StatefulWidget {
/// Called when the user selected a value.
final ValueChanged<AutoSuggestBoxItem<T>>? onSelected;

/// Widget to be displayed when none of the items fit the [sorter]
final WidgetBuilder? noResultsFoundBuilder;

/// Sort the [items] based on the current query text
///
/// See also:
Expand Down Expand Up @@ -295,6 +302,9 @@ class AutoSuggestBox<T> extends StatefulWidget {
/// * [TextBox.enabled]
final bool enabled;

/// {@macro flutter.widgets.editableText.inputFormatters}
final List<TextInputFormatter>? inputFormatters;

@override
State<AutoSuggestBox<T>> createState() => _AutoSuggestBoxState<T>();

Expand Down Expand Up @@ -491,6 +501,7 @@ class _AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
_dismissOverlay();
focusNode.unfocus();
},
noResultsFoundBuilder: widget.noResultsFoundBuilder,
),
),
),
Expand Down Expand Up @@ -655,6 +666,7 @@ class _AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
textInputAction: widget.textInputAction,
keyboardAppearance: widget.keyboardAppearance,
enabled: widget.enabled,
inputFormatters: widget.inputFormatters,
)
: TextBox(
key: _textBoxKey,
Expand Down Expand Up @@ -684,6 +696,7 @@ class _AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
textInputAction: widget.textInputAction,
keyboardAppearance: widget.keyboardAppearance,
enabled: widget.enabled,
inputFormatters: widget.inputFormatters,
),
),
);
Expand All @@ -701,6 +714,7 @@ class _AutoSuggestBoxOverlay<T> extends StatefulWidget {
required this.itemsStream,
required this.sorter,
required this.maxHeight,
required this.noResultsFoundBuilder,
}) : super(key: key);

final List<AutoSuggestBoxItem<T>> items;
Expand All @@ -711,6 +725,7 @@ class _AutoSuggestBoxOverlay<T> extends StatefulWidget {
final Stream<List<AutoSuggestBoxItem<T>>> itemsStream;
final AutoSuggestBoxSorter<T> sorter;
final double maxHeight;
final WidgetBuilder? noResultsFoundBuilder;

@override
State<_AutoSuggestBoxOverlay<T>> createState() =>
Expand Down Expand Up @@ -798,13 +813,14 @@ class _AutoSuggestBoxOverlayState<T> extends State<_AutoSuggestBoxOverlay<T>> {
final sortedItems = widget.sorter(value.text, items);
late Widget result;
if (sortedItems.isEmpty) {
result = Padding(
padding: const EdgeInsets.only(bottom: 4.0),
child: _AutoSuggestBoxOverlayTile(
text: Text(localizations.noResultsFoundLabel),
selected: false,
),
);
result = widget.noResultsFoundBuilder?.call(context) ??
Padding(
padding: const EdgeInsets.only(bottom: 4.0),
child: _AutoSuggestBoxOverlayTile(
text: Text(localizations.noResultsFoundLabel),
selected: false,
),
);
} else {
result = ListView.builder(
itemExtent: tileHeight,
Expand Down

0 comments on commit 4bb2bbe

Please sign in to comment.