Skip to content

Instantly share code, notes, and snippets.

@sharmadhiraj
Created April 29, 2020 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharmadhiraj/98483d98c183f8554129a93f3631d2b2 to your computer and use it in GitHub Desktop.
Save sharmadhiraj/98483d98c183f8554129a93f3631d2b2 to your computer and use it in GitHub Desktop.
Widget getBody() {
if (_photos.isEmpty) {
if (_loading) {
return Center(
child: Padding(
padding: const EdgeInsets.all(8),
child: CircularProgressIndicator(),
));
} else if (_error) {
return Center(
child: InkWell(
onTap: () {
setState(() {
_loading = true;
_error = false;
fetchPhotos();
});
},
child: Padding(
padding: const EdgeInsets.all(16),
child: Text("Error while loading photos, tap to try agin"),
),
));
}
} else {
return ListView.builder(
itemCount: _photos.length + (_hasMore ? 1 : 0),
itemBuilder: (context, index) {
if (index == _photos.length - _nextPageThreshold) {
fetchPhotos();
}
if (index == _photos.length) {
if (_error) {
return Center(
child: InkWell(
onTap: () {
setState(() {
_loading = true;
_error = false;
fetchPhotos();
});
},
child: Padding(
padding: const EdgeInsets.all(16),
child: Text("Error while loading photos, tap to try agin"),
),
));
} else {
return Center(
child: Padding(
padding: const EdgeInsets.all(8),
child: CircularProgressIndicator(),
));
}
}
final Photo photo = _photos[index];
return Card(
child: Column(
children: <Widget>[
Image.network(
photo.thumbnailUrl,
fit: BoxFit.fitWidth,
width: double.infinity,
height: 160,
),
Padding(
padding: const EdgeInsets.all(16),
child: Text(photo.title,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16)),
),
],
),
);
});
}
return Container();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment