Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.71 KB | None | 0 0
  1. import 'dart:convert';
  2. import 'package:flutter_social/views/tabs/detail_berita.dart';
  3. import 'package:http/http.dart' as http;
  4. import 'package:flutter/material.dart';
  5. import 'package:share/share.dart';
  6. import 'package:timeago/timeago.dart' as timeAgo;
  7. import 'package:flutter_html/flutter_html.dart';
  8. import 'package:html/dom.dart' as dom;
  9.  
  10. class BeritaPage extends StatefulWidget {
  11. @override
  12. _ArticleSourceScreenState createState() => new _ArticleSourceScreenState();
  13. }
  14.  
  15. class _ArticleSourceScreenState extends State<BeritaPage> {
  16. List dataJSON;
  17. GlobalKey<RefreshIndicatorState> refreshKey;
  18. @override
  19. void initState() {
  20. super.initState();
  21.  
  22. ambildata();
  23. }
  24.  
  25. void ambildata() async {
  26. http.Response hasil = await http.get(
  27. Uri.encodeFull("https:/xxxxxxx/Api/xxx"),
  28. headers: {"Accept": "application/json"});
  29. if (this.mounted) {
  30. this.setState(() {
  31.  
  32. return dataJSON = json.decode(hasil.body);
  33. });
  34. }
  35. }
  36.  
  37.  
  38.  
  39. Column buildButtonColumn(IconData icon) {
  40. return new Column(
  41. mainAxisSize: MainAxisSize.min,
  42. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  43. children: [
  44. new Icon(icon, color: Colors.red),
  45. ],
  46. );
  47. }
  48.  
  49. Future<void> refreshList() async {
  50. await Future.delayed(Duration(seconds: 2));
  51. http.Response hasil = await http.get(
  52. Uri.encodeFull("https://assazt/zza/aaaa"),
  53. headers: {"Accept": "application/json"});
  54.  
  55. this.setState(() {
  56.  
  57. dataJSON = json.decode(hasil.body);
  58.  
  59. });
  60. // return dataJSON;
  61. }
  62.  
  63.  
  64. Widget listnya(){
  65. return dataJSON == null
  66. ? const Center(child: const CircularProgressIndicator())
  67. : dataJSON.length != 0
  68. ? new ListView.builder(
  69. physics: const AlwaysScrollableScrollPhysics(),
  70. itemCount: dataJSON == null ? 0 : dataJSON.length,
  71.  
  72. padding: new EdgeInsets.all(8.0),
  73. itemBuilder: (BuildContext context, int i) {
  74. return new GestureDetector(
  75. child: new Card(
  76. elevation: 1.7,
  77. child: new Padding(
  78. padding: new EdgeInsets.all(10.0),
  79. child: new Column(
  80. children: [
  81. new Row(
  82.  
  83. children: [
  84. new Expanded(
  85. child: new GestureDetector(
  86. child:
  87. new Column(
  88. crossAxisAlignment:
  89. CrossAxisAlignment.start,
  90. children: [
  91. new Padding(
  92. padding: new EdgeInsets.only(
  93. right: 4.0),
  94. child: new Text(
  95. dataJSON[i]['judul'],
  96. style: new TextStyle(
  97. fontWeight: FontWeight.bold,
  98. fontSize: 18,
  99. color: Colors.black,
  100. ),
  101. ),
  102. ),
  103. ])
  104. ))],
  105. ),
  106. new Row(
  107. children: [
  108. new Expanded(
  109. child: new GestureDetector(
  110. child: Hero(
  111. tag: dataJSON[i]['id'] + 'list',
  112. child: new Column(
  113. crossAxisAlignment:
  114. CrossAxisAlignment.start,
  115. children: [
  116. new Padding(
  117. padding: new EdgeInsets.only(
  118. left: 4.0),
  119. child: new Text(
  120. timeAgo.format(DateTime.parse(
  121. dataJSON[i]['date']), locale: 'fr'),
  122. style: new TextStyle(
  123. fontWeight: FontWeight.w400,
  124. color: Colors.grey[600],
  125. ),
  126. ),
  127. ),
  128. new Padding(
  129. padding: new EdgeInsets.only(
  130. left: 4.0,
  131. right: 1.0,
  132. bottom: 8.0,
  133. top: 8.0),
  134. child: Html(
  135. data: dataJSON[i]['isi']
  136. .substring(0, 100) +
  137. " <b>Read more..</b>",
  138. //Optional parameters:
  139. padding: EdgeInsets.all(8.0),
  140. customTextAlign:
  141. (dom.Node node) {
  142. return TextAlign.justify;
  143. },
  144. )),
  145. new Padding(
  146. padding: new EdgeInsets.only(
  147. left: 4.0,
  148. right: 4.0,
  149. bottom: 4.0),
  150. child: new Text(
  151. dataJSON[i]['oleh'],
  152. style: new TextStyle(
  153. color: Colors.grey[500],
  154. ),
  155. ),
  156. ),
  157. ],
  158. ),
  159. ),
  160. onTap: () {
  161. Navigator.of(context).push(
  162. new MaterialPageRoute(
  163. builder:
  164. (BuildContext context) =>
  165. new DetailBerita(
  166. dataJSON:
  167. dataJSON[i])));
  168. },
  169. ),
  170. ),
  171. new Column(
  172. children: <Widget>[
  173. new Padding(
  174. padding: new EdgeInsets.only(top: 8.0),
  175. child: new SizedBox(
  176. height: 100.0,
  177. width: 100.0,
  178. child: new Image.network(
  179. 'https://xxxxxx/xl//' +
  180. dataJSON[i]['gambar'],
  181. fit: BoxFit.cover,
  182. ),
  183. ),
  184. ),
  185. new Row(
  186. children: <Widget>[
  187. new GestureDetector(
  188. child: new Padding(
  189. padding:
  190. new EdgeInsets.symmetric(
  191. vertical: 10.0,
  192. horizontal: 5.0),
  193. child: buildButtonColumn(
  194. Icons.share)),
  195. onTap: () {
  196. Share.share('https://xxxxxx/'+dataJSON[i]['id']);
  197. },
  198. ),
  199. ],
  200. )
  201. ],
  202. )
  203. ],
  204. ),
  205. ],
  206. ),
  207. ),
  208. ),
  209. );
  210. },
  211. )
  212. : new Center(
  213. child: new Column(
  214. mainAxisAlignment: MainAxisAlignment.center,
  215. children: [
  216. new Icon(Icons.chrome_reader_mode,
  217. color: Colors.grey, size: 60.0),
  218. new Text(
  219. "No articles saved",
  220. style:
  221. new TextStyle(fontSize: 24.0, color: Colors.grey),
  222. ),
  223. ],
  224. ),
  225. );
  226. }
  227. @override
  228. Widget build(BuildContext context) {
  229. return new Scaffold(
  230. appBar: new AppBar(
  231. title: new Text('Berita'),
  232. ),
  233. backgroundColor: Colors.grey[200],
  234. body:RefreshIndicator(
  235. key: refreshKey,
  236. onRefresh: () async {
  237. await refreshList();
  238. },
  239.  
  240. child:listnya()
  241.  
  242. )
  243. );
  244. }
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement