From e3c11e48b2e358ebf2b96ad8948f812ccfec3632 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 17 May 2020 14:17:37 +0200 Subject: [PATCH] Show user membership --- lib/helpers/users_helper.dart | 1 + lib/models/advanced_user_info.dart | 3 + .../widgets/tablet_mode/user_page_tablet.dart | 55 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/helpers/users_helper.dart b/lib/helpers/users_helper.dart index 8d1c1c5..5596126 100644 --- a/lib/helpers/users_helper.dart +++ b/lib/helpers/users_helper.dart @@ -164,6 +164,7 @@ class UsersHelper { canPostTexts: data["can_post_texts"], isFriendsListPublic: data["friend_list_public"], numberFriends: data["number_friends"], + accountCreationTime: data["account_creation_time"], likes: data["pageLikes"], userLike: data["user_like_page"], ); diff --git a/lib/models/advanced_user_info.dart b/lib/models/advanced_user_info.dart index 84a96b5..9384985 100644 --- a/lib/models/advanced_user_info.dart +++ b/lib/models/advanced_user_info.dart @@ -14,6 +14,7 @@ class AdvancedUserInfo extends User implements LikeElement { final bool canPostTexts; final bool isFriendsListPublic; final int numberFriends; + final int accountCreationTime; bool userLike; int likes; @@ -29,12 +30,14 @@ class AdvancedUserInfo extends User implements LikeElement { @required this.canPostTexts, @required this.isFriendsListPublic, @required this.numberFriends, + @required this.accountCreationTime, @required this.userLike, @required this.likes, }) : assert(publicNote != null), assert(canPostTexts != null), assert(isFriendsListPublic != null), assert(numberFriends != null), + assert(accountCreationTime != null), assert(userLike != null), assert(likes != null), super( diff --git a/lib/ui/widgets/tablet_mode/user_page_tablet.dart b/lib/ui/widgets/tablet_mode/user_page_tablet.dart index 46dbcec..482c125 100644 --- a/lib/ui/widgets/tablet_mode/user_page_tablet.dart +++ b/lib/ui/widgets/tablet_mode/user_page_tablet.dart @@ -10,6 +10,8 @@ import 'package:comunic/ui/widgets/post_create_form_widget.dart'; import 'package:comunic/ui/widgets/posts_list_widget.dart'; import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/conversations_utils.dart'; +import 'package:comunic/utils/date_utils.dart'; +import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -138,7 +140,19 @@ class _UserPageTabletState extends State { ); /// Build user information card - Widget _buildAboutCard() => Container(); + Widget _buildAboutCard() => _LeftPaneContainer( + child: Column( + children: [ + // User membership + _AboutUserEntry( + icon: Icons.access_time, + title: tr("Membership"), + value: tr("Member for %t%", args: { + "t": diffTimeFromNowToStr(_userInfo.accountCreationTime) + })), + ], + ), + ); } class _LeftPaneContainer extends StatelessWidget { @@ -171,3 +185,42 @@ class _MainCardSpacer extends StatelessWidget { Widget build(BuildContext context) => visible ? SizedBox(height: 10) : Container(); } + +class _AboutUserEntry extends StatelessWidget { + final IconData icon; + final String title; + final String value; + final bool visible; + + const _AboutUserEntry({ + Key key, + @required this.icon, + @required this.title, + @required this.value, + this.visible = true, + }) : assert(icon != null), + assert(title != null), + assert(visible != null), + super(key: key); + + @override + Widget build(BuildContext context) { + if (!visible) return Container(); + + return ListTile( + title: RichText( + text: TextSpan( + children: [ + WidgetSpan( + child: Icon(icon, size: 15), + alignment: PlaceholderAlignment.middle, + ), + TextSpan(text: " $title") + ], + ), + ), + subtitle: Text(value), + dense: true, + ); + } +}