Skip to content

Commit

Permalink
refactor: Day 7 - Home Page Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BbsonLin committed Sep 2, 2019
1 parent cfffac4 commit 39a7e37
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 77 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
@@ -1,7 +1,7 @@
import "package:flutter/material.dart";
import 'package:gitme_reborn/pages/home.dart';
import "package:gitme_reborn/pages/home.dart";
import "package:gitme_reborn/pages/login.dart";
import 'package:gitme_reborn/routes.dart';
import "package:gitme_reborn/routes.dart";

void main() => runApp(GitmeRebornApp());

Expand Down
204 changes: 130 additions & 74 deletions lib/pages/home.dart
Expand Up @@ -116,19 +116,92 @@ class MainPage extends StatelessWidget {
}

// 首頁
class HomePage extends StatelessWidget {
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
final List hnTops = [
{
"by": "jammygit",
"descendants": 18,
"title": "Pre-industrial workers had a shorter workweek than today's",
},
{
"by": "MaysonL",
"descendants": 2,
"title": "Help Advance the World with Advanced Linear Algebra",
},
{
"by": "xenocratus",
"descendants": 152,
"title": "Thoughts on Rust Bloat",
},
];

final List hnNews = [
{
"by": "rbanffy",
"descendants": 0,
"title": "Lost Nuclear Material Resurfaces in Maryland",
},
{
"by": "jakeprins",
"descendants": 0,
"title": "Find books that help you grow",
},
{
"by": "atlasunshrugged",
"descendants": 0,
"title": "America's Depressing New Culture War",
},
];

final List ghTrends = [
{
"author": "lumen",
"name": "lumen",
"avatar": "https://github.com/lumen.png",
"url": "https://github.com/lumen/lumen",
"description":
"An alternative BEAM implementation, designed for WebAssembly",
"language": "Rust",
"languageColor": "#dea584",
"stars": 850,
"forks": 21,
},
{
"author": "outline",
"name": "outline",
"avatar": "https://github.com/outline.png",
"url": "https://github.com/outline/outline",
"description":
"The fastest wiki and knowledge base for growing teams. Beautiful, feature rich, markdown compatible and open source.",
"language": "JavaScript",
"languageColor": "#f1e05a",
"stars": 5342,
"forks": 329,
},
{
"author": "tophubs",
"name": "TopList",
"avatar": "https://github.com/tophubs.png",
"url": "https://github.com/tophubs/TopList",
"description":
"今日热榜,一个获取各大热门网站热门头条的聚合网站,使用Go语言编写,多协程异步快速抓取信息,预览:https://www.printf520.com/hot.html",
"language": "Go",
"languageColor": "#00ADD8",
"stars": 1960,
"forks": 332,
}
];

@override
Widget build(BuildContext context) {
return Container(
return RefreshIndicator(
child: ListView(
children: <Widget>[
Container(
child: Divider(
height: 8.0,
color: Colors.grey[200],
),
color: Colors.grey[200],
),
ListTile(
dense: true,
title: Text("Hackernews Top"),
Expand All @@ -138,28 +211,7 @@ class HomePage extends StatelessWidget {
Divider(
height: 0.0,
),
ListTile(
title: Text(
"Pre-industrial workers had a shorter workweek than today's"),
subtitle: Text("by jammygit 2 hours ago | 18 comments"),
onTap: () {},
),
Divider(
height: 0.0,
),
ListTile(
title: Text("Help Advance the World with Advanced Linear Algebra"),
subtitle: Text("by MaysonL 1 hour ago | 2 comments"),
onTap: () {},
),
Divider(
height: 0.0,
),
ListTile(
title: Text("Thoughts on Rust Bloat"),
subtitle: Text("by xenocratus 7 hours ago | 152 comments"),
onTap: () {},
),
...buildHNTopStories(context),
Container(
child: Divider(
height: 8.0,
Expand All @@ -176,28 +228,7 @@ class HomePage extends StatelessWidget {
Divider(
height: 0.0,
),
ListTile(
title: Text(
"Pre-industrial workers had a shorter workweek than today's"),
subtitle: Text("by jammygit 2 hours ago | 18 comments"),
onTap: () {},
),
Divider(
height: 0.0,
),
ListTile(
title: Text("Help Advance the World with Advanced Linear Algebra"),
subtitle: Text("by MaysonL 1 hour ago | 2 comments"),
onTap: () {},
),
Divider(
height: 0.0,
),
ListTile(
title: Text("Thoughts on Rust Bloat"),
subtitle: Text("by xenocratus 7 hours ago | 152 comments"),
onTap: () {},
),
...buildHNNewStories(context),
Container(
child: Divider(
height: 8.0,
Expand All @@ -214,29 +245,54 @@ class HomePage extends StatelessWidget {
Divider(
height: 0.0,
),
ListTile(
title: Text("CorentinJ / Real-Time-Voice-Cloning"),
subtitle: Text("Python 3,795 446"),
onTap: () {},
),
Divider(
height: 0.0,
),
ListTile(
title: Text("google / mediapipe"),
subtitle: Text("C++ 1,505 201"),
onTap: () {},
),
Divider(
height: 0.0,
),
ListTile(
title: Text("MisterBooo / LeetCodeAnimation"),
subtitle: Text("Java 38,443 6,483"),
onTap: () {},
),
...buildGHTrends(context),
],
),
onRefresh: () {
return Future.delayed(Duration(seconds: 2));
},
);
}

buildHNTopStories(BuildContext context) {
return ListTile.divideTiles(
context: context,
tiles: hnTops.map((story) {
return ListTile(
title: Text(story["title"]),
subtitle: Text(
"by ${story["by"]} | ${story["descendants"]} comments"),
onTap: () {},
);
}).toList())
.toList();
}

buildHNNewStories(BuildContext context) {
return ListTile.divideTiles(
context: context,
tiles: hnNews.map((story) {
return ListTile(
title: Text(story["title"]),
subtitle: Text(
"by ${story["by"]} | ${story["descendants"]} comments"),
onTap: () {},
);
}).toList())
.toList();
}

buildGHTrends(BuildContext context) {
return ListTile.divideTiles(
context: context,
tiles: ghTrends.map((repo) {
return ListTile(
title: Text("${repo["author"]} / ${repo["name"]}"),
subtitle: Text(
"${repo["language"]} ${repo["stars"]} ${repo["forks"]}"),
onTap: () {},
);
}).toList())
.toList();
}
}
1 change: 0 additions & 1 deletion lib/pages/repo.dart
Expand Up @@ -48,7 +48,6 @@ class _RepoPageState extends State<RepoPage> {
setState(() {
repoList.add(
{"title": "BbsonLin/new-item", "description": "", "lang": ""});
print(repoList);
});
});
},
Expand Down

0 comments on commit 39a7e37

Please sign in to comment.