我是Flutter的新手所以请耐心等待.我有一个分页API,这意味着在调用时example.com?loaditems.php?page=0将加载前10个项目(播客列表),example.com?loaditems.php?page=1并将加载项目从10到20,依此类推.我希望StreamBuilder首先获取第0页,然后当列表到达底部时,它应该加载第1页并显示它.要检查我是否已到达列表视图中的最后一项,我使用的ScrollController是ListView.
现在我在bloc模式中使用StreamBuilder,ListView,InheritedWidget.我不确定我是否已正确实现它所以我将粘贴整个代码.我的问题是,这是正确的BLOC模式方式吗?如果不是那么它是什么?我还看到了这篇文章:https://crossingthestreams.io/loading-paginated-data-with-list-views-in-flutter/ 最后它说"更新:"但我无法理解它.
这是' 应用程序的切入点:
void main() => runApp(new MaterialApp(
title: "XYZ",
theme: ThemeData(fontFamily: 'Lato'),
home: PodcastsProvider( //This is InheritedWidget
child: RecentPodcasts(), //This is the child of InheritedWidget
),
));
Run Code Online (Sandbox Code Playgroud)
这是InheritedWidget PodcastsProvider:
class PodcastsProvider extends InheritedWidget{
final PodcastsBloc bloc; //THIS IS THE BLOC
PodcastsProvider({Key key, Widget child})
: bloc = PodcastsBloc(),
super(key: key, child: child);
@override
bool updateShouldNotify(InheritedWidget oldWidget) {
return true;
}
static PodcastsBloc of(BuildContext context){
return (context.inheritFromWidgetOfExactType(PodcastsProvider) …Run Code Online (Sandbox Code Playgroud) flutter ×1