Last active
May 20, 2020 19:22
-
-
Save e200/cd95e138e68b4082a926935b7d3dfb22 to your computer and use it in GitHub Desktop.
Flutter infinite scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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