I have a container
that's wrapped within a gesture detector
and within the container two text-fields which on clicked will show the time selector and date selector widgets consecutively. I added a clear button next to the date field and on tap it clears both the text-fields. The problem is on clicking the clear button it does not disappear even after both the text-fields have been cleared.
GestureDetector(
onTap: () async {
await _pickDateTime();
},
child: Container(
margin: const EdgeInsets.only(top: 20.0),
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 24.0, vertical: 15.0),
decoration: BoxDecoration(
color: tertiaryColor,
borderRadius: BorderRadius.circular(14.0)),
child: Column(
children: [
Row(
children: [
Flexible(
child: TextField(
enabled: false,
controller: _dateController,
onChanged: (String val) {
_setDate = val;
},
decoration: InputDecoration(
hintText: "Date",
hintStyle: hintTextStyle,
border: InputBorder.none),
style: todoScreenStyle,
),
),
_dateController.text.isNotEmpty &&
_timeController.text.isNotEmpty
? IconButton(
onPressed: () {
_dateController.clear();
_timeController.clear();
},
icon: Icon(
Icons.close,
color: Colors.white,
))
: Container()
],
),
dividerStyle,
TextField(
onChanged: (String val) {
_setTime = val;
},
enabled: false,
controller: _timeController,
decoration: InputDecoration(
hintText: "Time",
hintStyle: hintTextStyle,
border: InputBorder.none),
style: todoScreenStyle,
)
],
)),
),
I tried using setState
but that did not work, also suffix Icon
cannot be used as the whole container is wrapper within a gesture detector
For those who stumble upon this question: the answer is here: clear-button-not-changing-state