【问题标题】:How to make different style in same text widget?如何在同一个文本小部件中制作不同的样式?
【发布时间】:2019-07-04 20:48:48
【问题描述】:

如何为显示文本的不同部分应用不同的样式。如何在颤振中做到这一点?

例子:

你好世界

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    这可以使用RichText来实现

    RichText(
         text: TextSpan(
              text: 'Hello',
              style: TextStyle(fontSize: 22, color: Colors.black),
              children: <TextSpan>[
                 TextSpan(
                   text: 'World',
                   style: TextStyle(
                            fontSize: 24,
                            fontStyle: FontStyle.italic,
                            fontWeight: FontWeight.bold,
                   ),
                 ),
              ]
         ),
    ),
    

    【讨论】:

      【解决方案2】:
        return RichText(
        text: TextSpan(
          text: 'Can you ',
          style: TextStyle(color: Colors.black),
          children: <TextSpan>[
            TextSpan(
              text: 'find the',
              style: TextStyle(
                color: Colors.green,
                decoration: TextDecoration.underline,
                decorationStyle: TextDecorationStyle.wavy,
              ),
              recognizer: _longPressRecognizer,
            ),
            TextSpan(text: 'secret?'),
          ],
        ),
      );
      
      

      【讨论】:

        猜你喜欢
        • 2014-03-24
        • 2013-04-29
        • 2014-11-10
        • 2020-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-31
        相关资源
        最近更新 更多