颤振列表构建

时间:2020-04-24 07:48:07

标签: list flutter dart

void getData() {
    Firestore.instance
        .collection(collectionName)
        .getDocuments()
        .then((QuerySnapshot snapshot) {
      snapshot.documents.forEach((f) {
        String text = '${f.data}'.split(":")[0].substring(1);
        print(text);
      });
    });
}

该代码进入控制台,

I/flutter (25628): Country
I/flutter (25628): Meals
I/flutter (25628): Drinks

我需要这些值到List数组,例如

List<String> data = {"Country", "Meals", "Drinks"};

它显示在

Widget _text() {
  return Column(
    children: <Widget>[
      Text(data[0]), 
      Text(data[1]), 
      Text(data[2])
    ],
  );

}

1 个答案:

答案 0 :(得分:0)

List<Widget> data = [];

void getData() {
Firestore.instance
    .collection(collectionName)
    .getDocuments()
    .then((QuerySnapshot snapshot) {
  snapshot.documents.forEach((f) {
    String text = '${f.data}'.split(":")[0].substring(1);
    data.add(Text(text));
  });
});
}

Widget _text() {
return Column(
  children: data,
);
}