【问题标题】:how to add image in flutter TextFormField inside prefixIcon如何在prefixIcon内的颤动TextFormField中添加图像
【发布时间】:2023-03-17 08:22:01
【问题描述】:

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

【问题讨论】:

  • 添加一些你用TextFormField尝试过的代码

标签: image flutter size textfield assets


【解决方案1】:
 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,
          )),

【讨论】:

【解决方案2】:

您可以在 TextFormField 小部件中添加如下前缀图标,

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

prefixIcon 默认情况下是一个 48*48 像素宽的小部件,根据 Flutter documentation。因此要减小图标的大小,请在所有大小上添加填充,您将能够根据您的要求进行调整。

【讨论】:

    猜你喜欢
    • 2021-10-21
    • 2020-12-02
    • 2020-06-22
    • 2021-06-22
    • 2022-11-30
    • 2020-03-17
    • 1970-01-01
    • 2019-11-05
    • 2022-11-01
    相关资源
    最近更新 更多