问题
How can I change the color of part of a text?
I'm trying to make it so the text says "Don't have an account? Register now!
"
but I want to add a color to the Register now!
part. How can I do this if possible?
image
回答1:
Use 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)),
],
),
);
来源:https://stackoverflow.com/questions/55778185/how-can-i-color-part-of-a-text-for-ui-in-dart-flutter