Skip to content

Commit 37a9b5a

Browse files
committed
Fix: Issue #231 Overlay resize performance
1 parent 400b3b0 commit 37a9b5a

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

lib/src/searchfield.dart

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,6 @@ class _SearchFieldState<T> extends State<SearchField<T>> {
678678
@override
679679
void didChangeDependencies() {
680680
// update overlay dimensions on mediaQuery change
681-
if (mounted) {
682-
_calculateDimensions();
683-
}
684681
if (_overlayEntry != null && _overlayEntry!.mounted) {
685682
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
686683
if (mounted) {
@@ -925,36 +922,45 @@ class _SearchFieldState<T> extends State<SearchField<T>> {
925922
// final textFieldsize = textFieldRenderBox.size;
926923
// final offset = textFieldRenderBox.localToGlobal(Offset.zero);
927924
// var yOffset = Offset.zero;
928-
return StreamBuilder<List<SearchFieldListItem?>?>(
929-
stream: suggestionStream.stream,
930-
builder: (BuildContext context,
931-
AsyncSnapshot<List<SearchFieldListItem?>?> snapshot) {
932-
late var count = widget.maxSuggestionsInViewPort;
933-
if (snapshot.data != null) {
934-
count = snapshot.data!.length;
935-
}
936-
var yOffset = Offset.zero;
937-
if (widget.offset == null) {
938-
yOffset = getYOffset(count) ?? Offset.zero;
939-
}
940-
return Positioned(
941-
left: searchFieldDimensions.offset!.dx,
942-
width: widget.suggestionsDecoration?.width ??
943-
searchFieldDimensions.width,
944-
child: CompositedTransformFollower(
945-
offset: widget.offset ?? yOffset,
946-
link: _layerLink,
947-
child: Material(
948-
borderRadius: widget.suggestionsDecoration?.borderRadius ??
949-
BorderRadius.zero,
950-
shadowColor: widget.suggestionsDecoration?.shadowColor,
951-
elevation: widget.suggestionsDecoration?.elevation ??
952-
kDefaultElevation,
953-
child: _suggestionsBuilder(),
954-
),
955-
),
956-
);
957-
});
925+
return LayoutBuilder(
926+
builder: (BuildContext context, BoxConstraints constraints) {
927+
_calculateDimensions();
928+
return StreamBuilder<List<SearchFieldListItem?>?>(
929+
stream: suggestionStream.stream,
930+
builder: (BuildContext context,
931+
AsyncSnapshot<List<SearchFieldListItem?>?> snapshot) {
932+
late var count = widget.maxSuggestionsInViewPort;
933+
if (snapshot.data != null) {
934+
count = snapshot.data!.length;
935+
}
936+
var yOffset = Offset.zero;
937+
if (widget.offset == null) {
938+
yOffset = getYOffset(count) ?? Offset.zero;
939+
}
940+
return Stack(
941+
children: [
942+
Positioned(
943+
left: searchFieldDimensions.offset!.dx,
944+
width: widget.suggestionsDecoration?.width ??
945+
searchFieldDimensions.width,
946+
child: CompositedTransformFollower(
947+
offset: widget.offset ?? yOffset,
948+
link: _layerLink,
949+
child: Material(
950+
borderRadius:
951+
widget.suggestionsDecoration?.borderRadius ??
952+
BorderRadius.zero,
953+
shadowColor: widget.suggestionsDecoration?.shadowColor,
954+
elevation: widget.suggestionsDecoration?.elevation ??
955+
kDefaultElevation,
956+
child: _suggestionsBuilder(),
957+
),
958+
),
959+
),
960+
],
961+
);
962+
});
963+
});
958964
});
959965
}
960966

0 commit comments

Comments
 (0)