Skip to content

Commit c217359

Browse files
committed
final touches
1 parent 1de5a1a commit c217359

File tree

9 files changed

+78
-36
lines changed

9 files changed

+78
-36
lines changed

android/app/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ apply plugin: 'com.android.application'
2525
apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

28+
def keystoreProperties = new Properties()
29+
def keystorePropertiesFile = rootProject.file('key.properties')
30+
if (keystorePropertiesFile.exists()) {
31+
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
32+
}
33+
34+
2835
android {
2936
compileSdkVersion 29
3037

@@ -44,6 +51,15 @@ android {
4451
versionCode flutterVersionCode.toInteger()
4552
versionName flutterVersionName
4653
}
54+
55+
signingConfigs {
56+
release {
57+
keyAlias keystoreProperties['keyAlias']
58+
keyPassword keystoreProperties['keyPassword']
59+
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
60+
storePassword keystoreProperties['storePassword']
61+
}
62+
}
4763

4864
buildTypes {
4965
release {
13.4 KB
Loading
13.5 KB
Loading
13.2 KB
Loading
12.9 KB
Loading
12.5 KB
Loading

lib/card.dart

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import 'package:flutter/material.dart';
22
import 'comment.dart';
3+
import 'webview.dart';
34

4-
class HNStory {
5-
HNStory(this.headline, this.author, this.votes, this.comments, this.time,
6-
this.url, this.childrenID);
7-
String headline, author, url;
5+
class HNItem {
6+
HNItem(this.headline, this.author, this.votes, this.comments, this.time,
7+
this.url, this.type, this.childrenID);
8+
String headline, author, url, type;
89
int votes, comments, id, score, time;
910
List<dynamic> childrenID;
1011
List<HNComment> children;
1112
}
1213

1314
class HNCard extends StatelessWidget {
14-
final HNStory story;
15+
final HNItem story;
16+
1517
HNCard(this.story);
1618

17-
CommentPage page;
19+
Widget page;
1820

1921
Widget makeCard(BuildContext context) {
2022
var before = DateTime.now()
2123
.difference(DateTime.fromMillisecondsSinceEpoch(story.time * 1000));
22-
String timeString = "${before.inHours} hours ago (${story.url}";
24+
String timeString = "${before.inHours} hours ago";
2325
if (before.inHours < 1) {
2426
timeString = "${before.inMinutes} minutes ago";
2527
}
@@ -31,6 +33,16 @@ class HNCard extends StatelessWidget {
3133
color: Colors.white,
3234
child: InkWell(
3335
onTap: () {
36+
if (story.type == "job")
37+
page = Scaffold(
38+
appBar: AppBar(
39+
title: Text(
40+
story.headline,
41+
),
42+
backgroundColor: Color(0xffff6600)),
43+
body: Center(
44+
child: WebViewScreen(story.url),
45+
));
3446
if (page == null && story.childrenID != null) {
3547
story.children = List(story.childrenID.length);
3648
for (var i = 0; i < story.childrenID.length; i++) {
@@ -56,7 +68,8 @@ class HNCard extends StatelessWidget {
5668
color: Colors.black,
5769
fontFamily: "Helvetica"),
5870
),
59-
subtitle: Text("$timeString by ${this.story.author}")),
71+
subtitle: Text(
72+
"$timeString by ${this.story.author} (${story.url})")),
6073
Row(
6174
children: [
6275
Container(
@@ -80,7 +93,7 @@ class HNCard extends StatelessWidget {
8093
color: Colors.green,
8194
),
8295
onPressed: null),
83-
Text('${this.story.comments}',
96+
Text('${this.story.comments ?? 0}',
8497
style: TextStyle(fontWeight: FontWeight.w600))
8598
])),
8699
],

lib/comment.dart

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,31 @@ class HNComment {
1616
}
1717

1818
class CommentPage extends StatefulWidget {
19-
final HNStory _story;
19+
final HNItem story;
20+
List<Widget> cards;
21+
int counter = 0;
2022

21-
CommentPage(this._story);
23+
CommentPage(this.story) {
24+
cards = new List(story.comments);
25+
}
2226

23-
CommentPageState createState() => CommentPageState(_story);
27+
@override
28+
CommentPageState createState() => new CommentPageState(story);
2429
}
2530

2631
class CommentPageState extends State<CommentPage> {
27-
final HNStory _story;
28-
List<Widget> _cards;
32+
final HNItem _story;
2933

30-
CommentPageState(this._story) {
31-
_cards = new List(_story.comments);
32-
getComments();
33-
}
34+
CommentPageState(this._story);
3435

3536
void initState() {
3637
super.initState();
37-
var loading = _makeCard("...", "...", 0, 0);
38-
for (int i = 0; i < _story.comments; i++) {
39-
_cards[i] = loading;
38+
if (widget.counter == 0) {
39+
getComments();
40+
var loading = _makeCard("...", "...", 0, 0);
41+
for (int i = 0; i < _story.comments; i++) {
42+
widget.cards[i] = loading;
43+
}
4044
}
4145
}
4246

@@ -60,7 +64,6 @@ class CommentPageState extends State<CommentPage> {
6064
}
6165

6266
void getComments() async {
63-
int j = 0;
6467
for (var comment in _story.children) {
6568
comment.future = HNAPI.fetchItem(comment.id);
6669
ListQueue<HNComment> stack = new ListQueue();
@@ -69,13 +72,21 @@ class CommentPageState extends State<CommentPage> {
6972
HNComment top = stack.last;
7073
stack.removeLast();
7174
var res = await top.future;
72-
setState(() {
73-
if (j < _story.comments) {
74-
_cards[j] = _makeCard(res["text"] ?? "deleted", res["by"] ?? "?",
75-
res['time'], top.left);
76-
j++;
75+
if (mounted) {
76+
setState(() {
77+
if (widget.counter < _story.comments) {
78+
widget.cards[widget.counter] = _makeCard(res["text"] ?? "deleted",
79+
res["by"] ?? "?", res['time'], top.left);
80+
widget.counter++;
81+
}
82+
});
83+
} else {
84+
if (widget.counter < _story.comments) {
85+
widget.cards[widget.counter] = _makeCard(res["text"] ?? "deleted",
86+
res["by"] ?? "?", res['time'], top.left);
87+
widget.counter++;
7788
}
78-
});
89+
}
7990
if (res['kids'] != null) {
8091
top.children = new List(res["kids"].length);
8192
for (int i = 0; i < res["kids"].length; i++) {
@@ -94,23 +105,23 @@ class CommentPageState extends State<CommentPage> {
94105
length: 2,
95106
child: Scaffold(
96107
appBar: AppBar(
97-
title: Text("${_story.headline}"),
108+
title: Text(_story.headline),
98109
backgroundColor: Color(0xffff6600),
99110
bottom: TabBar(tabs: [
100-
Tab(text: "Website"),
101111
Tab(text: "Comments"),
112+
Tab(text: "Website"),
102113
]),
103114
),
104115
body: Center(
105116
child: TabBarView(children: [
106-
WebViewScreen(_story.url),
107117
Container(
108118
decoration: BoxDecoration(color: Colors.grey[200]),
109119
child: ListView.builder(
110120
itemBuilder: (context, index) {
111-
return _cards[index];
121+
return widget.cards[index];
112122
},
113-
itemCount: _cards.length)),
123+
itemCount: widget.cards.length)),
124+
WebViewScreen(_story.url),
114125
])),
115126
));
116127
}

lib/top.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ class HNTopState extends State<HNTop> {
66
Future<Map<String, dynamic>> items;
77
Future<List<dynamic>> itemIDs;
88
List<HNCard> cards;
9-
List<HNStory> stories;
9+
List<HNItem> stories;
1010

11-
HNCard loading = new HNCard(new HNStory('...', '...', 0, 0, 0, "", null));
11+
HNCard loading =
12+
new HNCard(new HNItem('...', '...', 0, 0, 0, "", "story", null));
1213

1314
@override
1415
void initState() {
@@ -35,13 +36,14 @@ class HNTopState extends State<HNTop> {
3536
future: item,
3637
builder: (context, snapshot) {
3738
if (snapshot.hasData) {
38-
stories[index] = HNStory(
39+
stories[index] = HNItem(
3940
snapshot.data['title'],
4041
snapshot.data['by'],
4142
snapshot.data['score'],
4243
snapshot.data['descendants'],
4344
snapshot.data['time'],
4445
snapshot.data['url'],
46+
snapshot.data["type"],
4547
snapshot.data['kids']);
4648
cards[index] = new HNCard(stories[index]);
4749
return cards[index];

0 commit comments

Comments
 (0)