buildTextField method

Widget buildTextField()

Implementation

Widget buildTextField() {
  //controller初始化值
  this.controller = TextEditingController.fromValue(
    TextEditingValue(
        text: text,
        selection: TextSelection.fromPosition(TextPosition(affinity: TextAffinity.downstream, offset: text.length))),
  );

  return Theme(
    data: new ThemeData(primaryColor: Color(0xFF3446F2), hintColor: Colors.black45),
    child: ConstrainedBox(
      constraints: BoxConstraints(
        maxHeight: height,
      ),
      child: TextField(
        controller: controller,
        autofocus: false,
        focusNode: this.focusNode,
        textAlign: this.textAlign, //文本对齐方式
        maxLines: maxLines, //最大行数
        style: TextStyle(fontSize: fontSize, color: Colors.black87, fontWeight: FontWeight.w500), //输入文本的样式
        inputFormatters: this.inputFormatters, //允许的输入格式
        onChanged: (text) {
          onTextChanged(text);
        },
        decoration: InputDecoration(
          hintText: hintText,
          hintStyle: TextStyle(fontSize: fontSize, color: hintTextColor),
          contentPadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
          border: outlineInputBorder,
          enabledBorder: outlineInputBorder,
          focusedBorder: focusedBorder,
        ),
      ),
    ),
  );
}