Advertisement
Guest User

Detail_Screen

a guest
Jun 15th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import '../models/meals_detail.dart';
  3. import '../blocs/meals_detail_bloc.dart';
  4. import 'package:dicoding_submission/src/models/meals_detail.dart';
  5.  
  6. class DetailScreen extends StatefulWidget {
  7.  
  8. final String idMeal;
  9. final String strMealThumb;
  10.  
  11. const DetailScreen({Key key, @required this.idMeal, this.strMealThumb}) : super(key: key);
  12.  
  13. @override
  14. _DetailScreenState createState() => _DetailScreenState();
  15.  
  16. }
  17.  
  18. class _DetailScreenState extends State<DetailScreen> {
  19.  
  20. @override
  21. void initState() {
  22. super.initState();
  23. bloc.fetchDetailMeals(widget.idMeal);
  24. }
  25.  
  26. // @override
  27. // void dispose() {
  28. // bloc.dispose();
  29. // super.dispose();
  30. // }
  31.  
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. appBar: AppBar(
  36. centerTitle: true,
  37. iconTheme: IconThemeData(
  38. color: Colors.white,
  39. ),
  40. title: Text(
  41. 'Detail Meals',
  42. style: TextStyle(color: Colors.white),
  43. ),
  44. ),
  45. body: getListDetail()
  46. );
  47. }
  48.  
  49. getListDetail() {
  50. return StreamBuilder(
  51. stream: bloc.detailMeals,
  52. builder: (context, AsyncSnapshot<MealsDetail> snapshot) {
  53. if (snapshot.hasData) {
  54. return _showListDetail(
  55. snapshot.data.meals[0].idMeal,
  56. snapshot.data.meals[0].strMeal,
  57. snapshot.data.meals[0].strMealThumb,
  58. snapshot.data.meals[0].strCategory,
  59. snapshot.data.meals[0].strArea,
  60. snapshot.data.meals[0].strIngredient1,
  61. snapshot.data.meals[0].strIngredient2,
  62. snapshot.data.meals[0].strIngredient3,
  63. snapshot.data.meals[0].strIngredient4,
  64. snapshot.data.meals[0].strIngredient5,
  65. snapshot.data.meals[0].strInstructions);
  66. } else if (snapshot.hasError) {
  67. return Text(snapshot.error.toString());
  68. }
  69. return Center(child: CircularProgressIndicator(
  70. valueColor: AlwaysStoppedAnimation<Color>(Color.fromRGBO(58, 66, 86, 1.0),)
  71. ));
  72. });
  73. }
  74.  
  75. Widget _showListDetail(
  76. String id,
  77. String name,
  78. String image,
  79. String category,
  80. String area,
  81. String ingredient1,
  82. String ingredient2,
  83. String ingredient3,
  84. String ingredient4,
  85. String ingredient5,
  86. String desc) {
  87. return SingleChildScrollView(
  88. child: Column(
  89. children: <Widget>[
  90. Hero(
  91. tag: name,
  92. child: Material(
  93. child: InkWell(
  94. child: Image.network(image, fit: BoxFit.cover),
  95. ),
  96. ),
  97. ),
  98. Container(
  99. alignment: Alignment.center,
  100. padding: EdgeInsets.all(3.0),
  101. child: Text(
  102. name,
  103. style: TextStyle(
  104. fontSize: 17,
  105. fontWeight: FontWeight.bold,
  106. color: Colors.black),
  107. ),
  108. ),
  109. Container(
  110. padding: EdgeInsets.all(5.0),
  111. child: Row(
  112. children: <Widget>[
  113. Align(
  114. alignment: Alignment.centerLeft,
  115. child: Text(
  116. "Category : ",
  117. style: TextStyle(
  118. fontSize: 15,
  119. fontWeight: FontWeight.bold,
  120. color: Colors.black),
  121. ),
  122. ),
  123. Align(
  124. alignment: Alignment.centerLeft,
  125. child: Text(
  126. category,
  127. style: TextStyle(
  128. fontStyle: FontStyle.normal, color: Colors.black),
  129. ),
  130. ),
  131. ],
  132. ),
  133. ),
  134. Container(
  135. padding: EdgeInsets.all(5.0),
  136. child: Row(
  137. children: <Widget>[
  138. Align(
  139. alignment: Alignment.centerLeft,
  140. child: Text(
  141. "Area : ",
  142. style: TextStyle(
  143. fontSize: 15,
  144. fontWeight: FontWeight.bold,
  145. color: Colors.black),
  146. ),
  147. ),
  148. Align(
  149. alignment: Alignment.centerLeft,
  150. child: Text(
  151. area,
  152. style: TextStyle(
  153. fontStyle: FontStyle.normal, color: Colors.black),
  154. ),
  155. ),
  156. ],
  157. ),
  158. ),
  159. Container(
  160. padding: EdgeInsets.all(5.0),
  161. child: Column(
  162. children: <Widget>[
  163. Align(
  164. alignment: Alignment.centerLeft,
  165. child: Text(
  166. "Ingredient :",
  167. style: TextStyle(
  168. fontSize: 15,
  169. fontWeight: FontWeight.bold,
  170. color: Colors.black),
  171. ),
  172. ),
  173. Align(
  174. alignment: Alignment.centerLeft,
  175. child: Text(
  176. ingredient1+ ', ' +
  177. ingredient1 + ', ' +
  178. ingredient2 + ', ' +
  179. ingredient3 + ', ' +
  180. ingredient4 + ', ' +
  181. ingredient5,
  182. style: TextStyle(
  183. fontStyle: FontStyle.italic, color: Colors.black),
  184. ),
  185. ),
  186. ],
  187. ),
  188. ),
  189. Container(
  190. padding: EdgeInsets.all(5.0),
  191. child: Column(
  192. children: <Widget>[
  193. Align(
  194. alignment: Alignment.centerLeft,
  195. child: Text(
  196. "Instructions :",
  197. style: TextStyle(
  198. fontSize: 15,
  199. fontWeight: FontWeight.bold,
  200. color: Colors.black),
  201. ),
  202. ),
  203. Align(
  204. alignment: Alignment.centerLeft,
  205. child: Text(
  206. desc,
  207. style: TextStyle(
  208. fontStyle: FontStyle.italic, color: Colors.black),
  209. ),
  210. ),
  211. ],
  212. ),
  213. ),
  214. ],
  215. ),
  216. );
  217. }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement