这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);
}
“美国”语言环境应输出“🇺🇸”
最佳答案
您发布的代码工作正常,即 print(emoji)
成功打印 🇺🇸。
我假设您遇到的真正问题是 Flutter Text
widget显示如下:
这是美国国旗,但是,我不得不承认,当您在设备上看到它时,它看起来不像它,因为字体非常小,而且国旗具有相当高的分辨率。
您需要 use a custom font并使用以下方法将其应用于您的 Text
小部件:
Text(emoji,
style: TextStyle(
fontFamily: '...',
),
)
否则,转换和显示标志都可以正常工作。我相信它们只是看起来与您预期的不同。
关于flutter - 在 Flutter 中显示国旗字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56999448/