【问题标题】:Display country flag character in Flutter在 Flutter 中显示国旗字符
【发布时间】:2019-07-12 18:47:13
【问题描述】:

这个answer 有一些代码可以将语言环境转换为Java 中的国家/地区表情符号。我尝试在 Dart 中实现它,但没有成功。

我尝试将上面的代码转换为 Dart

  void _emoji() {
    int flagOffset = 0x1F1E6;
    int asciiOffset = 0x41;

    String country = "US";

    int firstChar = country.codeUnitAt(0) - asciiOffset + flagOffset;
    int secondChar = country.codeUnitAt(1) - asciiOffset + flagOffset;

    String emoji =
        String.fromCharCode(firstChar) + String.fromCharCode(secondChar);
    print(emoji);
  }

“美国”语言环境应输出“??????????”

【问题讨论】:

  • 使用系统频道,这正是你要找的

标签: flutter dart


【解决方案1】:

您发布的代码工作正常,即print(emoji) 成功打印??。

我认为您遇到的真正问题是 Flutter Text widget 显示如下:

这是美国国旗,但是,我不得不承认,当你在设备上看到它时,它看起来并不像它,因为它的字体非常小,而且国旗的分辨率相当高。

您需要 use a custom font 并将其应用到您的 Text 小部件,使用以下命令:

Text(emoji,
  style: TextStyle(
    fontFamily: '...',
  ),
)

否则,转换和显示标志都可以正常工作。我相信它们只是看起来与您预期的不同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 2018-10-26
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多