NotoColorEmoji-Regular.ttf
放入资产中,并在 pubspec.yml 中配置它
- family: NotoColorEmoji
fonts:
- asset: assets/fonts/Noto_Color_Emoji/NotoColorEmoji-Regular.ttf
我是这样使用的:
Text(emoji,
style: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 22,
height: 1,
fontFamily: 'NotoColorEmoji',
color: const Color(0xFF191919),
),
)
这适用于
它不起作用
我试过了
flutter clean
flutter run
)我发现了
作为解决方法,我们目前在 ios 上使用系统字体:
TextStyle textEmoji(BuildContext context) {
return TextStyle(
fontFamily: Platform.isIOS
? null // see https://stackoverflow.com/questions/74710185/flutter-emoji-font-working-om-ios-emulator-but-not-on-real-device
: 'NotoColorEmoji',
// ...
);
}
编辑:我刚刚意识到你正在谈论一种不同的字体,仍然将其留在这里,以防它对某人有帮助
对于现在正在阅读本文的人来说,它似乎已在 iOS 上修复。我在我的 flutter 应用程序中使用了 https://fonts.google.com/noto/specimen/Noto+Emoji 字体,它适用于我的 iOS 版本构建 ✨
在
pubspec.yaml
-fonts:
- family: NotoEmoji
fonts:
- asset: fonts/NotoEmoji-VariableFont_wght.ttf
weight: 400
我还为表情符号创建了一个小部件:
class Emoji extends StatelessWidget {
final String emoji;
final TextStyle? style;
final EdgeInsets padding;
const TextEmoji(
emoji, {
this.style,
this.padding = EdgeInsets.zero,
});
@override
Widget build(BuildContext context) {
final theme = Provider.of<MyThemeData>(context);
final emojiStyle = TextStyle(
fontSize: theme.dimensions.emojiFontSize,
fontFamily: 'NotoEmoji',
color: theme.myColors.emojiText(),
);
return Padding(
padding: padding,
child: Text(
emoji,
style: style != null ? emojiStyle.merge(style) : emojiStyle,
),
);
}
}