如何在 Flutter 中设置红色星号 (*) 为必填字段

GoP*_*Pro 7 dart flutter flutter-layout

我正在尝试在 RichText 小部件中获取红色星号( );我可以使用 style 属性。但它会使整个文本变成红色。我只希望星号()是红色的。任何线索,如何实现它?

这是我的 RichText 小部件,现在我可以查看与文本其余部分颜色相同的星号 (*)。

RichText(
    text: TextSpan(
        text: '$labelText *',
        style: TextStyle(
            color: labelColor, fontWeight: fontWeight, fontSize: fontSize)),
    textScaleFactor: labelTextScale,
    maxLines: labelMaxLines,
    overflow: overflow,
    textAlign: textAlign,
  );
Run Code Online (Sandbox Code Playgroud)

GoP*_*Pro 7

我想出了怎么做。TextSpan 有一个子属性,它采用 List 作为值。

所以我为星号(*)分配了一个TextSpan。

 RichText(
    text: TextSpan(
        text: '$labelText',
        style: TextStyle(
            color: labelColor, fontWeight: fontWeight, fontSize: fontSize),
        children: [
           TextSpan(
                  text: ' *',
                  style: TextStyle(
                      color: Colors.red,
                      fontWeight: fontWeight,
                      fontSize: fontSize))
        ]),
    textScaleFactor: labelTextScale,
    maxLines: labelMaxLines,
    overflow: overflow,
    textAlign: textAlign,
  ),
Run Code Online (Sandbox Code Playgroud)