从 Firebase 存储和获取 MD 格式的数据

问题描述 投票:0回答:1

我们正在尝试将此数据存储到 Firebase 中,使用字符串字段似乎不是问题

### Whether you’ve posted a task or you’ve completed one, what should reviews provide?

Well-written reviews should provide constructive feedback on your experience, helping community members make better-informed decisions.

### What should reviewers consider when writing a review?

Reviewers should consider whether they'd recommend the Tasker or Customer to other community members. It's important to be honest and clear in reviews.

### What are some aspects to consider in a review?

Here are some things to consider in a review:

- **Was the communication great?**
- **Were instructions clear?**
- **How accurate was the task description?**
- **Was the task performed to a high standard?**
- **Did you receive support throughout the task?**
- **Were the task outcomes met?**
- **Did you receive feedback during and after the task?**

### Can Taskers be rated on specific attributes?

Yes, Taskers can be rated on specific attributes such as punctuality and communication skills. However, it's important to leave a written review to elaborate on this.

### What if someone wants to remain anonymous when rating the other person?

If someone wants to remain anonymous, they can skip their written review and just leave a rating out of 5.

然后我们使用 Flutter Markdown 包尝试渲染它,但似乎看不到换行符

class ArticleDetail extends StatelessWidget {
  final String subCategoryDocumentId;
  final String parentCategoryDocumentId;
  final String articleDocumentId;
  final String title;

  const ArticleDetail({
    Key? key,
    required this.subCategoryDocumentId,
    required this.parentCategoryDocumentId,
    required this.articleDocumentId,
    required this.title,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: FutureBuilder<DocumentSnapshot>(
        future: FirebaseFirestore.instance
            .collection('helpCentre')
            .doc(parentCategoryDocumentId)
            .collection('subCategory')
            .doc(subCategoryDocumentId)
            .collection('articles')
            .doc(articleDocumentId)
            .get(),
        builder: (context, snapshot) {
          if (snapshot.hasError) {
            return Text('Error: ${snapshot.error}');
          }

          if (snapshot.connectionState == ConnectionState.waiting) {
            return const CircularProgressIndicator();
          }

          var data = snapshot.data?.data() as Map<String, dynamic>;
          var articleBody = data['body'];

          return Markdown(
            data: articleBody,
            selectable: true,
          );
        },
      ),
    );
  }
}

我们最终得到了这个

flutter firebase google-cloud-firestore markdown
1个回答
0
投票

Firebase 控制台不能很好地处理文本中的换行符,因此我建议不要使用控制台输入或修改多行文本。

Firestore 完全按照您将文本传递给 API 的方式存储文本,因此最好的方法是通过代码输入文本。我通常使用最小的 Node.js 脚本,和/或为此类操作编写自定义管理(网页)页面。

© www.soinside.com 2019 - 2024. All rights reserved.