Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:flutter_social/views/tabs/detail_berita.dart';
- import 'package:http/http.dart' as http;
- import 'package:flutter/material.dart';
- import 'package:share/share.dart';
- import 'package:timeago/timeago.dart' as timeAgo;
- import 'package:flutter_html/flutter_html.dart';
- import 'package:html/dom.dart' as dom;
- class BeritaPage extends StatefulWidget {
- @override
- _ArticleSourceScreenState createState() => new _ArticleSourceScreenState();
- }
- class _ArticleSourceScreenState extends State<BeritaPage> {
- List dataJSON;
- GlobalKey<RefreshIndicatorState> refreshKey;
- @override
- void initState() {
- super.initState();
- ambildata();
- }
- void ambildata() async {
- http.Response hasil = await http.get(
- Uri.encodeFull("https:/xxxxxxx/Api/xxx"),
- headers: {"Accept": "application/json"});
- if (this.mounted) {
- this.setState(() {
- return dataJSON = json.decode(hasil.body);
- });
- }
- }
- Column buildButtonColumn(IconData icon) {
- return new Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- new Icon(icon, color: Colors.red),
- ],
- );
- }
- Future<void> refreshList() async {
- await Future.delayed(Duration(seconds: 2));
- http.Response hasil = await http.get(
- Uri.encodeFull("https://assazt/zza/aaaa"),
- headers: {"Accept": "application/json"});
- this.setState(() {
- dataJSON = json.decode(hasil.body);
- });
- // return dataJSON;
- }
- Widget listnya(){
- return dataJSON == null
- ? const Center(child: const CircularProgressIndicator())
- : dataJSON.length != 0
- ? new ListView.builder(
- physics: const AlwaysScrollableScrollPhysics(),
- itemCount: dataJSON == null ? 0 : dataJSON.length,
- padding: new EdgeInsets.all(8.0),
- itemBuilder: (BuildContext context, int i) {
- return new GestureDetector(
- child: new Card(
- elevation: 1.7,
- child: new Padding(
- padding: new EdgeInsets.all(10.0),
- child: new Column(
- children: [
- new Row(
- children: [
- new Expanded(
- child: new GestureDetector(
- child:
- new Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- new Padding(
- padding: new EdgeInsets.only(
- right: 4.0),
- child: new Text(
- dataJSON[i]['judul'],
- style: new TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 18,
- color: Colors.black,
- ),
- ),
- ),
- ])
- ))],
- ),
- new Row(
- children: [
- new Expanded(
- child: new GestureDetector(
- child: Hero(
- tag: dataJSON[i]['id'] + 'list',
- child: new Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- new Padding(
- padding: new EdgeInsets.only(
- left: 4.0),
- child: new Text(
- timeAgo.format(DateTime.parse(
- dataJSON[i]['date']), locale: 'fr'),
- style: new TextStyle(
- fontWeight: FontWeight.w400,
- color: Colors.grey[600],
- ),
- ),
- ),
- new Padding(
- padding: new EdgeInsets.only(
- left: 4.0,
- right: 1.0,
- bottom: 8.0,
- top: 8.0),
- child: Html(
- data: dataJSON[i]['isi']
- .substring(0, 100) +
- " <b>Read more..</b>",
- //Optional parameters:
- padding: EdgeInsets.all(8.0),
- customTextAlign:
- (dom.Node node) {
- return TextAlign.justify;
- },
- )),
- new Padding(
- padding: new EdgeInsets.only(
- left: 4.0,
- right: 4.0,
- bottom: 4.0),
- child: new Text(
- dataJSON[i]['oleh'],
- style: new TextStyle(
- color: Colors.grey[500],
- ),
- ),
- ),
- ],
- ),
- ),
- onTap: () {
- Navigator.of(context).push(
- new MaterialPageRoute(
- builder:
- (BuildContext context) =>
- new DetailBerita(
- dataJSON:
- dataJSON[i])));
- },
- ),
- ),
- new Column(
- children: <Widget>[
- new Padding(
- padding: new EdgeInsets.only(top: 8.0),
- child: new SizedBox(
- height: 100.0,
- width: 100.0,
- child: new Image.network(
- 'https://xxxxxx/xl//' +
- dataJSON[i]['gambar'],
- fit: BoxFit.cover,
- ),
- ),
- ),
- new Row(
- children: <Widget>[
- new GestureDetector(
- child: new Padding(
- padding:
- new EdgeInsets.symmetric(
- vertical: 10.0,
- horizontal: 5.0),
- child: buildButtonColumn(
- Icons.share)),
- onTap: () {
- Share.share('https://xxxxxx/'+dataJSON[i]['id']);
- },
- ),
- ],
- )
- ],
- )
- ],
- ),
- ],
- ),
- ),
- ),
- );
- },
- )
- : new Center(
- child: new Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- new Icon(Icons.chrome_reader_mode,
- color: Colors.grey, size: 60.0),
- new Text(
- "No articles saved",
- style:
- new TextStyle(fontSize: 24.0, color: Colors.grey),
- ),
- ],
- ),
- );
- }
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(
- title: new Text('Berita'),
- ),
- backgroundColor: Colors.grey[200],
- body:RefreshIndicator(
- key: refreshKey,
- onRefresh: () async {
- await refreshList();
- },
- child:listnya()
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement