如何在prefixIcon内的flutter TextFormField中添加图像

how to add image in flutter TextFormField inside prefixIcon

在 TextFormField 中 prefixIcon 带一个小部件, 我用了 Image.asset(lock,width: 10,height: 10,), 但它的尺寸大于 20, 我做什么?

您可以在 TextFormField Widget 中添加 prefixIcon,如下所示,

prefixIcon: Padding(
                padding: const EdgeInsets.all(10.0),
                child: Image.asset(
                  'assets/facebook_logo.jpg',
                  width: 20,
                  height: 20,
                  fit: BoxFit.fill,
                ),
              ),

prefixIcon is a 48*48 px wide widget by default as per flutter documentation. so to decrease the size of the icon add the padding on all the size and you will be able to adjust as per your requirements.

 prefixIcon: Container(
          margin: EdgeInsets.only(right: 5.0),
          decoration: BoxDecoration(
            color: Theme.of(context).buttonColor,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(8.0),
                bottomLeft: Radius.circular(8.0)),
          ),
          padding: EdgeInsets.all(8.0),
          child: SvgPicture.asset(
            "asset url",
            height: 20,
            width: 20,
          )),