admin管理员组文章数量:1186253
Two detail sheets use the same function to create a TextField widget with a DateTimePicker from an icon button. In one sheet, it displays the selected datetime into the TextField; the other does not. I create and initialize the TextControllers in the same places
I thought it might be because one sheet passed in the buildContext and one used the faramwork.dart get context (which I had no idea existed). Apparently, they both work
I've debugged and watches the code assign the new text version of the value into the TextController.text in both sheets. One sheet shows the text value and one does not
Any ideas?
inputDateField(
// either buildContext or framework `get context`
context: context,
textController: _remindedDateController,
label: 'Reminded At'.i18n,
getDateTimeValue: () => this.widget.item.remindedAt,
setDateTimeValue: (DateTime? newValue) {
this.setState(() {
this.widget.item.remindedAt = newValue;
_remindedDateController.text = formatDateTime(newValue);
});
},
),
from inputDateField():
onPressed: () async {
final DateTime? newValue = await showOmniDateTimePicker(
context: context,
initialDate: getDateTimeValue(),
);
if (newValue != null) {
setDateTimeValue(newValue);
}
},
Two detail sheets use the same function to create a TextField widget with a DateTimePicker from an icon button. In one sheet, it displays the selected datetime into the TextField; the other does not. I create and initialize the TextControllers in the same places
I thought it might be because one sheet passed in the buildContext and one used the faramwork.dart get context (which I had no idea existed). Apparently, they both work
I've debugged and watches the code assign the new text version of the value into the TextController.text in both sheets. One sheet shows the text value and one does not
Any ideas?
inputDateField(
// either buildContext or framework `get context`
context: context,
textController: _remindedDateController,
label: 'Reminded At'.i18n,
getDateTimeValue: () => this.widget.item.remindedAt,
setDateTimeValue: (DateTime? newValue) {
this.setState(() {
this.widget.item.remindedAt = newValue;
_remindedDateController.text = formatDateTime(newValue);
});
},
),
from inputDateField():
onPressed: () async {
final DateTime? newValue = await showOmniDateTimePicker(
context: context,
initialDate: getDateTimeValue(),
);
if (newValue != null) {
setDateTimeValue(newValue);
}
},
Share
Improve this question
asked Jan 26 at 21:03
Richard HavenRichard Haven
1,15416 silver badges31 bronze badges
2
|
1 Answer
Reset to default 0It was a subtle exception in the state object (the queue object and not the item object)
I need to read the entire output message even if it has a huge stack trace
Thank you for your attention
本文标签: dartFlutter TexField set via TextController is inconsistentStack Overflow
版权声明:本文标题:dart - Flutter TexField set via TextController is inconsistent - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738295402a2073355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
setState
and expecting the UI to update?I've had similar issues withAlertDialog
(which usually won't update on basicsetState
) – il_boga Commented Jan 27 at 10:08widget.item.remindedAt = newValue;
seem to suggest that you are using a widget variable to store the state. Is that intended? StatefulWidgets usually define only aconst
constructor and the state is store in a class variable ofState<...>
. – Dan R Commented Jan 27 at 15:34