Skip to content

Commit 5a0d088

Browse files
committed
Suggestionbox now follows chipsinput around instead of sticking in
initial position
1 parent c5eb05e commit 5a0d088

File tree

4 files changed

+93
-88
lines changed

4 files changed

+93
-88
lines changed

.idea/workspace.xml

Lines changed: 54 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MyApp extends StatelessWidget {
77
@override
88
Widget build(BuildContext context) {
99
return new MaterialApp(
10-
title: 'Flutter Demo',
10+
title: 'Flutter FormBuilder Demo',
1111
theme: new ThemeData(
1212
primarySwatch: Colors.green,
1313
),
@@ -74,7 +74,7 @@ class MyHomePage extends StatelessWidget {
7474
// resetButtonContent: Text("Clear Form"),
7575
controls: [
7676
FormBuilderInput.chipsInput(
77-
label: 'Test',
77+
label: 'Chips',
7878
attribute: 'chips_test',
7979
require: true,
8080
suggestionsCallback: (String query) {
@@ -117,7 +117,7 @@ class MyHomePage extends StatelessWidget {
117117
require: true,
118118
min: 3,
119119
),
120-
/*FormBuilderInput.dropdown(
120+
FormBuilderInput.dropdown(
121121
attribute: "dropdown",
122122
require: true,
123123
label: "Dropdown",
@@ -192,7 +192,7 @@ class MyHomePage extends StatelessWidget {
192192
FormBuilderInputOption(value: "Objective-C"),
193193
],
194194
),
195-
FormBuilderInput.checkbox(
195+
/*FormBuilderInput.checkbox(
196196
label: "I accept the terms and conditions",
197197
attribute: "accept_terms",
198198
hint:

lib/src/chips_input.dart

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
3535
Set<T> _chips = Set<T>();
3636
List<T> _suggestions;
3737
StreamController<List<T>> _suggestionsStreamController;
38-
Stream<List<T>> _suggestionsStream;
3938
int _searchId = 0;
4039
FocusNode _focusNode;
4140
TextEditingValue _value = TextEditingValue();
4241
TextInputConnection _connection;
4342
_SuggestionsBoxController _suggestionsBoxController;
4443
final LayerLink _layerLink = LayerLink();
45-
// OverlayEntry _overlayEntry;
4644

4745
String get text => String.fromCharCodes(
4846
_value.text.codeUnits.where((ch) => ch != kObjectReplacementChar),
@@ -56,7 +54,6 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
5654
this._focusNode = FocusNode();
5755
this._suggestionsBoxController = _SuggestionsBoxController(context);
5856
this._suggestionsStreamController = StreamController<List<T>>.broadcast();
59-
// this._suggestionsStream.asBroadcastStream(())
6057

6158
(() async {
6259
await this._initOverlayEntry();
@@ -72,11 +69,9 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
7269
if (_focusNode.hasFocus) {
7370
_openInputConnection();
7471
this._suggestionsBoxController.open();
75-
//Overlay.of(context).insert(_overlayEntry);
7672
} else {
7773
_closeInputConnectionIfNeeded();
7874
this._suggestionsBoxController.close();
79-
//_overlayEntry.remove();
8075
}
8176
setState(() {
8277
/*rebuild so that _TextCursor is hidden.*/
@@ -85,6 +80,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
8580

8681
Future<void> _initOverlayEntry() async {
8782
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
8884

8985
while (renderBox == null) {
9086
await Future.delayed(Duration(milliseconds: 10));
@@ -97,37 +93,33 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
9793
}
9894

9995
var size = renderBox.size;
100-
var offset = renderBox.localToGlobal(Offset.zero);
10196

10297
this._suggestionsBoxController._overlayEntry = OverlayEntry(
10398
builder: (context) {
10499
return Positioned(
105100
width: size.width,
106-
left: offset.dx,
107-
top: offset.dy + size.height + 5.0,
108-
/*child: CompositedTransformFollower(
101+
child: CompositedTransformFollower(
109102
link: this._layerLink,
110103
showWhenUnlinked: false,
111104
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+
),
128121
),
129122
),
130-
//),
131123
);
132124
},
133125
);
@@ -210,17 +202,20 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
210202
),
211203
);
212204

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+
),
224219
),
225220
),
226221
);

0 commit comments

Comments
 (0)