首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TextSpan之间留出空间

在TextSpan之间留出空间
EN

Stack Overflow用户
提问于 2022-04-23 12:49:58
回答 3查看 290关注 0票数 2

我试图在TextSpan之间留出空间--在TextSpan之间添加空间的最好方法是什么?

代码语言:javascript
复制
child: RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: 'Don\'t have an Account?',
              style: TextStyle(
                color: Colors.white,
                fontSize: 15.0,
                fontWeight: FontWeight.w400,
              ),
            ),
            
            TextSpan(
              text: 'Sign Up',
              style: TextStyle(
                color: Colors.white,
                fontSize: 15.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
EN

回答 3

Stack Overflow用户

发布于 2022-04-23 13:57:03

SizedBox小部件可以在两个小部件之间使用,以在两个小部件之间添加空间。使用SizedBox,方法是用WidgetSpan宽度包装它

代码语言:javascript
复制
child: RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: 'Don\'t have an Account?',
              style: TextStyle(
                color: Colors.white,
                fontSize: 15.0,
                fontWeight: FontWeight.w400,
              ),
            ),
            WidgetSpan(
             child: SizedBox(width: 10),
            ),
            TextSpan(
              text: 'Sign Up',
              style: TextStyle(
                color: Colors.white,
                fontSize: 15.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
票数 2
EN

Stack Overflow用户

发布于 2022-04-23 14:40:45

如果您希望在文本之间获得最大的空间,则可以选择Row小部件。对于RichText内部的x空间,您可以使用

代码语言:javascript
复制
TextSpan(...),
WidgetSpan(child: SizedBox(width: x)),
TextSpan(...),
代码语言:javascript
复制
RichText(
  text: const TextSpan(
    children: [
      TextSpan(
        text: 'Don\'t have an Account?',
        style: TextStyle(
          color: Color.fromARGB(255, 0, 0, 0),
          fontSize: 15.0,
          fontWeight: FontWeight.w400,
        ),
      ),

      WidgetSpan(child: SizedBox(width: 10)), ///this

      TextSpan(
        text: 'Sign Up',
        style: TextStyle(
          color: Color.fromARGB(255, 0, 0, 0),
          fontSize: 15.0,
          fontWeight: FontWeight.bold,
        ),
      ),
    ],
  ),
),
票数 2
EN

Stack Overflow用户

发布于 2022-04-23 14:32:06

您可以使用高度属性在TextStyle上创建一些间隔:

代码语言:javascript
复制
 RichText(
          text:  TextSpan(
            children: [
              TextSpan(
                text: 'Don\'t have an Account?',
                style: TextStyle(
                  height: 1.5, //USE THIS PROPERTY
                  color: Colors.white,
                  fontSize: 15.0,
                  fontWeight: FontWeight.w400,
                ),
              ),
              SizedBox(height: 10),
              TextSpan(
                text: 'Sign Up',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 15.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
        ),

文档中的更多信息:https://api.flutter.dev/flutter/painting/TextStyle/height.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71979775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档