Skip to content
69 changes: 69 additions & 0 deletions lib/hn-components.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';

class TimeAgo extends StatelessWidget {
final String text;

TimeAgo({Key key, @required this.text}): super(key: key);

@override
Widget build(BuildContext context) {
return RichText(
text: TextSpan(
text: text,
style: TextStyle(
color: Colors.grey,
fontSize: 14.0,
)
)
);
}
}

class FeedCardTitle extends StatelessWidget {
final String text;
final bool urlOpened;

FeedCardTitle ({Key key, @required this.text, @required this.urlOpened}): super(key: key);

@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.centerLeft,
child: RichText(
text: TextSpan(
text: text,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: urlOpened ? Colors.grey : Colors.black,
decoration: urlOpened ? TextDecoration.lineThrough : null,
)
)
)
);
}
}

class Domain extends StatelessWidget {
final String text;

Domain({Key key, this.text}): super(key: key);

@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.centerLeft,
child: Text(
text ?? "",
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w300,
color: Colors.black87,
)
)
);
}
}



34 changes: 34 additions & 0 deletions lib/hn-model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class FeedCard {
int id;
String title;
int points;
String user;
String timeAgo;
int commentsCount;
String url;
String domain;

FeedCard({
this.id,
this.title,
this.points,
this.user,
this.timeAgo,
this.commentsCount,
this.url,
this.domain
});

factory FeedCard.fromJSON(Map<String, dynamic> postJSON) {
return FeedCard(
id: postJSON["id"] as int,
title: postJSON["title"] as String,
points: postJSON["points"] as int,
user: postJSON["user"] as String,
timeAgo: postJSON["time_ago"] as String,
commentsCount: postJSON["comments_count"] as int,
url: postJSON["url"] as String,
domain: postJSON["domain"] as String,
);
}
}
Loading