1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Prepare for tablet mode of user page

This commit is contained in:
Pierre HUBERT 2020-05-16 10:20:27 +02:00
parent 288cd492a2
commit b364c7aece
2 changed files with 116 additions and 77 deletions

View File

@ -1,12 +1,8 @@
import 'package:comunic/enums/post_target.dart';
import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/helpers/users_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/conversations_utils.dart';
import 'package:comunic/ui/widgets/mobile_mode/user_page_mobile.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
@ -17,8 +13,6 @@ import 'package:flutter/material.dart';
enum _PageStatus { LOADING, ERROR, READY }
enum _MenuOptions { FRIENDS_LIST }
class UserPageScreen extends StatefulWidget {
final int userID;
@ -30,16 +24,14 @@ class UserPageScreen extends StatefulWidget {
_UserPageScreenState createState() => _UserPageScreenState();
}
class _UserPageScreenState extends State<UserPageScreen> {
class _UserPageScreenState extends SafeState<UserPageScreen> {
// Helpers
final usersHelper = UsersHelper();
final PostsHelper _postsHelper = PostsHelper();
// Objects members
_PageStatus _status = _PageStatus.LOADING;
AdvancedUserInfo _userInfo;
GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
_setStatus(_PageStatus s) => setState(() => _status = s);
@ -106,72 +98,10 @@ class _UserPageScreenState extends State<UserPageScreen> {
);
}
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(),
IconButton(
icon: Icon(
Icons.chat,
),
onPressed: () {
openPrivateConversation(context, widget.userID);
}),
PopupMenuButton<_MenuOptions>(
itemBuilder: (c) => [
PopupMenuItem(
child: Text(tr("Friends")),
enabled: _userInfo != null,
value: _MenuOptions.FRIENDS_LIST,
)
],
onSelected: _selectedMenuOption,
),
],
),
),
);
}
Widget _buildBody() {
return PostsListWidget(
topWidgets: [
_buildHeader(),
_userInfo.canPostTexts
? PostCreateFormWidget(
postTarget: PostTarget.USER_PAGE,
targetID: _userInfo.id,
onCreated: _postCreated,
)
: Container()
],
getPostsList: () => _postsHelper.getUserPosts(widget.userID),
getOlder: (from) => _postsHelper.getUserPosts(widget.userID, from: from),
showPostsTarget: false,
return UserMobilePage(
userInfo: _userInfo,
onNeedRefresh: () => _refreshIndicatorKey.currentState.show(),
);
}
/// 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() {
_refreshIndicatorKey.currentState.show();
}
}

View File

@ -0,0 +1,109 @@
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/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(),
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();
}
}