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

123 lines
3.3 KiB
Dart
Raw Normal View History

2020-05-16 08:20:27 +00:00
import 'package:comunic/models/advanced_user_info.dart';
2021-03-17 16:14:53 +00:00
import 'package:comunic/ui/screens/friends_list_screen.dart';
import 'package:comunic/ui/screens/other_friends_lists_screen.dart';
2021-03-17 16:40:25 +00:00
import 'package:comunic/ui/screens/user_page_sections/about_user_section.dart';
2021-03-17 16:04:45 +00:00
import 'package:comunic/ui/screens/user_page_sections/user_page_header.dart';
import 'package:comunic/ui/screens/user_page_sections/user_posts_section.dart';
2020-05-16 08:20:27 +00:00
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Mobile mode of user page
///
/// @author Pierre Hubert
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();
}
2021-03-17 16:04:45 +00:00
class _UserMobilePageState extends State<UserMobilePage>
with SingleTickerProviderStateMixin {
TabController _tabController;
List<UserPageTab> get _tabs => [
// User posts
UserPageTab(
label: tr("Posts"),
onBuild: (c) => UserPostsSection(
user: widget.userInfo,
),
),
2021-03-17 16:14:53 +00:00
2021-03-17 16:40:25 +00:00
// About user
UserPageTab(
label: tr("About"),
onBuild: (c) => AboutUserSection(user: widget.userInfo),
),
2021-03-17 16:14:53 +00:00
// User friends
UserPageTab(
label: tr("Friends"),
onBuild: (c) => widget.userInfo.isCurrentUser
? FriendsListScreen(
showAppBar: false,
)
: OtherUserFriendsListScreen(
userID: widget.userInfo.id,
enableAppBar: false,
),
visible: widget.userInfo.isFriendsListPublic ||
widget.userInfo.isCurrentUser),
].where((element) => element.visible).toList();
2021-03-17 16:04:45 +00:00
@override
void initState() {
super.initState();
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
_tabController = TabController(length: _tabs.length, vsync: this);
}
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => Column(children: [
_buildHeader(),
_buildBody(),
]);
Widget _buildHeader() => Material(
color: Colors.blue.shade700,
textStyle: TextStyle(color: Colors.white),
child: Column(
children: [
UserPageHeader(
user: widget.userInfo,
bgColor: Colors.transparent,
2020-05-16 08:20:27 +00:00
),
2021-03-17 16:04:45 +00:00
TabBar(
controller: _tabController,
tabs: _tabs.map((e) => e.tab).toList(),
2020-05-16 08:20:27 +00:00
),
],
),
2021-03-17 16:04:45 +00:00
);
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
Widget _buildBody() => Expanded(
child: TabBarView(
controller: _tabController,
children: _tabs.map((e) => e.onBuild(context)).toList(),
),
);
}
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
class UserPageTab {
final String label;
final WidgetBuilder onBuild;
2021-03-17 16:14:53 +00:00
final bool visible;
2020-05-16 08:20:27 +00:00
2021-03-17 16:04:45 +00:00
UserPageTab({
@required this.label,
@required this.onBuild,
2021-03-17 16:14:53 +00:00
this.visible = true,
2021-03-17 16:04:45 +00:00
}) : assert(label != null),
2021-03-17 16:14:53 +00:00
assert(onBuild != null),
assert(visible != null);
2021-03-17 16:04:45 +00:00
Tab get tab => Tab(text: label);
2020-05-16 08:20:27 +00:00
}