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

119 lines
3.1 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,
2022-03-11 15:36:42 +00:00
}) : super(key: key);
2020-05-16 08:20:27 +00:00
@override
_UserMobilePageState createState() => _UserMobilePageState();
}
2021-03-17 16:04:45 +00:00
class _UserMobilePageState extends State<UserMobilePage>
with SingleTickerProviderStateMixin {
TabController? _tabController;
2021-03-17 16:04:45 +00:00
List<UserPageTab> get _tabs => [
// User posts
UserPageTab(
label: tr("Posts")!,
2021-03-17 16:04:45 +00:00
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")!,
2021-03-17 16:40:25 +00:00
onBuild: (c) => AboutUserSection(user: widget.userInfo),
),
2021-03-17 16:14:53 +00:00
// User friends
UserPageTab(
label: tr("Friends")!,
2021-03-17 16:14:53 +00:00
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();
2021-03-17 16:04:45 +00:00
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,
2022-03-11 15:36:42 +00:00
});
2021-03-17 16:04:45 +00:00
Tab get tab => Tab(text: label);
2020-05-16 08:20:27 +00:00
}