class SampleStreamBuilder extends StatelessWidget { Stream<List<String>> loadData() async* { await Future.delayed(Duration(seconds: 3)); yield List.generate(10, (index) => "Index $index"); } @override Widget build(BuildContext context) { return Scaffold( body: StreamBuilder<List<String>>( stream: loadData(), builder: (context, snapshot) { return snapshot.hasData ? CustomScrollView(slivers: [ SliverList( delegate: SliverChildBuilderDelegate((context, index) { return ListTile( title: Text(snapshot.data[index]), ); }, childCount: snapshot.data.length), )], ) : Center(child: CircularProgressIndicator(), ); }, ), ); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)