[英]What is the best way of formatting text in this Flutter example?
我有一张卡片,我点击它可以打开或关闭 DND。 目前,卡片上有一串文字,上面写着“DND ON”或“DND OFF”。 我想要实现的是在“免打扰”下方添加较小的字体和斜体:“警报、媒体、触摸声音”。
我的裸骨代码:
Card(
color: Color.fromARGB(255, 76, 175, 80),
elevation: 5.0,
child: InkWell(
splashColor: Colors.blueGrey,
onTap: () {
setState(() {
pressed = !pressed;
});
pressed ? _dndOn() : _dndOff();
},
child: Center(
child: Text(
pressed ? ('DND ON') : ('DND OFF'),
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
),
),
),
我的尝试:我尝试在 RichText 中定义我的字符串,使用 TextTheme,并创建具有各种样式的文本列。 每次我收到诸如“类型‘列’不是‘字符串’类型的子类型”或“‘RichText’类型不是‘字符串’类型的子类型等错误时。
你对我如何实现我想要的有什么想法吗?
您不能使用列小部件作为文本小部件的文本属性。 您需要以定义要保存的子项列表的方式使用它,在本例中为 Text 小部件列表。
Card(
color: Color.fromARGB(255, 76, 175, 80),
elevation: 5.0,
child: InkWell(
splashColor: Colors.blueGrey,
onTap: () {
setState(() {
pressed = !pressed;
});
pressed ? _dndOn() : _dndOff();
},
child: Center(
child: Column(
children: [
Text(
pressed ? 'DND ON' : 'DND OFF',
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
Text(
'Alarms, Media, Touch Sounds',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
],
),
),
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.