Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using a FormTextField in a Flutter app

To update a certain column value, the user types in the FormTextField, otherwise leaves the field empty.

I tried this code, but it was adding a null value to the column, deleting the existing value. I'm not happy with this behavior.

      String _getProd5Name() {
           if ((_prod5Controller.text).isNotEmpty == true) {
              _prod5String = _prod5Controller.text;
            } 
             return _prod5String;
           }

Is there a way to do it?

I found similar questions, but they are relevant to other languages and their solutions don't solve my case.

question from:https://stackoverflow.com/questions/65557318/empty-form-text-filed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
246 views
Welcome To Ask or Share your Answers For Others

1 Answer

String _getProd5Name() {
    // Actually you don't have to make it private
    // since this is a local variable inside a function
    String _prod5String = variableContainingInitialValue;

    if (_prod5Controller.text.isNotEmpty) {
        _prod5String = _prod5Controller.text;
      }
    return _prod5String;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...