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

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

flutter - empty form text filed

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

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

1 Answer

0 votes
by (71.8m points)
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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...