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 itemBorderRadius and wrap itemBuilder with IgnorePointer #584

Closed
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `itemBorderRadius` parameter to `TypeAheadField` and `CupertinoTypeAheadField` (#584)

### Fixed
- Mouse cursor doesn't change to pointer-hand when ListTile is returned in itemBuilder (#584)

## 5.2.0 - 2024-02-08
### Added
- force refreshing suggestions with `SuggestionsController.refresh`
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ TypeAheadField<City>(
)
);
},
itemBorderRadius: BorderRadius.circular(8),
itemBuilder: (context, city) {
return ListTile(
title: Text(city.name),
Expand Down Expand Up @@ -257,6 +258,8 @@ You must then specify the following parameters:

As well as all the usual parameters, such as `suggestionsCallback`, `onSelected`, etc.

If you want to set border radius to the suggestion items, doing it inside `itemBuilder` probably won't work. Use `itemBorderRadius` parameter instead.

The `decorationBuilder` can be used to inject required wrappers like `Material` or `DefaultTextStyle`.
For more information, see the source code of the `TypeAheadField` widget.

Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ExampleTypeAhead extends StatelessWidget
borderRadius: borderRadius,
child: child,
),
itemBorderRadius: BorderRadius.circular(8),
itemBuilder: (context, product) => ListTile(
title: Text(product.name),
subtitle: product.description != null
Expand Down Expand Up @@ -224,6 +225,7 @@ class CupertinoExampleTypeAhead extends StatelessWidget
),
child: child,
),
itemBorderRadius: BorderRadius.circular(8),
itemBuilder: (context, product) => CupertinoListTile(
title: Text(product.name),
subtitle: product.description != null
Expand Down
2 changes: 2 additions & 0 deletions example/lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SettingsTypeAhead extends StatelessWidget
hintText: hintText,
),
),
itemBorderRadius: BorderRadius.circular(8),
itemBuilder: (context, setting) {
if (setting is ToggleFieldOption) {
IconData? icon = setting.value
Expand Down Expand Up @@ -125,6 +126,7 @@ class CupertinoSettingsTypeAhead extends StatelessWidget
fontStyle: FontStyle.italic,
),
),
itemBorderRadius: BorderRadius.circular(8),
itemBuilder: (context, setting) {
if (setting is ToggleFieldOption) {
return CupertinoListTile(
Expand Down
16 changes: 10 additions & 6 deletions lib/src/cupertino/cupertino_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ abstract final class TypeAheadCupertinoDefaults {
/// Provides the functionality to select an item on tap.
static SuggestionsItemBuilder<T> itemBuilder<T>(
SuggestionsItemBuilder<T> builder,
BorderRadius itemBorderRadius,
) {
return (context, item) {
return FocusableActionDetector(
mouseCursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
child: builder(context, item),
onTap: () => SuggestionsController.of<T>(context).select(item),
return ClipRRect(
borderRadius: itemBorderRadius,
child: FocusableActionDetector(
mouseCursor: SystemMouseCursors.click,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
child: IgnorePointer(child: builder(context, item)),
onTap: () => SuggestionsController.of<T>(context).select(item),
),
),
);
};
Expand Down
4 changes: 3 additions & 1 deletion lib/src/cupertino/typeahead_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CupertinoTypeAheadField<T> extends RawTypeAheadField<T> {
super.hideOnUnfocus,
super.hideWithKeyboard,
super.hideOnSelect,
BorderRadius itemBorderRadius = BorderRadius.zero,
required SuggestionsItemBuilder<T> itemBuilder,
super.itemSeparatorBuilder,
super.retainOnLoading,
Expand All @@ -49,7 +50,8 @@ class CupertinoTypeAheadField<T> extends RawTypeAheadField<T> {
loadingBuilder:
loadingBuilder ?? TypeAheadCupertinoDefaults.loadingBuilder,
emptyBuilder: emptyBuilder ?? TypeAheadCupertinoDefaults.emptyBuilder,
itemBuilder: TypeAheadCupertinoDefaults.itemBuilder(itemBuilder),
itemBuilder: TypeAheadCupertinoDefaults.itemBuilder(
itemBuilder, itemBorderRadius),
decorationBuilder:
TypeAheadCupertinoDefaults.wrapperBuilder(decorationBuilder),
);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/material/material_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ abstract final class TypeAheadMaterialDefaults {
/// Provides the functionality to select an item on tap.
static SuggestionsItemBuilder<T> itemBuilder<T>(
SuggestionsItemBuilder<T> builder,
BorderRadius itemBorderRadius,
) {
return (context, item) {
return InkWell(
borderRadius: itemBorderRadius,
focusColor: Theme.of(context).hoverColor,
onTap: () => SuggestionsController.of<T>(context).select(item),
child: builder(context, item),
child: IgnorePointer(child: builder(context, item)),
);
};
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/material/typeahead_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TypeAheadField<T> extends RawTypeAheadField<T> {
super.hideOnUnfocus,
super.hideWithKeyboard,
super.hideOnSelect,
BorderRadius itemBorderRadius = BorderRadius.zero,
required SuggestionsItemBuilder<T> itemBuilder,
super.itemSeparatorBuilder,
super.retainOnLoading,
Expand All @@ -49,7 +50,8 @@ class TypeAheadField<T> extends RawTypeAheadField<T> {
loadingBuilder:
loadingBuilder ?? TypeAheadMaterialDefaults.loadingBuilder,
emptyBuilder: emptyBuilder ?? TypeAheadMaterialDefaults.emptyBuilder,
itemBuilder: TypeAheadMaterialDefaults.itemBuilder(itemBuilder),
itemBuilder: TypeAheadMaterialDefaults.itemBuilder(
itemBuilder, itemBorderRadius),
decorationBuilder:
TypeAheadMaterialDefaults.wrapperBuilder(decorationBuilder),
);
Expand Down