flutter - 如何设置嵌入文本的样式?
问题描述
我在下面有一段代码,我想以不同的方式设置文本“From”的样式,即,将其显示为黑色和粗体。它应该保持相同的格式。
谢谢你。
Text("From :" + " " + from, style: GoogleFonts.viga(
color: Colors.blue[800],
fontWeight: FontWeight.w500,
), /*TextStyle(color: Colors.blue[800],)*/
),
解决方案
您可以使用RichText
和TextSpan
类来实现此行为。
RichText(
text: TextSpan(
text: 'From:',
style: TextStyle(color: Colors.black),
children: <TextSpan>[
TextSpan(text: ' $from', style: TextStyle(color: Colors.blue[800])),
],
),
)
你可以在这里阅读更多关于它的信息
推荐阅读
- c# - 如何在c#后台服务中运行多个cron表达式
- c++ - 动态数组似乎比它的动态大小变量大
- go - 'protoc-gen-go-grpc: program not found or is not executable',尽管付出了所有努力
- python - 无法从 anaconda navigator 启动 jupyter notebook 或 spyder
- python - Kivy 按钮和变量的问题
- nginx - 告诉 Nginx 在不同的目录中查找我的主题文件
- django - Django 遍历 Queryset 并获取用户输入
- react-native - 为什么我的应用程序停止发出 api 请求?
- azure - 如何在 Azure 管道运行期间检索 VsTest 测试计划测试用例 ID 并在自动化代码中使用它
- c# - C# UWP Richeditbox 缩放内容有问题