Skip to content

Instantly share code, notes, and snippets.

@haidar786
Created December 21, 2019 12:09
Show Gist options
  • Save haidar786/30b775e64af2ca7951774938ab31dc25 to your computer and use it in GitHub Desktop.
Save haidar786/30b775e64af2ca7951774938ab31dc25 to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:flutter/material.dart';
class ListItem extends StatelessWidget {
final posts = News.fromJson({"status":"ok","posts": [{ "title":"Barcelona 0-0 Real Madrid: Bale goal disallowed in tense Clasico","content": "Gareth Bale saw a goal disallowed as Barcelona and Real Madrid played out a 0-0 draw at Camp Nou on Wednesday. LaLiga's top two went into the contest level on points this season and with 72 wins each from previous league meetings, and there was nothing to separate them in a tense clash in Catalonia. The match was rearranged from October after the initial date became a security risk due to the prospect of Catalan independence protests, and there were fans inside and outside the stadium making their voices heard over one of Spain's most divisive issues.", "date": "2019-12-21 11:27:25","thumbnail_image": {"medium_large": { "url": "https://www.livescore.com/newsapi/04/soccer/imageret/barcelona-real-madrid-gareth-bale-goal-disallowed-tense-clasico-7-1cgsl7i8ipuf61gmt7m8ttd60w.jpg"}}}]});
@override
Widget build(BuildContext context) {
return Container(
child: Row(
textDirection: TextDirection.rtl,
children: <Widget>[
Container(
height: 400,
width: 220,
child: Image.network(posts.posts[0].thumbnailImage.mediumLarge.url),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
posts.posts[0].title,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.right,
maxLines: 2,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
]),
),
)
],
));
}
}
class News {
String status;
List<Posts> posts;
News({this.status, this.posts});
News.fromJson(Map<String, dynamic> json) {
status = json['status'];
if (json['posts'] != null) {
posts = new List<Posts>();
json['posts'].forEach((v) {
posts.add(new Posts.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['status'] = this.status;
if (this.posts != null) {
data['posts'] = this.posts.map((v) => v.toJson()).toList();
}
return data;
}
}
class Posts {
String title;
String content;
String date;
ThumbnailImage thumbnailImage;
Posts({this.title, this.content, this.date, this.thumbnailImage});
Posts.fromJson(Map<String, dynamic> json) {
title = json['title'];
content = json['content'];
date = json['date'];
thumbnailImage = json['thumbnail_image'] != null
? new ThumbnailImage.fromJson(json['thumbnail_image'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['title'] = this.title;
data['content'] = this.content;
data['date'] = this.date;
if (this.thumbnailImage != null) {
data['thumbnail_image'] = this.thumbnailImage.toJson();
}
return data;
}
}
class ThumbnailImage {
MediumLarge mediumLarge;
ThumbnailImage({this.mediumLarge});
ThumbnailImage.fromJson(Map<String, dynamic> json) {
mediumLarge = json['medium_large'] != null
? new MediumLarge.fromJson(json['medium_large'])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.mediumLarge != null) {
data['medium_large'] = this.mediumLarge.toJson();
}
return data;
}
}
class MediumLarge {
String url;
MediumLarge({this.url});
MediumLarge.fromJson(Map<String, dynamic> json) {
url = json['url'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['url'] = this.url;
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment