使用
StreamBuilder
import 'package:flutter/material.dart';import 'package:firebase_firestore/firebase_firestore.dart';class ExpenseList extends StatelessWidget { @override Widget build(BuildContext context) { return new StreamBuilder<QuerySnapshot>( stream: Firestore.instance.collection("expenses").snapshots, builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) { if (!snapshot.hasData) return new Text("There is no expense"); return new ListView(children: getExpenseItems(snapshot)); }); } getExpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) { return snapshot.data.documents .map((doc) => new ListTile(title: new Text(doc["name"]), subtitle: new Text(doc["amount"].toString()))) .toList(); }}


