From ae5660061c7378a1d5c48f008e49c11389b5d343 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Wed, 2 Oct 2019 15:23:33 +0800 Subject: [PATCH] refactor: avatar size --- lib/screens/commits.dart | 2 +- lib/screens/login.dart | 2 +- lib/widgets/avatar.dart | 22 +++++++++++++++++++--- lib/widgets/comment_item.dart | 3 +-- lib/widgets/event_item.dart | 3 +-- lib/widgets/issue_item.dart | 3 +-- lib/widgets/repository_item.dart | 5 ++++- lib/widgets/user_item.dart | 2 +- 8 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/screens/commits.dart b/lib/screens/commits.dart index 2564906..e6d842d 100644 --- a/lib/screens/commits.dart +++ b/lib/screens/commits.dart @@ -94,7 +94,7 @@ class CommitsScreen extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Avatar(url: payload['author']['avatarUrl'], size: 16), + Avatar.medium(url: payload['author']['avatarUrl']), SizedBox(width: 8), Expanded( child: Column( diff --git a/lib/screens/login.dart b/lib/screens/login.dart index 1d6435b..f0b2881 100644 --- a/lib/screens/login.dart +++ b/lib/screens/login.dart @@ -30,7 +30,7 @@ class _LoginScreenState extends State { ), child: Row( children: [ - Avatar(url: account.avatarUrl, size: 24), + Avatar.large(url: account.avatarUrl), Padding(padding: EdgeInsets.only(left: 10)), Expanded( child: Column( diff --git a/lib/widgets/avatar.dart b/lib/widgets/avatar.dart index 30e9403..47f045e 100644 --- a/lib/widgets/avatar.dart +++ b/lib/widgets/avatar.dart @@ -10,9 +10,25 @@ class Avatar extends StatelessWidget { Avatar({ @required this.url, - this.size = 18, this.login, + @required this.size, }); + Avatar.extraSmall({ + @required this.url, + this.login, + }) : size = 16; + Avatar.small({ + @required this.url, + this.login, + }) : size = 24; + Avatar.medium({ + @required this.url, + this.login, + }) : size = 36; + Avatar.large({ + @required this.url, + this.login, + }) : size = 48; @override Widget build(BuildContext context) { @@ -21,8 +37,8 @@ class Avatar extends StatelessWidget { child: FadeInImage.assetNetwork( placeholder: 'images/octoface.png', image: url, - width: 2 * size, - height: 2 * size, + width: size, + height: size, fadeInDuration: Duration(milliseconds: 200), fadeOutDuration: Duration(milliseconds: 100), ), diff --git a/lib/widgets/comment_item.dart b/lib/widgets/comment_item.dart index a56cfa9..35329b7 100644 --- a/lib/widgets/comment_item.dart +++ b/lib/widgets/comment_item.dart @@ -43,9 +43,8 @@ class CommentItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row(children: [ - Avatar( + Avatar.medium( url: payload['author']['avatarUrl'], - size: 16, login: payload['author']['login'], ), SizedBox(width: 8), diff --git a/lib/widgets/event_item.dart b/lib/widgets/event_item.dart index 5a038fc..1ea91f9 100644 --- a/lib/widgets/event_item.dart +++ b/lib/widgets/event_item.dart @@ -79,10 +79,9 @@ class EventItem extends StatelessWidget { Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Avatar( + Avatar.medium( url: event.actorAvatarUrl, login: event.actorLogin, - size: 20, ), SizedBox(width: 10), Expanded( diff --git a/lib/widgets/issue_item.dart b/lib/widgets/issue_item.dart index ad249ed..6d64d0e 100644 --- a/lib/widgets/issue_item.dart +++ b/lib/widgets/issue_item.dart @@ -120,10 +120,9 @@ class IssueItem extends StatelessWidget { children: [ // FIXME: Deleted user if (payload['author'] != null) ...[ - Avatar( + Avatar.extraSmall( login: payload['author']['login'], url: payload['author']['avatarUrl'], - size: 8, ), SizedBox(width: 4), Text( diff --git a/lib/widgets/repository_item.dart b/lib/widgets/repository_item.dart index 8d75088..b43e3d0 100644 --- a/lib/widgets/repository_item.dart +++ b/lib/widgets/repository_item.dart @@ -130,7 +130,10 @@ class RepositoryItem extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Avatar(url: payload['owner']['avatarUrl'], size: 12), + Avatar.small( + url: payload['owner']['avatarUrl'], + login: payload['owner']['login'], + ), SizedBox(width: 8), Expanded( child: Column( diff --git a/lib/widgets/user_item.dart b/lib/widgets/user_item.dart index 58e8f0f..45ddf76 100644 --- a/lib/widgets/user_item.dart +++ b/lib/widgets/user_item.dart @@ -50,7 +50,7 @@ class UserItem extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Avatar(url: avatarUrl, size: 24), + Avatar.large(url: avatarUrl), SizedBox(width: 10), Expanded( child: Column(