如何在Flutter中使颜色成为UI文本的一部分?

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

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

image

flutter flutter-layout
1个回答
3
投票

使用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.