流生成器看起来不在小部件树中。请试试这个
Scaffold(
floatingActionButton : FloatingActionButton(),
body : SizedBox(
width: double.infinity,
child: Center(
child: StreamBuilder(
stream: _products.snapshots(),
initialData: 0,
builder: (
BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot,
) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Container( );
} else if (snapshot.connectionState == ConnectionState.active
|| snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return const Text('Error');
} else if (snapshot.hasData) {
return Text(
snapshot.data.toString(),
);
} else {
return const Text('Empty data');
}
} else {
return Text('State: ${snapshot.connectionState}');
}
),