Created
April 29, 2020 07:53
-
-
Save sharmadhiraj/98483d98c183f8554129a93f3631d2b2 to your computer and use it in GitHub Desktop.
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
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