I want to be able to select either a textField or the container surrounding the widget depending on whether the user long presses on it, or simply taps. A long press should select the container so they can drag and reorder it, and a tap should select the textfield to edit the text.
Right now, a long press is selecting the textfield for each item. I can select the container, but I must tap and hold either above or below the textfield portion of the container in order to do so. I instead want to be able to select either one depending on the gesture type they use - not where exactly they tap.
I realise I need to use a GestureDetector with onLongPress and onTap somewhere, and I am unsure where exactly to put it - do I put it in the _NotesPageState class build method, or the Item class _buildChild method.
I have also tried using focus nodes but they apparently only work with textfields, and cannot be applied to other widget types.
Here is the build method from the _NotesPageState class:
Widget build(BuildContext context) {
return Scaffold(
body: ReorderableList(
onReorder: this._reorderCallback,
onReorderDone: this._reorderDone,
child: CustomScrollView(
// cacheExtent: 3000,
slivers: <Widget>[
SliverPadding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Item(
data: _todos[index],
todoIndex: index,
// first and last attributes affect border drawn during dragging
isFirst: index == 0,
isLast: index == _todos.length - 1,
);
},
childCount: _todos.length,
),
)),
],
),
),
);
}
And the code from the Item class method:
Widget content = Container(
decoration: decoration,
child: SafeArea(
top: false,
bottom: false,
child: Opacity(
// hide content for placeholder
opacity: state == ReorderableItemState.placeholder ? 0.0 : 1.0,
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 24.0, horizontal: 14.0),
child: TextField(
decoration: null,
controller: _controller,
maxLength: 512,
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: (text) {
data.title = text;
},
),
),
),
],
),
),
),
),
);
content = DelayedReorderableListener(
child: content,
);
return content;
}
In summary:
-
Where exactly should I put the GestureDetector?
-
How do I select either the textfield or the whole item depending on a tap or long press?