TextFormField的前缀图像在字段不再聚焦后消失



如果email.png前缀失去了对字段的关注,它就会消失。我尝试过使用prefixIcon,在这种情况下成功了,但如果我使用prefixIcon,我就无法调整图像的大小。

TextFormField(
decoration: InputDecoration(
//textInputDecoration.copyWith(hintText: 'Password'),
prefix: Padding(
padding: EdgeInsets.fromLTRB(5, 0, 10, 0),
child: Image.asset(
'assets/email.png',
width:20,
height:20,
),
),
hintText: 'Email',
hintStyle:  TextStyle(
color: HexColor("#1A1A1A").withOpacity(0.2),
fontSize: 14,
),
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(40.0),
borderSide: BorderSide(color: HexColor("#1A1A1A").withOpacity(0.2)),
),
),
validator: (val) => val.isEmpty ? 'Enter an email' : null, 
onChanged: (val) {
setState(() => email = val);
},
),

这是有效的,因为以前我使用的图标小部件具有prefix:属性,而它本应是prefixIcon:属性

TextFormField(
decoration: InputDecoration(
prefixIcon: SizedBox(
child: Center(
widthFactor: 0.0,
child: Image.asset(
'assets/email.png',
width: 20,
height: 20,
),
),
),
),
)

最新更新