1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 16:26:27 +00:00
comunicmobile/lib/ui/screens/user_page_sections/about_user_section.dart

135 lines
4.6 KiB
Dart
Raw Normal View History

2021-03-17 16:40:25 +00:00
import 'package:comunic/enums/user_page_visibility.dart';
2021-03-17 16:46:50 +00:00
import 'package:comunic/helpers/friends_helper.dart';
2021-03-17 16:40:25 +00:00
import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/models/displayed_content.dart';
2021-03-17 16:46:50 +00:00
import 'package:comunic/models/friend_status.dart';
import 'package:comunic/ui/widgets/FrienshipStatusWidget.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
2021-03-17 16:40:25 +00:00
import 'package:comunic/ui/widgets/text_widget.dart';
import 'package:comunic/utils/clipboard_utils.dart';
2021-03-17 16:40:25 +00:00
import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
/// About current user
///
/// @author Pierre Hubert
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class AboutUserSection extends StatefulWidget {
final AdvancedUserInfo user;
const AboutUserSection({
Key? key,
required this.user,
2022-03-11 15:40:56 +00:00
}) : super(key: key);
2021-03-17 16:40:25 +00:00
@override
_AboutUserSectionState createState() => _AboutUserSectionState();
}
class _AboutUserSectionState extends State<AboutUserSection> {
late FriendStatus _friendStatus;
2021-03-17 16:46:50 +00:00
final _screenKey = GlobalKey<AsyncScreenWidgetState>();
Future<void> _init() async {
if (!widget.user.isCurrentUser)
_friendStatus = await FriendsHelper().getFriendshipStatus(widget.user.id);
}
void _toggleRefresh() => _screenKey.currentState!.refresh();
2021-03-17 16:46:50 +00:00
2021-03-17 16:40:25 +00:00
@override
2021-03-17 16:46:50 +00:00
Widget build(BuildContext context) => AsyncScreenWidget(
key: _screenKey,
onReload: _init,
onBuild: _buildList,
errorMessage: tr("Failed to load user information!")!);
2021-03-17 16:46:50 +00:00
Widget _buildList() => ListView(
2021-03-17 16:40:25 +00:00
children: [
2021-03-17 16:46:50 +00:00
widget.user.isCurrentUser
? Container()
: FriendshipStatusWidget(
status: _friendStatus, onFriendshipUpdated: _toggleRefresh),
2021-03-17 16:40:25 +00:00
// Account URL
widget.user.hasPersonalWebsite
? ListTile(
leading: Icon(Icons.link),
title: Text(tr("Personal Website")!),
2021-03-17 16:40:25 +00:00
subtitle: Text(widget.user.personalWebsite),
onTap: () => launch(widget.user.personalWebsite),
)
: Container(),
// Account note
widget.user.hasPublicNote
? ListTile(
leading: Icon(Icons.note),
title: Text(tr("Note")!),
2021-03-17 16:40:25 +00:00
subtitle: TextWidget(
content: DisplayedString(widget.user.publicNote)),
)
: Container(),
// Virtual directory
widget.user.hasVirtualDirectory
? ListTile(
leading: Icon(Icons.alternate_email),
title: Text(tr("Virtual directory")!),
2021-03-17 16:40:25 +00:00
subtitle: Text("@${widget.user.virtualDirectory}"))
: Container(),
// User email address
widget.user.emailAddress == null
? Container()
: ListTile(
leading: Icon(Icons.email_outlined),
title: Text(tr("Email address")!),
subtitle: Text(widget.user.emailAddress!),
onTap: () =>
copyToClipboard(context, widget.user.emailAddress!),
),
// User location
widget.user.location == null
? Container()
: ListTile(
leading: Icon(Icons.location_on),
title: Text(tr("Location")!),
subtitle: Text(widget.user.location!),
onTap: () => copyToClipboard(context, widget.user.location!),
),
2021-03-17 16:40:25 +00:00
// Number of friends
widget.user.isFriendsListPublic
? ListTile(
leading: Icon(Icons.group),
title: Text(tr("Number of friends")!),
2021-03-17 16:40:25 +00:00
subtitle: Text(widget.user.numberFriends.toString()),
)
: Container(),
// Member for
ListTile(
leading: Icon(Icons.access_time_rounded),
title: Text(tr("Member for")!),
2021-03-17 16:40:25 +00:00
subtitle:
Text(diffTimeFromNowToStr(widget.user.accountCreationTime)!),
2021-03-17 16:40:25 +00:00
),
// Account visibility
ListTile(
leading: Icon(Icons.remove_red_eye),
title: Text(tr("Account visibility")!),
2021-03-17 16:40:25 +00:00
subtitle: Text(widget.user.pageVisibility == UserPageVisibility.OPEN
? tr("Open page")!
2021-03-17 16:40:25 +00:00
: (widget.user.pageVisibility == UserPageVisibility.PUBLIC
? tr("Public page")!
: tr("Private page")!)),
2021-03-17 16:40:25 +00:00
),
],
);
}