From ede2d064f10e361c4d60142600c05ef4f2698abc Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Fri, 13 Sep 2019 23:34:19 +0800 Subject: [PATCH] feat: format numbers with group seperator --- lib/screens/issues.dart | 4 ++-- lib/screens/repo.dart | 13 ++++++------- lib/utils/utils.dart | 3 +++ lib/widgets/comment_item.dart | 2 +- lib/widgets/entry_item.dart | 4 +++- lib/widgets/repo_item.dart | 4 ++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/screens/issues.dart b/lib/screens/issues.dart index 8861e42..7d4f255 100644 --- a/lib/screens/issues.dart +++ b/lib/screens/issues.dart @@ -156,8 +156,8 @@ class IssuesScreen extends StatelessWidget { Icon(Octicons.comment, size: 13, color: PrimerColors.gray700), SizedBox(width: 4), - Text(payload['comments']['totalCount'] - .toString()) + Text(numberFormat + .format(payload['comments']['totalCount'])) ], ], ), diff --git a/lib/screens/repo.dart b/lib/screens/repo.dart index d774869..b53a998 100644 --- a/lib/screens/repo.dart +++ b/lib/screens/repo.dart @@ -251,7 +251,7 @@ class RepoScreen extends StatelessWidget { text: Text('Issues'), rightWidget: Row( children: [ - Text(payload['issues']['totalCount'].toString()), + Text(numberFormat.format(payload['issues']['totalCount'])), Icon( CupertinoIcons.right_chevron, size: 18, @@ -266,7 +266,8 @@ class RepoScreen extends StatelessWidget { text: Text('Pull requests'), rightWidget: Row( children: [ - Text(payload['pullRequests']['totalCount'].toString()), + Text(numberFormat + .format(payload['pullRequests']['totalCount'])), Icon( CupertinoIcons.right_chevron, size: 18, @@ -286,17 +287,15 @@ class RepoScreen extends StatelessWidget { rightWidget: Text(payload['licenseInfo'] == null ? 'Unknown' : (payload['licenseInfo']['spdxId'] ?? - payload['licenseInfo']['name']) - .toString()), + payload['licenseInfo']['name'])), ), TableViewItem( leftWidget: Icon(Octicons.history, size: 20), text: Text('Commits'), rightWidget: Row( children: [ - Text(payload['defaultBranchRef']['target']['history'] - ['totalCount'] - .toString()), + Text(numberFormat.format(payload['defaultBranchRef'] + ['target']['history']['totalCount'])), Icon( CupertinoIcons.right_chevron, size: 18, diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 6d99760..2bdf9eb 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:git_touch/screens/user.dart'; +import 'package:intl/intl.dart'; import 'package:primer/primer.dart'; import '../screens/repo.dart'; export 'package:flutter_vector_icons/flutter_vector_icons.dart'; @@ -125,6 +126,8 @@ K ifNotNull(T value, K Function(T v) builder) { return value == null ? null : builder(value); } +final numberFormat = NumberFormat(); + class BorderView extends StatelessWidget { final double height; diff --git a/lib/widgets/comment_item.dart b/lib/widgets/comment_item.dart index c7deff6..a56cfa9 100644 --- a/lib/widgets/comment_item.dart +++ b/lib/widgets/comment_item.dart @@ -88,7 +88,7 @@ class CommentItem extends StatelessWidget { children: [ Text(emoji, style: TextStyle(fontSize: 18)), SizedBox(width: 4), - Text(count.toString(), + Text(numberFormat.format(count), style: TextStyle( color: PrimerColors.blue500, fontSize: 14)) ], diff --git a/lib/widgets/entry_item.dart b/lib/widgets/entry_item.dart index 13b6475..c47bd9b 100644 --- a/lib/widgets/entry_item.dart +++ b/lib/widgets/entry_item.dart @@ -1,4 +1,6 @@ import 'package:flutter/cupertino.dart'; +import 'package:git_touch/utils/utils.dart'; +import 'package:intl/intl.dart'; import 'package:primer/primer.dart'; import 'link.dart'; @@ -19,7 +21,7 @@ class EntryItem extends StatelessWidget { child: Column( children: [ Text( - count.toString(), + numberFormat.format(count), style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600), ), Text( diff --git a/lib/widgets/repo_item.dart b/lib/widgets/repo_item.dart index 76b1164..f2f3a12 100644 --- a/lib/widgets/repo_item.dart +++ b/lib/widgets/repo_item.dart @@ -54,7 +54,7 @@ class RepoItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Icon(Octicons.star, size: 14, color: PrimerColors.gray600), - Text(payload['stargazers']['totalCount'].toString()), + Text(numberFormat.format(payload['stargazers']['totalCount'])), ], ), ), @@ -64,7 +64,7 @@ class RepoItem extends StatelessWidget { children: [ Icon(Octicons.repo_forked, size: 14, color: PrimerColors.gray600), - Text(payload['forks']['totalCount'].toString()) + Text(numberFormat.format(payload['forks']['totalCount'])), ], ), ),