Android 我想在嵌套子对象中的flifter中将数据添加到Firebase?

Android 我想在嵌套子对象中的flifter中将数据添加到Firebase?,android,firebase,flutter,dart,firebase-realtime-database,Android,Firebase,Flutter,Dart,Firebase Realtime Database,数据样本 database |__news |__category1 | | | |__post1 | | |__text: "Lorem ipsum 1" | | |__title: "Title of post1" | |__post2 | | |__text: "Lorem ipsum 2" | | |

数据样本

database
|__news
    |__category1
    |    |
    |    |__post1
    |    |    |__text: "Lorem ipsum 1"
    |    |    |__title: "Title of post1"
    |    |__post2
    |    |    |__text: "Lorem ipsum 2"
    |    |    |__title: "Title of post2"
    |    |__description: "description text"
    |    |__id: "id of category"
    |    .
    |    .
    |
    |__category2
    |    |
    |    |__post34
    |    |    |__text: "Lorem ipsum 34"
    |    |    |__title: "Title of post34"
    |    .
    |    .
现在我有一个在Firebase中创建数据的简单函数:

 void createRecord() {
    databaseReference.child("post1").set({
      'text': 'Mastering EJB',
      'title': 'Programming Guide for J2EE'
    });
我的问题是我想在
=>news->category1>[posts]

因此,我需要做什么来迭代到
post1

以将相同的数据写入
/news/category1/post1
,您可以执行以下操作:

databaseReference.child("/news/category1/post1").set({
  'text': 'Mastering EJB',
  'title': 'Programming Guide for J2EE'
});

作为一个侧节点,您似乎正在嵌套类别和帖子,这与Firebase对和的建议背道而驰

我建议您不要只拥有一棵树,而是:

database
|__news
    |__category1
    |    |
    |    |__post1
    |    |    |__text: "Lorem ipsum 1"
    |    |    |__title: "Title of post1"
    |    |__post2
    |    |    |__text: "Lorem ipsum 2"
    |    |    |__title: "Title of post2"
    |    .
    |    .
    |
    |__category2
    |    |
    |    |__post34
    |    |    |__text: "Lorem ipsum 34"
    |    |    |__title: "Title of post34"
    |    .
    |    .
|__news_categories
    |__category1
    |    |__description: "description text"
    |    |__id: "id of category"
    |
    |__category2
    |    |__description: "description text of category 2"
    |    |__id: "id of category2"
    |    .
    |    .