1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/ui/widgets/mobile_mode/user_page_mobile.dart

113 lines
3.3 KiB
Dart

import 'package:comunic/enums/post_target.dart';
import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/models/advanced_user_info.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
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/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Mobile mode of user page
///
/// @author Pierre Hubert
enum _MenuOptions { FRIENDS_LIST }
class UserMobilePage extends StatefulWidget {
final AdvancedUserInfo userInfo;
final void Function() onNeedRefresh;
const UserMobilePage({
Key key,
@required this.userInfo,
@required this.onNeedRefresh,
}) : assert(userInfo != null),
assert(onNeedRefresh != null),
super(key: key);
@override
_UserMobilePageState createState() => _UserMobilePageState();
}
class _UserMobilePageState extends State<UserMobilePage> {
AdvancedUserInfo get _userInfo => widget.userInfo;
int get _userID => _userInfo.id;
Widget _buildHeader() {
return Container(
color: Colors.black26,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
InkWell(
onTap: () =>
showImageFullScreen(context, _userInfo.accountImageURL),
child: AccountImageWidget(user: _userInfo),
),
Text(" ${_userInfo.displayName}"),
Spacer(),
_userID == userID()
? Container()
: IconButton(
icon: Icon(
Icons.chat,
),
onPressed: () {
openPrivateConversation(context, _userID);
}),
PopupMenuButton<_MenuOptions>(
itemBuilder: (c) => [
PopupMenuItem(
child: Text(tr("Friends")),
enabled: _userInfo != null,
value: _MenuOptions.FRIENDS_LIST,
)
],
onSelected: _selectedMenuOption,
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return PostsListWidget(
topWidgets: [
_buildHeader(),
_userInfo.canPostTexts
? PostCreateFormWidget(
postTarget: PostTarget.USER_PAGE,
targetID: _userInfo.id,
onCreated: _postCreated,
)
: Container()
],
getPostsList: () => PostsHelper().getUserPosts(_userID),
getOlder: (from) => PostsHelper().getUserPosts(_userID, from: from),
showPostsTarget: false,
);
}
/// Method called each time a menu option is selected
void _selectedMenuOption(_MenuOptions value) {
switch (value) {
case _MenuOptions.FRIENDS_LIST:
MainController.of(context).openUserFriendsList(_userInfo.id);
break;
}
}
/// Method called once a post has been created
void _postCreated() {
widget.onNeedRefresh();
}
}