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 [Web/Desktop] Tap event is not simulated in a overlay on Flutter 3.7 #19

Merged
merged 2 commits into from
Apr 24, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 1. Fix tap event is not simulated in a overlay on Flutter 3.7 for Web/Desktop

Date: 2023-04-24

## Status

Accepted

## Context

Tap events are not being simulated to overlay on the `Web/Desktop` but work fine on mobile devices. This worked fine until the previous release stable 3.3.

## Root causes

Because the thing that the overlay is attached to is a `TextField`, so in order to keep from unfocused the text field when tapping outside of it, you need to tell the overlay widget that it's part of the TextField for purposes of the `tap outside` behavior by adding the `TextFieldTapRegion` around it, so that when the tap arrives, it's considered `inside` of the text field.

## Decision

Try wrapping a `TextFieldTapRegion` around the `Material` in the overlay.

## Consequences

This worked fine
143 changes: 73 additions & 70 deletions lib/tag_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,77 +332,82 @@ class TagsEditorState<T> extends State<TagEditor<T>> {
initialData: _suggestions,
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data!.isNotEmpty) {
final suggestionsListView = PointerInterceptor(
child: AutocompleteHighlightedOption(
highlightIndexNotifier: _highlightedOptionIndex,
child: ValidationSuggestionItem(
validationNotifier: _validationSuggestionItemNotifier,
child: Padding(
padding: widget.suggestionMargin ?? EdgeInsets.zero,
child: Material(
elevation: widget.suggestionsBoxElevation ?? 20,
borderRadius: BorderRadius.circular(
widget.suggestionsBoxRadius ?? 20),
color: widget.suggestionsBoxBackgroundColor ??
Colors.white,
child: ClipRRect(
final suggestionsListView = TextFieldTapRegion(
child: PointerInterceptor(
child: AutocompleteHighlightedOption(
highlightIndexNotifier: _highlightedOptionIndex,
child: ValidationSuggestionItem(
validationNotifier: _validationSuggestionItemNotifier,
child: Padding(
padding: widget.suggestionMargin ?? EdgeInsets.zero,
child: Material(
elevation: widget.suggestionsBoxElevation ?? 20,
borderRadius: BorderRadius.circular(
widget.suggestionsBoxRadius ?? 20),
child: Container(
decoration: BoxDecoration(
color:
widget.suggestionsBoxBackgroundColor ??
Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(
widget.suggestionsBoxRadius ?? 0))),
constraints: BoxConstraints(
maxHeight: suggestionBoxHeight),
child: ListView.builder(
shrinkWrap: true,
padding: widget.suggestionPadding ??
EdgeInsets.zero,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
if (_suggestions != null &&
_suggestions?.isNotEmpty == true) {
final item = _suggestions![index];
final highlight =
AutocompleteHighlightedOption.of(
context) ==
index;
final suggestionValid =
ValidationSuggestionItem.of(context);

if (!widget.useDefaultHighlight) {
return widget.suggestionBuilder(
context,
this,
item,
index,
snapshot.data!.length,
highlight,
suggestionValid);
color: widget.suggestionsBoxBackgroundColor ??
Colors.white,
child: ClipRRect(
borderRadius: BorderRadius.circular(
widget.suggestionsBoxRadius ?? 20),
child: Container(
decoration: BoxDecoration(
color: widget
.suggestionsBoxBackgroundColor ??
Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(
widget.suggestionsBoxRadius ??
0))),
constraints: BoxConstraints(
maxHeight: suggestionBoxHeight),
child: ListView.builder(
shrinkWrap: true,
padding: widget.suggestionPadding ??
EdgeInsets.zero,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
if (_suggestions != null &&
_suggestions?.isNotEmpty == true) {
final item = _suggestions![index];
final highlight =
AutocompleteHighlightedOption.of(
context) ==
index;
final suggestionValid =
ValidationSuggestionItem.of(
context);

if (!widget.useDefaultHighlight) {
return widget.suggestionBuilder(
context,
this,
item,
index,
snapshot.data!.length,
highlight,
suggestionValid);
} else {
return Container(
color: highlight
? widget.itemHighlightColor ??
Theme.of(context)
.focusColor
: null,
child: widget.suggestionBuilder(
context,
this,
item,
index,
snapshot.data!.length,
highlight,
suggestionValid));
}
} else {
return Container(
color: highlight
? widget.itemHighlightColor ??
Theme.of(context).focusColor
: null,
child: widget.suggestionBuilder(
context,
this,
item,
index,
snapshot.data!.length,
highlight,
suggestionValid));
return Container();
}
} else {
return Container();
}
},
)),
},
)),
),
),
),
),
Expand All @@ -415,14 +420,12 @@ class TagsEditorState<T> extends State<TagEditor<T>> {
link: _layerLink,
showWhenUnlinked: false,
offset: compositedTransformFollowerOffset,
child: TextFieldTapRegion(
child: !showTop
child: !showTop
? suggestionsListView
: FractionalTranslation(
translation: const Offset(0, -1),
child: suggestionsListView,
),
),
),
);
}
Expand Down