英文:
I was trying to add TextSpan as the children of TextSpan, but I'm getting error
问题
我遇到的错误是:
"参数类型'TextSpan'无法分配给参数类型'List
以下是代码:
Widget buildSignUpBtn() {
return GestureDetector(
onTap: () => print('SignUp Pressed'),
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Don\'t have an Account',
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.w500,
),
),
TextSpan(
text: 'Don\'t have an Account',
style: TextStyle(
color: Colors white,
fontSize: 18.0,
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}
请帮我修复这个问题!
英文:
The error which I'm getting is :
" The argument type 'TextSpan' can't be assigned to the parameter type 'List<InlineSpan>? "
Here is the code:
Widget buildSignUpBtn() {
return GestureDetector(
onTap: () => print('SignUp Pressed'),
child: RichText(
text: TextSpan(
children: TextSpan(
text: 'Don\'t have an Account',
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.w500,
),
),
TextSpan(
text: 'Don\'t have an Account',
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.w500,
),
),
),
),
);
}
Please help me to fix this!
答案1
得分: 0
在children
属性中,它接受了一个TextSpan的列表,就像这样:
RichText(
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: const <TextSpan>[
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' world!'),
],
),
)
您可以在官方文档中了解更多关于RichText的信息,链接在此处:官方文档。
英文:
it is taking list of TextSpan in the children property just like this:
RichText(
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: const <TextSpan>[
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' world!'),
],
),
)
you can read more about RichText in the official documentation here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论