Unicode символы не работают в Cloud Firestore - PullRequest
0 голосов
/ 19 декабря 2018

Я пытаюсь получить строку из облачного пожарного магазина в формате Unicode и отобразить ее в своем приложении для флаттера.

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),
    ),
  ),
);}

This is how it displays when it stored as a string

Принимая во внимание, что если я попытаюсь сохранить его в облачном хранилище и использовать тот же виджет 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),
    ),
  ),
);

}

This is how it show when I get the string from firestore

Пожалуйста, предоставьте решение для этого

1 Ответ

0 голосов
/ 19 декабря 2018

Храните ваши данные так, как вы хотите, чтобы они отображались в ваших виджетах (UTF-8), в этом случае не нужно использовать Юникод.

enter image description here

 TextSpan(text: text, style: defaultStyle)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...