enter image description here

如何改变这个的 colored颜色 ?并放置在其他位置.(如顶部的中心)

代码:

TextField(
      maxLength: 25,
      textAlign: TextAlign.center,
      obscureText: obscuretext,
      decoration: InputDecoration(
        contentPadding: const EdgeInsets.all(8.0),
        border: InputBorder.none,
        iconColor: Colors.grey.shade800,
        hintText: hintText,
        hintStyle: TextStyle(
          fontWeight: FontWeight.w600,
          fontSize: 16,
          color: Colors.grey.shade800,
        ),
        filled: true,
        fillColor: Colors.white54,
      ),
    );

推荐答案

try 下面的代码并使用buildCounter

Padding(
  padding: const EdgeInsets.all(16),
  child: TextFormField(
    maxLength: 25,
    decoration: const InputDecoration(
      border: OutlineInputBorder(),
       // If you want change color only of counterText then refer below style
      /*counterStyle: TextStyle(
        color: Colors.green,
      ),*/
    ),
    buildCounter: (BuildContext context,
            {int? currentLength, int? maxLength, bool? isFocused}) =>
        Container(
      alignment: Alignment.topLeft,//use alignment position on your need
      child: Text(
        '${currentLength.toString()}/${maxLength.toString()}',
        style: const TextStyle(
          color: Colors.indigo,
        ),
      ),
    ),
  ),
),

Result Screen-> image

Flutter相关问答推荐

从底部开始固定,然后使其可拖曳Flutter

如何在FiRestore中正确编写OR查询

如何在抖动中预加载一条路由,或者即使在屏幕外也保持加载小工具?

使小部件处于有状态状态会导致hasSize异常

为什么Spotify Auth API返回400,而";code_verier不正确?

怎么才能像这样在摆动着这些曲线呢?

如何更改Flutter 中文本的混合模式?

打开键盘时屏幕组件会被压扁

Flutter:如何设置 PersistentFooterButtons 背景?

Flutter 中的区域不匹配

Riverpod中stateNotiferProvider和notifierProvider的区别

如何防止键盘将内容向上推?

Freezed+BLoc 如何从 BLoc Listener 查看当前状态和特定状态的变量

具有 BLOC 和存储库模式的 Flutter Workmanager

应用程序和应用程序内的 webview 之间的单点登录

通过点击缩略图加载全屏图像

如何使用 Navigator 2.0 导航到任何页面?

type '_InternalLinkedHashMap' 不是使用 http 包的'String' 类型的子类型

如何在 IntroductionScreen 小部件 Flutter 中制作全屏渐变色

RangeError(索引):无效值:有效值范围为空:点击文章时为0