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 mouse events propagating through the SuggestionBox to the underlying HTMLElementView #495

Merged
merged 2 commits into from
Jun 4, 2023
Merged
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
12 changes: 11 additions & 1 deletion lib/src/material/field/typeahead_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:flutter_typeahead/src/material/suggestions_box/suggestions_box_d
import 'package:flutter_typeahead/src/material/suggestions_box/suggestions_list.dart';
import 'package:flutter_typeahead/src/typedef.dart';
import 'package:flutter_typeahead/src/utils.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';

/// # Flutter TypeAhead
/// A TypeAhead widget for Flutter, where you can show suggestions to
Expand Down Expand Up @@ -378,6 +379,10 @@ class TypeAheadField<T> extends StatefulWidget {
///
/// If not specified, the error is shown in [ThemeData.errorColor](https://docs.flutter.io/flutter/material/ThemeData/errorColor.html)
final ErrorBuilder? errorBuilder;

/// Used to overcome [Flutter issue 98507](https://github.com/flutter/flutter/issues/98507)
/// Most commonly experienced when placing the [TypeAheadFormField] on a google map in Flutter Web.
final bool intercepting;

/// Called to display animations when [suggestionsCallback] returns suggestions
///
Expand Down Expand Up @@ -538,6 +543,7 @@ class TypeAheadField<T> extends StatefulWidget {
required this.itemBuilder,
this.itemSeparatorBuilder,
this.layoutArchitecture,
this.intercepting = false,
required this.onSuggestionSelected,
this.textFieldConfiguration = const TextFieldConfiguration(),
this.suggestionsBoxDecoration = const SuggestionsBoxDecoration(),
Expand Down Expand Up @@ -763,6 +769,7 @@ class _TypeAheadFieldState<T> extends State<TypeAheadField<T>>
suggestionsBox: _suggestionsBox,
decoration: widget.suggestionsBoxDecoration,
debounceDuration: widget.debounceDuration,
intercepting: widget.intercepting,
controller: this._effectiveController,
loadingBuilder: widget.loadingBuilder,
scrollController: widget.scrollController,
Expand Down Expand Up @@ -863,7 +870,9 @@ class _TypeAheadFieldState<T> extends State<TypeAheadField<T>>
Widget build(BuildContext context) {
return CompositedTransformTarget(
link: this._layerLink,
child: TextField(
child: PointerInterceptor(
intercepting: widget.intercepting,
child: TextField(
focusNode: this._effectiveFocusNode,
controller: this._effectiveController,
decoration: widget.textFieldConfiguration.decoration,
Expand Down Expand Up @@ -898,6 +907,7 @@ class _TypeAheadFieldState<T> extends State<TypeAheadField<T>>
widget.textFieldConfiguration.enableInteractiveSelection,
readOnly: widget.hideKeyboard,
autofillHints: widget.textFieldConfiguration.autofillHints),
),
);
}
}
2 changes: 2 additions & 0 deletions lib/src/material/field/typeahead_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TypeAheadFormField<T> extends FormField<String> {
bool hideOnEmpty = false,
bool hideOnError = false,
bool hideSuggestionsOnKeyboardHide = true,
bool intercepting = false,
bool keepSuggestionsOnLoading = true,
bool keepSuggestionsOnSuggestionSelected = false,
bool autoFlipDirection = false,
Expand Down Expand Up @@ -116,6 +117,7 @@ class TypeAheadFormField<T> extends FormField<String> {
keepSuggestionsOnLoading: keepSuggestionsOnLoading,
keepSuggestionsOnSuggestionSelected:
keepSuggestionsOnSuggestionSelected,
intercepting: intercepting,
autoFlipDirection: autoFlipDirection,
autoFlipListDirection: autoFlipListDirection,
autoFlipMinHeight: autoFlipMinHeight,
Expand Down
9 changes: 7 additions & 2 deletions lib/src/material/suggestions_box/suggestions_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_typeahead/src/should_refresh_suggestion_focus_index_noti
import 'package:flutter_typeahead/src/material/suggestions_box/suggestions_box.dart';
import 'package:flutter_typeahead/src/material/suggestions_box/suggestions_box_decoration.dart';
import 'package:flutter_typeahead/src/typedef.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';

/// Renders all the suggestions using a ListView as default. If
/// `layoutArchitecture` is specified, uses that instead.
Expand All @@ -25,6 +26,7 @@ class SuggestionsList<T> extends StatefulWidget {
final SuggestionsBoxDecoration? decoration;
final Duration? debounceDuration;
final WidgetBuilder? loadingBuilder;
final bool intercepting;
final WidgetBuilder? noItemsFoundBuilder;
final ErrorBuilder? errorBuilder;
final AnimationTransitionBuilder? transitionBuilder;
Expand All @@ -47,6 +49,7 @@ class SuggestionsList<T> extends StatefulWidget {
SuggestionsList({
required this.suggestionsBox,
this.controller,
this.intercepting = false,
this.getImmediateSuggestions = false,
this.onSuggestionSelected,
this.suggestionsCallback,
Expand Down Expand Up @@ -308,7 +311,9 @@ class _SuggestionsListState<T> extends State<SuggestionsList<T>>
);
}

var container = Material(
var container = PointerInterceptor(
intercepting: widget.intercepting,
child: Material(
elevation: widget.decoration!.elevation,
color: widget.decoration!.color,
shape: widget.decoration!.shape,
Expand All @@ -319,7 +324,7 @@ class _SuggestionsListState<T> extends State<SuggestionsList<T>>
constraints: constraints,
child: animationChild,
),
);
));

return container;
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
flutter:
sdk: flutter
flutter_keyboard_visibility: ^5.4.1
pointer_interceptor: ^0.9.3+4

dev_dependencies:
flutter_test:
Expand Down