Skip to content

Instantly share code, notes, and snippets.

@e200
Last active May 20, 2020 19:22
Show Gist options
  • Save e200/cd95e138e68b4082a926935b7d3dfb22 to your computer and use it in GitHub Desktop.
Save e200/cd95e138e68b4082a926935b7d3dfb22 to your computer and use it in GitHub Desktop.
Flutter infinite scroll
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Posts: ${_posts.length}'),
),
body: Builder(
builder: (context) {
if (_posts.isEmpty) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
itemBuilder: (BuildContext context, int index) {
if (index == _posts.length) {
return ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
],
),
);
} else {
final _post = _posts[index];
return ListTile(
title: Text(
_post['title'],
),
subtitle: Text(
_post['body'],
),
);
}
},
itemCount: _posts.length + 1,
);
},
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment