我还是个初学者,正在学习文本字段.我有一个文本字段,如下所示:

enter image description here

我想在前缀图标和可编辑文本之间添加一些填充.以下是我的代码:

TextField(
  style: const TextStyle(
    color: Color.fromARGB(125, 0, 0, 0),
  ),
  decoration: InputDecoration(
    border: const OutlineInputBorder(),
    hintText: 'Full Name',
    hintStyle: TextStyle(color: Colors.grey[300]),
    fillColor: Colors.white,
    filled: true,
    prefixIcon: Container(
      decoration: BoxDecoration(
        border: Border(
          right: BorderSide(
            color: Colors.grey[300]!,
          ),
        ),
      ),
      child: const Icon(
        Icons.person_outline,
        color: kPurple,
      ),
    ),
  ),
  cursorColor: kPurple,
)

推荐答案

您可以使用填充来包装图标小工具.或者可替换地将填充物添加到容器,

--试试下面的代码,在我这边运行得很好

   TextField(
          style: const TextStyle(
            color: Color.fromARGB(125, 0, 0, 0),
          ),
          decoration: InputDecoration(
            border: const OutlineInputBorder(),
            hintText: 'Full Name',
            hintStyle: TextStyle(color: Colors.grey[300]),
            fillColor: Colors.white,
            filled: true,
            prefixIcon: Container(
            margin: const EdgeInsets.only(
                  right: 40, top: 20, bottom: 20, left: 40),
              decoration: BoxDecoration(
                border: Border(
                  right: BorderSide(
                    color: Colors.grey[300]!,
                  ),
                ),
              ),
              child: const Icon(
                Icons.person_outline,
                color: Colors.purpleAccent,
              ),
            ),
          ),
          cursorColor: Colors.purple,
        ),
      

Flutter相关问答推荐

具有可变高度小部件的SingleChildScrollView内的列

自动测试Flutter应用程序进行QA的最佳方法是什么?

如何防止alert 对话框在收到通知时出现在某个flutter页面中

Flutter:如何从Bottom Navigator中删除此内容

我如何才能收到每天重复的预定通知?

查询满足AND条件的文档的FiRestore

如何在抖动中将PNG图像转换为WebP

带有附加图像的ListTile

如何在 VS Code 中启用 Flutter 运行/调试工具栏?

课程中的访问Provider

Flutter中如何实现带有变化图标的浮动操作按钮?

提供者、存储库和服务之间有什么区别?

如何从底部导航栏打开 bottomModal 表?

graphql_flutter 错误:非抽象类GraphQLWebSocketChannel缺少实现

按下 Command+W 时关闭窗口

Flutter - 定义按钮的优雅方式

如何在 flutter 的alert 对话框中实现进度指示器?

Flutter RawMaterialButton 常量相对大小

为什么 Flutter riverpod 直接分配不起作用但方法可以

如何将所有行项目平等地放在一行中?Flutter