flutter - 在 Flutter 的 Input Decoration 中为 labelText 添加 mandatory(*)

标签 flutter dart flutter-layout label

我想在 InputDecoration labelText 中添加星号并更改它的颜色(如红色),以便用户轻松理解此字段是必需的。

TextField(
    autofocus: true,
    controller: _nameCtrlr,
    keyboardType: TextInputType.text,
    decoration: InputDecoration(
    labelText: "Name *",
   ))

像这张图片的预期结果 Sample Image

最佳答案

您可以像这样使用 Rich Text Widget

RichText getRequiredLabel(String fieldName) {
  return RichText(
      text: TextSpan(
          style: TextStyle(color: Colors.black),
          text: fieldName,
          children: [
        TextSpan(text: '*', style: TextStyle(color: Colors.red))
      ]));
}

关于flutter - 在 Flutter 的 Input Decoration 中为 labelText 添加 mandatory(*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320684/

相关文章:

dart - 在 ListView 中向上滚动时,第一个项目不断重新渲染

flutter - 读取 Assets 图像尺寸而不加载到内存中

flutter - 我已经删除了我的 .android keystore 但我没有使用它,我该如何生成一个新的?

flutter - Dart/Flutter ffi(外部函数接口(interface)) native 回调,例如 : sqlite3_exec

flutter : Use Froala-editor in Flutter web

flutter - 状态错误 : field does not exist within the DocumentSnapshotPlatform Flutter Firestore

flutter - 如何拦截 Navigator.pop 并有条件地阻止导航返回?

flutter - 创建两个彼此独立的小部件

flutter 设计曲线布局

flutter - 如何从类方法返回枚举元素?