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 Could it be something state-related? Like you debug and see the values change correctly, and call setState and expecting the UI to update?I've had similar issues with AlertDialog (which usually won't update on basic setState) – il_boga Commented Jan 27 at 10:08
  • 1 The line widget.item.remindedAt = newValue; seem to suggest that you are using a widget variable to store the state. Is that intended? StatefulWidgets usually define only a const constructor and the state is store in a class variable of State<...> . – Dan R Commented Jan 27 at 15:34
Add a comment  | 

1 Answer 1

Reset to default 0

It 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