如何在dart / flutter中为UI上色文本的一部分?

时间:2019-04-20 22:10:07

标签: flutter flutter-layout

如何更改文本部分的颜色? 我正在尝试使文本显示为“ Don't have an account? Register now!” 但我想为Register now!部分添加颜色。如果可能的话我该怎么办?

image

1 个答案:

答案 0 :(得分:0)

使用RichText https://docs.flutter.io/flutter/widgets/RichText-class.html

RichText(
        text: TextSpan(
          text: "Don't have an account? ",
          style: TextStyle(color: Colors.black, fontSize: 40),
          children: <TextSpan>[
            TextSpan(text: ' Register now!', style: TextStyle(color: Colors.red)),
          ],
        ),
      );

Result