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({
|
|
|
|
Key key,
|
|
|
|
@required this.user,
|
|
|
|
}) : assert(user != null),
|
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_AboutUserSectionState createState() => _AboutUserSectionState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AboutUserSectionState extends State<AboutUserSection> {
|
2021-03-17 16:46:50 +00:00
|
|
|
FriendStatus _friendStatus;
|
|
|
|
|
|
|
|
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: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!"));
|
|
|
|
|
|
|
|
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")),
|
|
|
|
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")),
|
|
|
|
subtitle: TextWidget(
|
|
|
|
content: DisplayedString(widget.user.publicNote)),
|
|
|
|
)
|
|
|
|
: Container(),
|
|
|
|
|
|
|
|
// Virtual directory
|
|
|
|
widget.user.hasVirtualDirectory
|
|
|
|
? ListTile(
|
|
|
|
leading: Icon(Icons.alternate_email),
|
|
|
|
title: Text(tr("Virtual directory")),
|
|
|
|
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),
|
|
|
|
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")),
|
|
|
|
subtitle: Text(widget.user.numberFriends.toString()),
|
|
|
|
)
|
|
|
|
: Container(),
|
|
|
|
|
|
|
|
// Member for
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.access_time_rounded),
|
|
|
|
title: Text(tr("Member for")),
|
|
|
|
subtitle:
|
|
|
|
Text(diffTimeFromNowToStr(widget.user.accountCreationTime)),
|
|
|
|
),
|
|
|
|
|
|
|
|
// Account visibility
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(Icons.remove_red_eye),
|
|
|
|
title: Text(tr("Account visibility")),
|
|
|
|
subtitle: Text(widget.user.pageVisibility == UserPageVisibility.OPEN
|
|
|
|
? tr("Open page")
|
|
|
|
: (widget.user.pageVisibility == UserPageVisibility.PUBLIC
|
|
|
|
? tr("Public page")
|
|
|
|
: tr("Private page"))),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|