Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1.  
  2. class HomeScreen extends StatefulWidget {
  3. @override
  4. _HomeScreenState createState() => _HomeScreenState();
  5. }
  6.  
  7. class _HomeScreenState extends State<HomeScreen> {
  8. Service _service;
  9.  
  10. @override
  11. void initState() {
  12. print('init homescreen');
  13. _service = Service();
  14. super.initState();
  15. // _service.getNowPlaying();
  16. }
  17.  
  18. var imageUrl = "http://image.tmdb.org/t/p/w500/";
  19.  
  20. @override
  21. Widget build(BuildContext context) {
  22. return Scaffold(
  23. appBar: AppBar(
  24. title: Text("Aplikasi Fetch Data"),
  25. ),
  26. body: Center(
  27. child: FutureBuilder<MovieResponse>(
  28. future: _service.getNowPlaying(),
  29. builder: (context, snapshot) {
  30. if (snapshot.hasData) {
  31. return ListView.builder(
  32. itemCount: snapshot.data.results.length,
  33. itemBuilder: (context, index) {
  34. var gambar =
  35. imageUrl + snapshot.data.results[index].posterPath;
  36. var data = snapshot.data.results[index];
  37. if (snapshot.data.results.length == null) {
  38. return Text("Tidak ada data");
  39. } else {
  40. return Padding(
  41. padding: const EdgeInsets.all(8.0),
  42. child: Row(
  43. mainAxisSize: MainAxisSize.max,
  44. children: <Widget>[
  45. Flexible(
  46. flex: 1,
  47. fit: FlexFit.tight,
  48. child: Container(
  49. height: 150,
  50. width: 100,
  51. decoration: BoxDecoration(
  52. borderRadius:
  53. BorderRadius.all(Radius.circular(10))),
  54. child: ClipRRect(
  55. borderRadius:
  56. BorderRadius.all(Radius.circular(10)),
  57. child: CachedNetworkImage(
  58. imageUrl: gambar,
  59. placeholder: (context, url) =>
  60. CircularProgressIndicator(),
  61. errorWidget: (context, url, error) =>
  62. Icon(Icons.error),
  63. ),
  64. ),
  65. ),
  66. ),
  67. Flexible(
  68. flex: 2,
  69. fit: FlexFit.tight,
  70. child: Container(
  71. height: 150,
  72. decoration: BoxDecoration(
  73. borderRadius:
  74. BorderRadius.all(Radius.circular(10)),
  75. color: Colors.white,
  76. boxShadow: [
  77. BoxShadow(
  78. color: Colors.blue, blurRadius: 3)
  79. ]),
  80. child: Padding(
  81. padding: const EdgeInsets.all(8.0),
  82. child: Column(
  83. children: <Widget>[
  84. Text(
  85. data.title,
  86. style: TextStyle(
  87. fontSize: 20,
  88. fontWeight: FontWeight.bold),
  89. ),
  90. SizedBox(height: 5),
  91. Text(
  92. data.overview,
  93. overflow: TextOverflow.ellipsis,
  94. maxLines: 5,
  95. ),
  96. ],
  97. ),
  98. )),
  99. )
  100. ],
  101. ),
  102. );
  103. }
  104. },
  105. );
  106. } else {
  107. return Text("Tidak masuk");
  108. }
  109. }),
  110. ),
  111. );
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement