mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
Start to refactor user page
This commit is contained in:
parent
afeb8c4a7d
commit
20e486fe26
49
lib/ui/screens/user_page_sections/user_page_header.dart
Normal file
49
lib/ui/screens/user_page_sections/user_page_header.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import 'package:comunic/models/advanced_user_info.dart';
|
||||||
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
|
import 'package:comunic/utils/account_utils.dart';
|
||||||
|
import 'package:comunic/utils/conversations_utils.dart';
|
||||||
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// User header
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
class UserPageHeader extends StatelessWidget {
|
||||||
|
final AdvancedUserInfo user;
|
||||||
|
final Color bgColor;
|
||||||
|
|
||||||
|
const UserPageHeader({
|
||||||
|
Key key,
|
||||||
|
@required this.user,
|
||||||
|
@required this.bgColor,
|
||||||
|
}) : assert(user != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Container(
|
||||||
|
color: bgColor,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
InkWell(
|
||||||
|
onTap: () => showImageFullScreen(context, user.accountImageURL),
|
||||||
|
child: AccountImageWidget(user: user),
|
||||||
|
),
|
||||||
|
Expanded(flex: 1, child: Text(" ${user.displayName}")),
|
||||||
|
user.id == userID()
|
||||||
|
? Container()
|
||||||
|
: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.chat,
|
||||||
|
color: DefaultTextStyle.of(context).style.color,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
openPrivateConversation(context, user.id);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
49
lib/ui/screens/user_page_sections/user_posts_section.dart
Normal file
49
lib/ui/screens/user_page_sections/user_posts_section.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
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/widgets/post_create_form_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// User posts
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
class UserPostsSection extends StatefulWidget {
|
||||||
|
final AdvancedUserInfo user;
|
||||||
|
|
||||||
|
const UserPostsSection({
|
||||||
|
Key key,
|
||||||
|
@required this.user,
|
||||||
|
}) : assert(user != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_UserPostsSectionState createState() => _UserPostsSectionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UserPostsSectionState extends State<UserPostsSection> {
|
||||||
|
int get _userID => widget.user.id;
|
||||||
|
|
||||||
|
final _postsKey = GlobalKey<PostsListWidgetState>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => PostsListWidget(
|
||||||
|
topWidgets: [
|
||||||
|
widget.user.canPostTexts
|
||||||
|
? PostCreateFormWidget(
|
||||||
|
postTarget: PostTarget.USER_PAGE,
|
||||||
|
targetID: _userID,
|
||||||
|
onCreated: _postCreated,
|
||||||
|
)
|
||||||
|
: Container()
|
||||||
|
],
|
||||||
|
getPostsList: () => PostsHelper().getUserPosts(_userID),
|
||||||
|
getOlder: (from) => PostsHelper().getUserPosts(_userID, from: from),
|
||||||
|
showPostsTarget: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
void _postCreated() {
|
||||||
|
_postsKey.currentState.loadPostsList(getOlder: false);
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,13 @@
|
|||||||
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/models/advanced_user_info.dart';
|
||||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
import 'package:comunic/ui/screens/user_page_sections/user_page_header.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/screens/user_page_sections/user_posts_section.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/intl_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Mobile mode of user page
|
/// Mobile mode of user page
|
||||||
///
|
///
|
||||||
/// @author Pierre Hubert
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
enum _MenuOptions { FRIENDS_LIST }
|
|
||||||
|
|
||||||
class UserMobilePage extends StatefulWidget {
|
class UserMobilePage extends StatefulWidget {
|
||||||
final AdvancedUserInfo userInfo;
|
final AdvancedUserInfo userInfo;
|
||||||
final void Function() onNeedRefresh;
|
final void Function() onNeedRefresh;
|
||||||
@ -33,80 +24,73 @@ class UserMobilePage extends StatefulWidget {
|
|||||||
_UserMobilePageState createState() => _UserMobilePageState();
|
_UserMobilePageState createState() => _UserMobilePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UserMobilePageState extends State<UserMobilePage> {
|
class _UserMobilePageState extends State<UserMobilePage>
|
||||||
AdvancedUserInfo get _userInfo => widget.userInfo;
|
with SingleTickerProviderStateMixin {
|
||||||
|
TabController _tabController;
|
||||||
|
|
||||||
int get _userID => _userInfo.id;
|
List<UserPageTab> get _tabs => [
|
||||||
|
// User posts
|
||||||
Widget _buildHeader() {
|
UserPageTab(
|
||||||
return Container(
|
label: tr("Posts"),
|
||||||
color: Colors.black26,
|
onBuild: (c) => UserPostsSection(
|
||||||
child: Padding(
|
user: widget.userInfo,
|
||||||
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
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
void dispose() {
|
||||||
return PostsListWidget(
|
_tabController.dispose();
|
||||||
topWidgets: [
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Column(children: [
|
||||||
_buildHeader(),
|
_buildHeader(),
|
||||||
_userInfo.canPostTexts
|
_buildBody(),
|
||||||
? 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
|
Widget _buildHeader() => Material(
|
||||||
void _selectedMenuOption(_MenuOptions value) {
|
color: Colors.blue.shade700,
|
||||||
switch (value) {
|
textStyle: TextStyle(color: Colors.white),
|
||||||
case _MenuOptions.FRIENDS_LIST:
|
child: Column(
|
||||||
MainController.of(context).openUserFriendsList(_userInfo.id);
|
children: [
|
||||||
break;
|
UserPageHeader(
|
||||||
}
|
user: widget.userInfo,
|
||||||
}
|
bgColor: Colors.transparent,
|
||||||
|
),
|
||||||
|
TabBar(
|
||||||
|
controller: _tabController,
|
||||||
|
tabs: _tabs.map((e) => e.tab).toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/// Method called once a post has been created
|
Widget _buildBody() => Expanded(
|
||||||
void _postCreated() {
|
child: TabBarView(
|
||||||
widget.onNeedRefresh();
|
controller: _tabController,
|
||||||
}
|
children: _tabs.map((e) => e.onBuild(context)).toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserPageTab {
|
||||||
|
final String label;
|
||||||
|
final WidgetBuilder onBuild;
|
||||||
|
|
||||||
|
UserPageTab({
|
||||||
|
@required this.label,
|
||||||
|
@required this.onBuild,
|
||||||
|
}) : assert(label != null),
|
||||||
|
assert(onBuild != null);
|
||||||
|
|
||||||
|
Tab get tab => Tab(text: label);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user