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';
|
2021-04-17 06:47:05 +00:00
|
|
|
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({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.user,
|
2021-03-17 16:40:25 +00:00
|
|
|
}) : assert(user != null),
|
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_AboutUserSectionState createState() => _AboutUserSectionState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AboutUserSectionState extends State<AboutUserSection> {
|
2022-03-10 18:39:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
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,
|
2022-03-10 18:39:57 +00:00
|
|
|
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),
|
2022-03-10 18:39:57 +00:00
|
|
|
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),
|
2022-03-10 18:39:57 +00:00
|
|
|
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),
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Virtual directory")!),
|
2021-03-17 16:40:25 +00:00
|
|
|
subtitle: Text("@${widget.user.virtualDirectory}"))
|
|
|
|
: Container(),
|
|
|
|
|
2021-04-17 06:47:05 +00:00
|
|
|
// User email address
|
|
|
|
widget.user.emailAddress == null
|
|
|
|
? Container()
|
|
|
|
: ListTile(
|
|
|
|
leading: Icon(Icons.email_outlined),
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Email address")!),
|
|
|
|
subtitle: Text(widget.user.emailAddress!),
|
2021-04-17 06:47:05 +00:00
|
|
|
onTap: () =>
|
2022-03-10 18:39:57 +00:00
|
|
|
copyToClipboard(context, widget.user.emailAddress!),
|
2021-04-17 06:47:05 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
// User location
|
|
|
|
widget.user.location == null
|
|
|
|
? Container()
|
|
|
|
: ListTile(
|
|
|
|
leading: Icon(Icons.location_on),
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Location")!),
|
|
|
|
subtitle: Text(widget.user.location!),
|
|
|
|
onTap: () => copyToClipboard(context, widget.user.location!),
|
2021-04-17 06:47:05 +00:00
|
|
|
),
|
|
|
|
|
2021-03-17 16:40:25 +00:00
|
|
|
// Number of friends
|
|
|
|
widget.user.isFriendsListPublic
|
|
|
|
? ListTile(
|
|
|
|
leading: Icon(Icons.group),
|
2022-03-10 18:39:57 +00:00
|
|
|
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),
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Member for")!),
|
2021-03-17 16:40:25 +00:00
|
|
|
subtitle:
|
2022-03-10 18:39:57 +00:00
|
|
|
Text(diffTimeFromNowToStr(widget.user.accountCreationTime)!),
|
2021-03-17 16:40:25 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
// Account visibility
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.remove_red_eye),
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Account visibility")!),
|
2021-03-17 16:40:25 +00:00
|
|
|
subtitle: Text(widget.user.pageVisibility == UserPageVisibility.OPEN
|
2022-03-10 18:39:57 +00:00
|
|
|
? tr("Open page")!
|
2021-03-17 16:40:25 +00:00
|
|
|
: (widget.user.pageVisibility == UserPageVisibility.PUBLIC
|
2022-03-10 18:39:57 +00:00
|
|
|
? tr("Public page")!
|
|
|
|
: tr("Private page")!)),
|
2021-03-17 16:40:25 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|