@@ -35,14 +35,12 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
35
35
Set <T > _chips = Set <T >();
36
36
List <T > _suggestions;
37
37
StreamController <List <T >> _suggestionsStreamController;
38
- Stream <List <T >> _suggestionsStream;
39
38
int _searchId = 0 ;
40
39
FocusNode _focusNode;
41
40
TextEditingValue _value = TextEditingValue ();
42
41
TextInputConnection _connection;
43
42
_SuggestionsBoxController _suggestionsBoxController;
44
43
final LayerLink _layerLink = LayerLink ();
45
- // OverlayEntry _overlayEntry;
46
44
47
45
String get text => String .fromCharCodes (
48
46
_value.text.codeUnits.where ((ch) => ch != kObjectReplacementChar),
@@ -56,7 +54,6 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
56
54
this ._focusNode = FocusNode ();
57
55
this ._suggestionsBoxController = _SuggestionsBoxController (context);
58
56
this ._suggestionsStreamController = StreamController <List <T >>.broadcast ();
59
- // this._suggestionsStream.asBroadcastStream(())
60
57
61
58
(() async {
62
59
await this ._initOverlayEntry ();
@@ -72,11 +69,9 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
72
69
if (_focusNode.hasFocus) {
73
70
_openInputConnection ();
74
71
this ._suggestionsBoxController.open ();
75
- //Overlay.of(context).insert(_overlayEntry);
76
72
} else {
77
73
_closeInputConnectionIfNeeded ();
78
74
this ._suggestionsBoxController.close ();
79
- //_overlayEntry.remove();
80
75
}
81
76
setState (() {
82
77
/*rebuild so that _TextCursor is hidden.*/
@@ -85,6 +80,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
85
80
86
81
Future <void > _initOverlayEntry () async {
87
82
RenderBox renderBox = context.findRenderObject ();
83
+ // TODO: See if after_layout mixin (https://pub.dartlang.org/packages/after_layout) works instead of keep checking if rendered
88
84
89
85
while (renderBox == null ) {
90
86
await Future .delayed (Duration (milliseconds: 10 ));
@@ -97,37 +93,33 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
97
93
}
98
94
99
95
var size = renderBox.size;
100
- var offset = renderBox.localToGlobal (Offset .zero);
101
96
102
97
this ._suggestionsBoxController._overlayEntry = OverlayEntry (
103
98
builder: (context) {
104
99
return Positioned (
105
100
width: size.width,
106
- left: offset.dx,
107
- top: offset.dy + size.height + 5.0 ,
108
- /*child: CompositedTransformFollower(
101
+ child: CompositedTransformFollower (
109
102
link: this ._layerLink,
110
103
showWhenUnlinked: false ,
111
104
offset: Offset (0.0 , size.height + 5.0 ),
112
- */
113
- child : Material (
114
- elevation : 4.0 ,
115
- child : StreamBuilder (
116
- stream : _suggestionsStreamController.stream ,
117
- builder : ( BuildContext context,
118
- AsyncSnapshot < List < dynamic >> snapshot) {
119
- return ListView . builder (
120
- shrinkWrap : true ,
121
- itemCount : snapshot.data ? .length ?? 0 ,
122
- itemBuilder : ( BuildContext context, int index) {
123
- return widget. suggestionBuilder (
124
- context, this , _suggestions[index]);
125
- },
126
- );
127
- } ,
105
+ child : Material (
106
+ elevation : 4.0 ,
107
+ child : StreamBuilder (
108
+ stream : _suggestionsStreamController.stream,
109
+ builder : ( BuildContext context ,
110
+ AsyncSnapshot < List < dynamic >> snapshot) {
111
+ return ListView . builder (
112
+ shrinkWrap : true ,
113
+ itemCount : snapshot.data ? .length ?? 0 ,
114
+ itemBuilder : ( BuildContext context, int index) {
115
+ return widget. suggestionBuilder (
116
+ context, this , _suggestions[index]);
117
+ },
118
+ );
119
+ },
120
+ ) ,
128
121
),
129
122
),
130
- //),
131
123
);
132
124
},
133
125
);
@@ -210,17 +202,20 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
210
202
),
211
203
);
212
204
213
- return GestureDetector (
214
- behavior: HitTestBehavior .opaque,
215
- onTap: requestKeyboard,
216
- child: InputDecorator (
217
- decoration: widget.decoration,
218
- isFocused: _focusNode.hasFocus,
219
- isEmpty: _value.text.length == 0 ,
220
- child: Wrap (
221
- children: chipsChildren,
222
- spacing: 4.0 ,
223
- runSpacing: 4.0 ,
205
+ return CompositedTransformTarget (
206
+ link: this ._layerLink,
207
+ child: GestureDetector (
208
+ behavior: HitTestBehavior .opaque,
209
+ onTap: requestKeyboard,
210
+ child: InputDecorator (
211
+ decoration: widget.decoration,
212
+ isFocused: _focusNode.hasFocus,
213
+ isEmpty: _value.text.length == 0 ,
214
+ child: Wrap (
215
+ children: chipsChildren,
216
+ spacing: 4.0 ,
217
+ runSpacing: 4.0 ,
218
+ ),
224
219
),
225
220
),
226
221
);
0 commit comments