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

问题描述 投票:0回答:1

如何更改文本部分的颜色?我试图这样做,所以文字说“Don't have an account? Register now!”,但我想为Register now!部分添加一种颜色。如果可能的话我怎么能这样做?

image

flutter flutter-layout
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.