我想使用Flutter在文本小部件中显示表情符号。
当我从互联网上复制示例表情符号时,其中的一些在我的IDE中显示为2个字符。
例如:
static String dualCharEmoji = "⚔️";
static String singleCharEmoji = "?";
当我在文本小部件中使用此变量时,它们两个都可以正常工作:
Text("⚔️",)
Text("?",)
但是,仅在首次运行应用程序时,双字符表情符号仅显示为其第一个字符。
即仅在首次打开应用程序时,剑图标才会显示为⚔
而不是⚔️
重新加载后,它得到修复,并且热重新加载/热重启不会使其再次出错。
我的问题是:
这是一个错误吗?我在这里错过了一些细节吗?为什么只有在首次打开应用程序时才会发生这种情况?
如何从一开始显示2号大小的表情符号?
我正在使用以下Flutter版本:
>flutter --version
Flutter 1.9.1+hotfix.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision cc949a8e8b (9 weeks ago) • 2019-09-27 15:04:59 -0700
Engine • revision b863200c37
Tools • Dart 2.5.0
请参见下面的最小可重复示例:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',home: MyHomePage(),);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static String dualCharEmoji = "⚔️";
static String singleCharEmoji = "?";
String text = dualCharEmoji;
int count = 0;
void swapText() {
setState(() {
if (count % 2 == 0)
text = singleCharEmoji;
else
text = dualCharEmoji;
count++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
Text(
text,style: TextStyle(fontSize: 50),),],floatingactionButton: FloatingactionButton(
onpressed: swapText,);
}
}