inputBox function

Widget inputBox (
  1. SamModel sm,
  2. {@required String sym,
  3. @required String label,
  4. double width: 200,
  5. double height: 50,
  6. String hint,
  7. FocusFunc onFocus}
)

Return an TextField widget according to the host platform.

The returned widget will be a PlatformTextField. The optional 02onFocus callback is triggered as the focus changes so that the underlying widgets can be modified if it is necessary to allow space for the virtual keyboard popup.

The sym value is used in SamHot both to get the initial value from and to save the updated value.

The label, width, height and hint are used to provide properties to the host platform dependent widget used to hold the field.

When the value changes an SE.sa_change proposal with the new values is presented to the SamModel at SamModel.present.

Implementation

Widget inputBox(SamModel sm,{@required String sym,@required String label,double width = 200,double height = 50,String hint,FocusFunc onFocus}) {
  //log("buildInputBox $label");
  return ConstrainedBox(
    constraints: BoxConstraints.tight(Size(width, height)),
    child: Focus(
      onFocusChange:(hasFocus) {log("textField focus $hasFocus");if (onFocus != null) onFocus(hasFocus);},
      child:PlatformTextField(
      onChanged: (newValue) => sm.actionCall(SE.sa_change, {'value': newValue, 'sym': sym}),
      material: (_, __)  => MaterialTextFieldData(
        //autofocus:false,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: label,
          hintText: hint,
          ),
      ),
      cupertino: (_, __) => CupertinoTextFieldData(
          placeholder:label,
        ),
      )
    )
  );
}