我试图将TextSpan作为TextSpan的子元素添加,但出现错误。

huangapple go评论48阅读模式
英文:

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: () =&gt; print(&#39;SignUp Pressed&#39;),
      child: RichText(
        text: TextSpan(
          children: TextSpan(
            text: &#39;Don\&#39;t have an Account&#39;,
            style: TextStyle(
              color: Colors.white,
              fontSize: 18.0,
              fontWeight: FontWeight.w500,
            ),
          ),
          TextSpan(
            text: &#39;Don\&#39;t have an Account&#39;,
            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: &#39;Hello &#39;,
style: DefaultTextStyle.of(context).style,
children: const &lt;TextSpan&gt;[
  TextSpan(text: &#39;bold&#39;, style: TextStyle(fontWeight: FontWeight.bold)),
  TextSpan(text: &#39; world!&#39;),
],
),
)

you can read more about RichText in the official documentation here

huangapple
  • 本文由 发表于 2023年2月6日 02:47:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定