Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.16 KB | None | 0 0
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:ws_flutter_fetchapi/core/model/movie_resp.dart';
  4. import 'package:ws_flutter_fetchapi/core/model/movie_response.dart';
  5. import 'package:ws_flutter_fetchapi/core/service/service.dart';
  6.  
  7. class HomeScreen extends StatefulWidget {
  8. @override
  9. _HomeScreenState createState() => _HomeScreenState();
  10. }
  11.  
  12. class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
  13. Service _service;
  14. var imageUrl = "http://image.tmdb.org/t/p/w500/";
  15. var errorImage =
  16. "https://cdn2.iconfinder.com/data/icons/image-1/64/Image-12-512.png";
  17.  
  18. //tambahkan bari di bawah ini
  19. List<Tab> _tabList = List();
  20. TabController _tabController;
  21.  
  22. @override
  23. void initState() {
  24. print('init homescreen');
  25. _service = Service();
  26. super.initState();
  27.  
  28. _tabList.add(new Tab(text: 'Now Playing'));
  29. _tabList.add(new Tab(text: 'Up Coming'));
  30.  
  31. _tabController = TabController(length: _tabList.length, vsync: this);
  32. }
  33.  
  34. @override
  35. Widget build(BuildContext context) {
  36. return Scaffold(
  37. backgroundColor: Colors.grey,
  38. appBar: AppBar(
  39. title: Text("Aplikasi Fetch Data"),
  40. bottom: TabBar(
  41. tabs: _tabList,
  42. controller: _tabController,
  43. indicatorColor: Colors.orange,
  44. indicatorSize: TabBarIndicatorSize.tab,
  45. ),
  46. ),
  47. body: TabBarView(
  48. controller: _tabController,
  49. children: <Widget>[
  50. Center(
  51. child: FutureBuilder<MovieResponse>(
  52. future: _service.getNowPlaying(),
  53. builder: (context, snapshot) {
  54. if (snapshot.hasData) {
  55. return ListView.builder(
  56. itemCount: snapshot.data.results.length,
  57. itemBuilder: (context, index) {
  58. var gambar = imageUrl +
  59. snapshot.data.results[index].posterPath;
  60. var data = snapshot.data.results[index];
  61. if (snapshot.data.results.length == null) {
  62. return Text("Tidak ada data");
  63. } else {
  64. return Padding(
  65. padding: const EdgeInsets.all(8.0),
  66. child: Row(
  67. mainAxisSize: MainAxisSize.max,
  68. children: <Widget>[
  69. Flexible(
  70. flex: 1,
  71. fit: FlexFit.tight,
  72. child: Container(
  73. height: 150,
  74. width: 100,
  75. decoration: BoxDecoration(
  76. borderRadius: BorderRadius.all(
  77. Radius.circular(10))),
  78. child: ClipRRect(
  79. borderRadius: BorderRadius.all(
  80. Radius.circular(10)),
  81. child: CachedNetworkImage(
  82. fit: BoxFit.cover,
  83. imageUrl: gambar,
  84. placeholder: (context, url) =>
  85. CircularProgressIndicator(),
  86. errorWidget: (context, url, error) =>
  87. Icon(Icons.error),
  88. ),
  89. ),
  90. ),
  91. ),
  92. SizedBox(
  93. width: 10,
  94. ),
  95. Flexible(
  96. flex: 2,
  97. fit: FlexFit.tight,
  98. child: Container(
  99. height: 150,
  100. decoration: BoxDecoration(
  101. borderRadius: BorderRadius.all(
  102. Radius.circular(10)),
  103. color: Colors.white,
  104. boxShadow: [
  105. BoxShadow(
  106. color: Colors.blue,
  107. blurRadius: 3)
  108. ]),
  109. child: Padding(
  110. padding: const EdgeInsets.all(8.0),
  111. child: Column(
  112. children: <Widget>[
  113. Text(
  114. data.title,
  115. overflow: TextOverflow.ellipsis,
  116. maxLines: 2,
  117. style: TextStyle(
  118. fontSize: 20,
  119. fontWeight:
  120. FontWeight.bold),
  121. ),
  122. SizedBox(height: 5),
  123. Text(
  124. data.overview,
  125. overflow: TextOverflow.ellipsis,
  126. maxLines: 5,
  127. ),
  128. ],
  129. ),
  130. )),
  131. )
  132. ],
  133. ),
  134. );
  135. }
  136. },
  137. );
  138. } else {
  139. return CircularProgressIndicator();
  140. }
  141. }),
  142. ),
  143. Center(
  144. child: FutureBuilder<MovieResp>(
  145. future: _service.getUpcoming(),
  146. builder: (context, snapshot) {
  147. if (snapshot.hasData) {
  148. return ListView.builder(
  149. itemCount: snapshot.data.results.length,
  150. itemBuilder: (context, index) {
  151. var data = snapshot.data.results[index];
  152.  
  153. if (index == 0) data.posterPath = null;
  154.  
  155. return Stack(
  156. children: <Widget>[
  157. //! kotak judul
  158. Padding(
  159. padding: const EdgeInsets.all(8.0),
  160. child: Row(
  161. mainAxisSize: MainAxisSize.max,
  162. children: <Widget>[
  163. SizedBox(
  164. width: 30,
  165. ),
  166. Expanded(
  167. child: Container(
  168. height: 120,
  169. decoration: BoxDecoration(
  170. color: Colors.white,
  171. borderRadius: BorderRadius.all(
  172. Radius.circular(8))),
  173. child: Padding(
  174. padding: const EdgeInsets.only(
  175. top: 10.0, left: 50.0),
  176. child: Column(children: <Widget>[
  177. ListTile(
  178. title: Text(data.title),
  179. subtitle: Text(data.releaseDate),
  180. )
  181. ]),
  182. ),
  183. ),
  184. ),
  185. ],
  186. ),
  187. ),
  188.  
  189. //! foto movie
  190. Positioned(
  191. top: 20,
  192. left: 5,
  193. child: Container(
  194. decoration: BoxDecoration(
  195. shape: BoxShape.circle, color: Colors.white
  196. // borderRadius: BorderRadius.all(
  197. // Radius.circular(10.0))
  198. ),
  199. child: Padding(
  200. padding: const EdgeInsets.all(8.0),
  201. child: CircleAvatar(
  202. backgroundImage: NetworkImage(
  203. data.posterPath != null
  204. ? imageUrl + data.posterPath
  205. : errorImage),
  206. radius: 40.0,
  207. ),
  208. ),
  209. ),
  210. )
  211. ],
  212. );
  213. },
  214. );
  215. } else {
  216. return CircularProgressIndicator();
  217. }
  218. },
  219. ),
  220. )
  221. ],
  222. ));
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement