From ca7ecb311f5f7cd5d37e6028512ae9974d281eff Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:39:40 +0900 Subject: [PATCH 1/2] add trailing commas --- lib/view/common/avatar_icon.dart | 144 ++++++++++++++++--------------- 1 file changed, 76 insertions(+), 68 deletions(-) diff --git a/lib/view/common/avatar_icon.dart b/lib/view/common/avatar_icon.dart index 63258a520..470937f36 100644 --- a/lib/view/common/avatar_icon.dart +++ b/lib/view/common/avatar_icon.dart @@ -32,8 +32,10 @@ class AvatarIcon extends StatelessWidget { ); } - factory AvatarIcon.fromUserResponse(UsersShowResponse response, - {double height = 48}) { + factory AvatarIcon.fromUserResponse( + UsersShowResponse response, { + double height = 48, + }) { return AvatarIcon( user: User( id: response.id, @@ -49,72 +51,78 @@ class AvatarIcon extends StatelessWidget { @override Widget build(BuildContext context) { return GestureDetector( - onTap: onTap ?? - () { - context.pushRoute(UserRoute( - userId: user.id, account: AccountScope.of(context))); - }, - child: Padding( - padding: const EdgeInsets.only(top: 3), - child: Stack(children: [ - if (user.isCat) - Positioned( - left: 0, - top: 0, - width: height * MediaQuery.of(context).textScaleFactor, - height: height * MediaQuery.of(context).textScaleFactor, - child: Transform.rotate( - angle: -0 * pi / 180, - child: Transform.translate( - offset: Offset( - -height * - 0.3 * - MediaQuery.of(context).textScaleFactor, - -height * - 0.3 * - MediaQuery.of(context).textScaleFactor), - child: Icon(Icons.play_arrow_rounded, - color: Theme.of(context).primaryColor, - size: height * - 1 * - MediaQuery.of(context).textScaleFactor), - ), - )), - if (user.isCat) - Positioned( - left: 0, - top: 0, - width: height * MediaQuery.of(context).textScaleFactor, - height: height * MediaQuery.of(context).textScaleFactor, - child: Transform.translate( - offset: Offset( - height * - 1.333 * - MediaQuery.of(context).textScaleFactor, - -height * - 0.3 * - MediaQuery.of(context).textScaleFactor), - child: Transform( - transform: Matrix4.rotationY(pi), - child: Icon(Icons.play_arrow_rounded, - color: Theme.of(context).primaryColor, - size: height * - 1 * - MediaQuery.of(context).textScaleFactor), - ), - )), - ClipRRect( - borderRadius: BorderRadius.circular( - height * MediaQuery.of(context).textScaleFactor), - child: SizedBox( - width: height * MediaQuery.of(context).textScaleFactor, - height: height * MediaQuery.of(context).textScaleFactor, - child: NetworkImageView( - fit: BoxFit.cover, - url: user.avatarUrl.toString(), - type: ImageType.avatarIcon, - )), + onTap: onTap ?? + () { + context.pushRoute( + UserRoute( + userId: user.id, + account: AccountScope.of(context), ), - ]))); + ); + }, + child: Padding( + padding: const EdgeInsets.only(top: 3), + child: Stack( + children: [ + if (user.isCat) + Positioned( + left: 0, + top: 0, + width: height * MediaQuery.of(context).textScaleFactor, + height: height * MediaQuery.of(context).textScaleFactor, + child: Transform.rotate( + angle: -0 * pi / 180, + child: Transform.translate( + offset: Offset( + -height * 0.3 * MediaQuery.of(context).textScaleFactor, + -height * 0.3 * MediaQuery.of(context).textScaleFactor, + ), + child: Icon( + Icons.play_arrow_rounded, + color: Theme.of(context).primaryColor, + size: height * 1 * MediaQuery.of(context).textScaleFactor, + ), + ), + ), + ), + if (user.isCat) + Positioned( + left: 0, + top: 0, + width: height * MediaQuery.of(context).textScaleFactor, + height: height * MediaQuery.of(context).textScaleFactor, + child: Transform.translate( + offset: Offset( + height * 1.333 * MediaQuery.of(context).textScaleFactor, + -height * 0.3 * MediaQuery.of(context).textScaleFactor, + ), + child: Transform( + transform: Matrix4.rotationY(pi), + child: Icon( + Icons.play_arrow_rounded, + color: Theme.of(context).primaryColor, + size: height * 1 * MediaQuery.of(context).textScaleFactor, + ), + ), + ), + ), + ClipRRect( + borderRadius: BorderRadius.circular( + height * MediaQuery.of(context).textScaleFactor, + ), + child: SizedBox( + width: height * MediaQuery.of(context).textScaleFactor, + height: height * MediaQuery.of(context).textScaleFactor, + child: NetworkImageView( + fit: BoxFit.cover, + url: user.avatarUrl.toString(), + type: ImageType.avatarIcon, + ), + ), + ), + ], + ), + ), + ); } } From a0774050c11ba9029ed39eed46a90308b46830b7 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:43:00 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E7=8C=AB=E8=80=B3=E3=81=AE=E8=89=B2?= =?UTF-8?q?=E3=82=92=E3=82=A2=E3=82=A4=E3=82=B3=E3=83=B3=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E3=81=AE=E5=B9=B3=E5=9D=87=E8=89=B2=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/view/common/avatar_icon.dart | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/view/common/avatar_icon.dart b/lib/view/common/avatar_icon.dart index 470937f36..3bb153513 100644 --- a/lib/view/common/avatar_icon.dart +++ b/lib/view/common/avatar_icon.dart @@ -25,6 +25,7 @@ class AvatarIcon extends StatelessWidget { id: response.id, username: response.username, avatarUrl: response.avatarUrl, + avatarBlurhash: response.avatarBlurhash, isCat: response.isCat, isBot: response.isBot, ), @@ -41,6 +42,7 @@ class AvatarIcon extends StatelessWidget { id: response.id, username: response.username, avatarUrl: response.avatarUrl, + avatarBlurhash: response.avatarBlurhash, isCat: response.isCat, isBot: response.isBot, ), @@ -48,16 +50,33 @@ class AvatarIcon extends StatelessWidget { ); } + Color? averageColor() { + // https://github.com/woltapp/blurhash/blob/master/Algorithm.md + final blurhash = user.avatarBlurhash; + if (blurhash == null) { + return null; + } + final value = blurhash + .substring(2, 6) + .split("") + .map( + r'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~' + .indexOf, + ) + .fold(0, (acc, i) => acc * 83 + i); + return Color(0xFF000000 | value); + } + @override Widget build(BuildContext context) { + final catEarColor = + (user.isCat ? averageColor() : null) ?? Theme.of(context).primaryColor; + return GestureDetector( onTap: onTap ?? () { context.pushRoute( - UserRoute( - userId: user.id, - account: AccountScope.of(context), - ), + UserRoute(userId: user.id, account: AccountScope.of(context)), ); }, child: Padding( @@ -79,7 +98,7 @@ class AvatarIcon extends StatelessWidget { ), child: Icon( Icons.play_arrow_rounded, - color: Theme.of(context).primaryColor, + color: catEarColor, size: height * 1 * MediaQuery.of(context).textScaleFactor, ), ), @@ -100,7 +119,7 @@ class AvatarIcon extends StatelessWidget { transform: Matrix4.rotationY(pi), child: Icon( Icons.play_arrow_rounded, - color: Theme.of(context).primaryColor, + color: catEarColor, size: height * 1 * MediaQuery.of(context).textScaleFactor, ), ),