【问题标题】:Unicode characters not working in Cloud FirestoreUnicode 字符在 Cloud Firestore 中不起作用
【发布时间】:2019-05-20 04:18:33
【问题描述】:

我正在尝试从 Cloud Firestore 中获取 unicode 格式的字符串,并将其显示在我的 Flutter 应用程序中。

c。 10\u{207B}\u{2076} 秒:强子纪元开始:随着宇宙冷却到大约 10\u{00B9}\u{2070} 开尔文,发生夸克-强子转变,夸克结合形成更多复杂粒子——强子。这种夸克限制包括质子和中子(核子)的形成,它们是原子核的组成部分。

当我将它存储为字符串并在 RichText 小部件中显示时,它工作正常:

Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final record = Record.fromSnapshot(data);
String temp1 = "c. 10\u{207B}\u{2076} seconds: Hadron epoch begins: As the universe cools to about 10\u{00B9}\u{2070} kelvin, a quark-hadron transition takes place in which quarks bind to form more complex particles—hadrons. This quark confinement includes the formation of protons and neutrons (nucleons), the building blocks of atomic nuclei.";

return Padding(
  key: ValueKey(record.name),
  padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  child: Container(
    child: RichText(
      text: TextSpan(text: temp1, style: defaultStyle),
    ),
  ),
);}

而如果我尝试将其存储在云 Firestore 上并使用相同的 RichText 小部件,它就无法正常工作。它只是按原样打印。:

Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final record = Record.fromSnapshot(data);
//String temp1 = "c. 10\u{207B}\u{2076} seconds: Hadron epoch begins: As the universe cools to about 10\u{00B9}\u{2070} kelvin, a quark-hadron transition takes place in which quarks bind to form more complex particles—hadrons. This quark confinement includes the formation of protons and neutrons (nucleons), the building blocks of atomic nuclei.";

return Padding(
  key: ValueKey(record.name),
  padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  child: Container(
    child: RichText(
      text: TextSpan(text: record.name, style: defaultStyle),
    ),
  ),
);

}

请提供解决方案

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    按照您希望在小部件中显示的方式存储您的数据 (UTF-8),不需要在这种情况下使用 unicode。

     TextSpan(text: text, style: defaultStyle)
    

    【讨论】:

    • 我无法这样存储它。如果我尝试复制粘贴带有上标的文本,它只是正常粘贴而没有任何上标。
    • 这很奇怪,我可以直接在 Firestore 上做
    • 你如何在firestore上存储值,你能上传截图吗?
    • 好的,现在尝试在 Firestore 上使用 unicode 来查看它的外观并再次添加图像
    • 我猜这是 Windows 或浏览器的问题。当我尝试将文本粘贴到浏览器的地址栏中时,它被正常粘贴,没有任何上标。这发生在 Opera & Edge 中。然而,如果我尝试将它粘贴到写字板中,它会与上标一起很好地粘贴。我可以知道您使用的是哪种浏览器和操作系统吗?
    猜你喜欢
    • 2020-09-12
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 2021-11-22
    • 2018-03-18
    相关资源
    最近更新 更多