【问题标题】:How to combine unicode characters in Flutter?如何在 Flutter 中组合 unicode 字符?
【发布时间】:2019-05-05 21:41:29
【问题描述】:

我需要在一些其他字符上显示组合的上划线字符(unicode U+0305),例如“2”或“x”。

https://www.fileformat.info/info/unicode/char/0305/index.htm

有没有办法在 Dart 中实现这一点?

提前致谢。

【问题讨论】:

    标签: unicode flutter


    【解决方案1】:

    您可以通过将 unicode 放在字母后面来组合:

    String overlined = 'O\u{0305}V\u{0305}E\u{0305}R\u{0305}';
    
    print(overlined);  // Output: O̅V̅E̅R̅ 
    

    更动态的版本(逻辑简单)是:

    void main() {
      String overlined = overline('I AM AN OVERLINED TEXT');
    
      print(overlined);  // Output: I̅ A̅M̅ A̅N̅ O̅V̅E̅R̅L̅I̅N̅E̅D̅ T̅E̅X̅T̅
    }
    
    String overline(String text) {
      return text.split('').map((String char) {
        if (char.trim().isEmpty)
          return char;
        else
          return '$char\u{0305}';
      }).join();
    }
    

    但是,这非常有限。更好的方法是使用 Flutter 的 Textstyle 属性来做到这一点:

    const Text(
      'OVER',
      style: TextStyle(decoration: TextDecoration.overline),
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      • 2013-09-22
      相关资源
      最近更新 更多