我在容器内使用文本和文本表单字段来获取用户名。我需要进行文本字段验证并获得错误消息和红色边界框,如预期结果图像所示。我也包括了当前的输出。我也尝试了其他一些方法。但没有任何效果。
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
shape: BoxShape.rectangle,
color: Color(0xFFF4F9FE),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(10, 3, 0, 0),
child: Text("Full Name",
style: TextStyle(color: Color(0xFFA8C3EC)),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: new InputDecoration(
hintText: "Enter Your Full Name",
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(color: Colors.red),
),
disabledBorder: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 1.0),
),
validator: _validateName,
),
),
],
),
);
String _validateName(String value) {
return "Required field cannot be empty";
}