How can I color part of a text for UI in dart/flutter?

孤街浪徒 提交于 2019-12-23 22:25:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!