From a430537b6f2789fb2af6095748f66f47fbceb855 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Sun, 7 Aug 2022 23:40:31 +0100 Subject: [PATCH] feat: fetch real data on the Latest Commit card --- lib/services/github_api.dart | 5 ++- lib/ui/widgets/latest_commit_card.dart | 53 ++++++++++++++------------ pubspec.lock | 7 ++++ pubspec.yaml | 1 + 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/lib/services/github_api.dart b/lib/services/github_api.dart index 9a490102..82359960 100644 --- a/lib/services/github_api.dart +++ b/lib/services/github_api.dart @@ -1,5 +1,6 @@ import 'package:github/github.dart'; import 'package:injectable/injectable.dart'; +import 'package:timeago/timeago.dart'; @lazySingleton class GithubAPI { @@ -19,10 +20,10 @@ class GithubAPI { return dlurl; } - Future latestCommitTime(String org, repoName) async { + Future latestCommitTime(String org, repoName) async { var repo = await github.repositories.getRepository( RepositorySlug(org, repoName), ); - return repo.pushedAt; + return format(repo.pushedAt!); } } diff --git a/lib/ui/widgets/latest_commit_card.dart b/lib/ui/widgets/latest_commit_card.dart index 88220360..6134b26c 100644 --- a/lib/ui/widgets/latest_commit_card.dart +++ b/lib/ui/widgets/latest_commit_card.dart @@ -14,23 +14,6 @@ class LatestCommitCard extends StatefulWidget { class _LatestCommitCardState extends State { GithubAPI githubAPI = GithubAPI(); - String lastPatcherCommit = 'Loading...'; - String lastManagerCommit = 'Loading...'; - - void latestCommit() async { - // lastPatcherCommit = - // await githubAPI.latestCommitTime('revanced', 'revanced-patcher'); - // lastManagerCommit = - // await githubAPI.latestCommitTime('revanced', 'revanced-manager'); - } - - @override - void initState() { - setState(() { - latestCommit(); - }); - super.initState(); - } @override Widget build(BuildContext context) { @@ -57,10 +40,20 @@ class _LatestCommitCardState extends State { ), ), ), - Text( - '$lastPatcherCommit ago', - style: robotoTextStyle, - ) + FutureBuilder( + future: githubAPI.latestCommitTime( + 'revanced', + 'revanced-patcher', + ), + initialData: FlutterI18n.translate( + context, + 'latestCommitCard.loadingLabel', + ), + builder: (context, snapshot) => Text( + snapshot.data!, + style: robotoTextStyle, + ), + ), ], ), Row( @@ -74,10 +67,20 @@ class _LatestCommitCardState extends State { ), ), ), - Text( - '$lastManagerCommit ago', - style: robotoTextStyle, - ) + FutureBuilder( + future: githubAPI.latestCommitTime( + 'revanced', + 'revanced-patcher', + ), + initialData: FlutterI18n.translate( + context, + 'latestCommitCard.loadingLabel', + ), + builder: (context, snapshot) => Text( + snapshot.data!, + style: robotoTextStyle, + ), + ), ], ), ], diff --git a/pubspec.lock b/pubspec.lock index 9535d059..48470ca3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -712,6 +712,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.9" + timeago: + dependency: "direct main" + description: + name: timeago + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.2" timing: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 72fb0fe4..185da425 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: stacked: ^2.3.15 stacked_generator: ^0.7.14 stacked_services: ^0.9.3 + timeago: ^3.2.2 dev_dependencies: build_runner: any