diff --git a/lib/screens/account/profile_page.dart b/lib/screens/account/profile_page.dart index a4c47ef..a10c1d5 100644 --- a/lib/screens/account/profile_page.dart +++ b/lib/screens/account/profile_page.dart @@ -132,6 +132,63 @@ class _AccountProfilePageState extends State { } } + Future _subscribeToUser() async { + setState(() => _isSubscribing = true); + _subscription = + await Get.find().subscribeToUser(_userinfo!.id); + setState(() => _isSubscribing = false); + } + + Future _unsubscribeFromUser() async { + setState(() => _isSubscribing = true); + await Get.find().unsubscribeFromUser(_userinfo!.id); + _subscription = null; + setState(() => _isSubscribing = false); + } + + Future _makeFriend() async { + setState(() => _isMakingFriend = true); + try { + _relationship = await _relationshipProvider.makeFriend(widget.name); + context.showSnackbar( + 'accountFriendRequestSent'.tr, + ); + } catch (e) { + context.showErrorDialog(e); + } finally { + setState(() => _isMakingFriend = false); + } + } + + Future _blockUser() async { + setState(() => _isMakingFriend = true); + try { + _relationship = await _relationshipProvider.blockUser(widget.name); + context.showSnackbar( + 'accountBlocked'.tr, + ); + } catch (e) { + context.showErrorDialog(e); + } finally { + setState(() => _isMakingFriend = false); + } + } + + Future _unblockUser() async { + setState(() => _isMakingFriend = true); + try { + _relationship = + await _relationshipProvider.editRelation(_userinfo!.id, 1); + context.showSnackbar( + 'accountUnblocked'.tr, + ); + } catch (e) { + context.showErrorDialog(e); + } finally { + setState(() => _isMakingFriend = false); + } + } + int get _userSocialCreditPoints { return _totalUpvote * 2 - _totalDownvote + _postController.postTotal.value; } @@ -170,23 +227,6 @@ class _AccountProfilePageState extends State { }); } - Widget _buildStatisticsEntry(String label, String content) { - return Expanded( - child: Column( - children: [ - Text( - label, - style: Theme.of(context).textTheme.bodySmall, - ), - Text( - content, - style: Theme.of(context).textTheme.bodyLarge, - ), - ], - ), - ); - } - @override Widget build(BuildContext context) { if (_isBusy || _userinfo == null) { @@ -239,15 +279,7 @@ class _AccountProfilePageState extends State { visualDensity: VisualDensity(horizontal: -4, vertical: -2), ), - onPressed: _isSubscribing - ? null - : () async { - setState(() => _isSubscribing = true); - _subscription = - await Get.find() - .subscribeToUser(_userinfo!.id); - setState(() => _isSubscribing = false); - }, + onPressed: _isSubscribing ? null : _subscribeToUser, icon: const Icon(Icons.add_circle_outline), tooltip: 'subscribe'.tr, ) @@ -257,37 +289,15 @@ class _AccountProfilePageState extends State { visualDensity: VisualDensity(horizontal: -4, vertical: -2), ), - onPressed: _isSubscribing - ? null - : () async { - setState(() => _isSubscribing = true); - await Get.find() - .unsubscribeFromUser(_userinfo!.id); - _subscription = null; - setState(() => _isSubscribing = false); - }, + onPressed: + _isSubscribing ? null : _unsubscribeFromUser, icon: const Icon(Icons.remove_circle_outline), tooltip: 'unsubscribe'.tr, ), if (_userinfo != null && _relationship == null) IconButton( icon: const Icon(Icons.person_add), - onPressed: _isMakingFriend - ? null - : () async { - setState(() => _isMakingFriend = true); - try { - _relationship = await _relationshipProvider - .makeFriend(widget.name); - context.showSnackbar( - 'accountFriendRequestSent'.tr, - ); - } catch (e) { - context.showErrorDialog(e); - } finally { - setState(() => _isMakingFriend = false); - } - }, + onPressed: _isMakingFriend ? null : _makeFriend, tooltip: 'friendAdd'.tr, ) else @@ -315,9 +325,8 @@ class _AccountProfilePageState extends State { physics: const NeverScrollableScrollPhysics(), children: [ ListView( - padding: EdgeInsets.zero, + padding: const EdgeInsets.only(top: 16, bottom: 16), children: [ - const Gap(16), CenteredContainer( child: AccountHeadingWidget( name: _userinfo!.name, @@ -484,25 +493,8 @@ class _AccountProfilePageState extends State { vertical: -2, ), ), - onPressed: _isMakingFriend - ? null - : () async { - setState( - () => _isMakingFriend = true); - try { - _relationship = - await _relationshipProvider - .blockUser(widget.name); - context.showSnackbar( - 'accountBlocked'.tr, - ); - } catch (e) { - context.showErrorDialog(e); - } finally { - setState(() => - _isMakingFriend = false); - } - }, + onPressed: + _isMakingFriend ? null : _blockUser, icon: const Icon( Icons.block, size: 16, @@ -517,26 +509,8 @@ class _AccountProfilePageState extends State { vertical: -2, ), ), - onPressed: _isMakingFriend - ? null - : () async { - setState( - () => _isMakingFriend = true); - try { - _relationship = - await _relationshipProvider - .editRelation( - _userinfo!.id, 1); - context.showSnackbar( - 'accountUnblocked'.tr, - ); - } catch (e) { - context.showErrorDialog(e); - } finally { - setState(() => - _isMakingFriend = false); - } - }, + onPressed: + _isMakingFriend ? null : _unblockUser, icon: const Icon( Icons.add_circle_outline, size: 16, @@ -564,7 +538,7 @@ class _AccountProfilePageState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - _buildStatisticsEntry( + _StatsWidget( 'totalSocialCreditPoints'.tr, _userinfo != null ? _userSocialCreditPoints.toString() @@ -577,16 +551,16 @@ class _AccountProfilePageState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Obx( - () => _buildStatisticsEntry( + () => _StatsWidget( 'totalPostCount'.tr, _postController.postTotal.value.toString(), ), ), - _buildStatisticsEntry( + _StatsWidget( 'totalUpvote'.tr, _totalUpvote.toString(), ), - _buildStatisticsEntry( + _StatsWidget( 'totalDownvote'.tr, _totalDownvote.toString(), ), @@ -684,3 +658,28 @@ class _AccountProfilePageState extends State { ); } } + +class _StatsWidget extends StatelessWidget { + final String label; + final String content; + + const _StatsWidget(this.label, this.content); + + @override + Widget build(BuildContext context) { + return Expanded( + child: Column( + children: [ + Text( + label, + style: Theme.of(context).textTheme.bodySmall, + ), + Text( + content, + style: Theme.of(context).textTheme.bodyLarge, + ), + ], + ), + ); + } +} diff --git a/lib/widgets/account/account_profile_popup.dart b/lib/widgets/account/account_profile_popup.dart index 7ca58f4..0190df1 100644 --- a/lib/widgets/account/account_profile_popup.dart +++ b/lib/widgets/account/account_profile_popup.dart @@ -113,7 +113,7 @@ class _AccountProfilePopupState extends State { borderRadius: BorderRadius.all(Radius.circular(8)), ), title: Text('visitProfilePage'.tr), - subtitle: Text('learMoreAboutPerson'.tr), + subtitle: Text('learnMoreAboutPerson'.tr), visualDensity: const VisualDensity(horizontal: -4, vertical: -2), trailing: const Icon(Icons.chevron_right),