相关疑难解决方法(0)

Firebase Firestore 新行命令

我正在尝试使用换行命令在文本中创建新行。从这个问题看来,这是不可能的:New Line Command (\n) Not Working With Firebase Firestore Database Strings

现在还是这样吗?假设是这样,Flutter 是否提供了与以下功能类似的任何方法来解决这个问题?

label.text = stringRecived.replacingOccurrences(of: "\n", with: "\n")
Run Code Online (Sandbox Code Playgroud)

*更多上下文:这是我输入数据的 Firestore 字符串的图片。 带换行符的 Firestore 字符串

然后我使用未来的构建器从 Firestore 调用它,然后将字符串(在本例中为注释)传递给另一个小部件。

return new SocialFeedWidget(
  filter: false,
  articleID: document['article'],
  article_header: document['article_title'],
  userName: document['author'],
  spectrumValue: document['spectrum_value'].toDouble(),
  comment: document['comment'],
  fullName: document['firstName'] + " " + document['lastName'],
  user_id: document['user_id'],
  postID: document.documentID,
  posterID: userID,
  );
}).toList(),
Run Code Online (Sandbox Code Playgroud)

在新的小部件中,我将它作为字符串传入并通过 Text 小部件提供,如下所示:

new Text(
  comment,
  style: new TextStyle(
    color: Color.fromRGBO(74, 74, 74, 1.0),
    fontSize: 13.0,
  ),
),
Run Code Online (Sandbox Code Playgroud)

当它出现时,它仍然在字符串中包含 \n。 从控制台

firebase flutter google-cloud-firestore

13
推荐指数
2
解决办法
7033
查看次数

新行命令(\n)不使用Firebase Firestore数据库字符串

我正在使用Swift制作应用程序,而我正在使用Firebase Firestore.Firestore是一个数据库,它包含一些我放入的字符串UILabel.我的一些叮咬,我使用新的行命令(或\n).所以我的一些字符串看起来像这样:

"This is line one\nThis is line two\nThis is line three"
Run Code Online (Sandbox Code Playgroud)

但是,无论何时检索到该字符串,它都是addetoto UILabel并且看起来像这样......

这是第一行\n这是第二行\n这是第三行

......应该是这样......

这是第一行

这是第二行

这是第三行

我假设这\n不适用于来自数据库的字符串?我试过双重逃避\\n.有人有解决方法吗?

这是我正在使用的代码......

    database.collection("songs").whereField("storyTitle", isEqualTo: "This is the story header").getDocuments { (snapshot, error) in

        for document in (snapshot?.documents)! {
            self.storyBodyLabel.text = (document.data()["storyBody"] as? String)!
   }
}
Run Code Online (Sandbox Code Playgroud)

string newline firebase swift google-cloud-firestore

4
推荐指数
1
解决办法
5596
查看次数