1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/ui/screens/authorized_group_page_screen.dart

186 lines
5.3 KiB
Dart
Raw Normal View History

2020-04-15 16:23:38 +00:00
import 'package:comunic/models/advanced_group_info.dart';
2020-05-05 11:21:37 +00:00
import 'package:comunic/ui/routes/main_route/main_route.dart';
2021-03-16 18:01:50 +00:00
import 'package:comunic/ui/screens/group_sections/about_group_section.dart';
2021-03-16 17:41:16 +00:00
import 'package:comunic/ui/screens/group_sections/group_members_screen.dart';
2021-03-16 17:36:17 +00:00
import 'package:comunic/ui/screens/group_sections/group_posts_section.dart';
2020-05-01 13:12:55 +00:00
import 'package:comunic/ui/screens/group_settings_screen.dart';
2020-04-15 16:39:07 +00:00
import 'package:comunic/ui/widgets/group_following_widget.dart';
2020-04-15 16:23:38 +00:00
import 'package:comunic/ui/widgets/group_icon_widget.dart';
import 'package:comunic/ui/widgets/group_membership_widget.dart';
2020-04-15 17:23:08 +00:00
import 'package:comunic/ui/widgets/like_widget.dart';
2021-03-16 18:14:49 +00:00
import 'package:comunic/ui/widgets/post_container_widget.dart';
2021-03-16 17:27:02 +00:00
import 'package:comunic/ui/widgets/safe_state.dart';
2020-05-01 13:12:55 +00:00
import 'package:comunic/utils/intl_utils.dart';
2020-04-15 16:23:38 +00:00
import 'package:flutter/material.dart';
/// Authorized group page screen
///
/// This screen is shown when the user is allowed to access to a group's page
///
/// @author Pierre Hubert
2021-03-16 17:27:02 +00:00
Color get _headerTextColor => Colors.white;
Color get _headerColor => Colors.blueAccent.shade700;
2020-04-15 16:23:38 +00:00
class AuthorizedGroupPageScreen extends StatefulWidget {
final AdvancedGroupInfo advancedGroupInfo;
final Function() needRefresh;
const AuthorizedGroupPageScreen({
Key key,
@required this.advancedGroupInfo,
@required this.needRefresh,
}) : assert(advancedGroupInfo != null),
assert(needRefresh != null),
super(key: key);
@override
_AuthorizedGroupPageScreenState createState() =>
_AuthorizedGroupPageScreenState();
}
2021-03-16 17:27:02 +00:00
class _AuthorizedGroupPageScreenState
extends SafeState<AuthorizedGroupPageScreen>
with SingleTickerProviderStateMixin {
2020-04-15 16:23:38 +00:00
AdvancedGroupInfo get _group => widget.advancedGroupInfo;
2021-03-16 17:27:02 +00:00
TabController _tabController;
List<_GroupPageTab> get _tabs => [
2021-03-16 17:36:17 +00:00
// Posts list
_GroupPageTab(
2021-03-17 15:58:10 +00:00
widget: (c) => GroupPostsSection(group: _group),
2021-03-16 17:36:17 +00:00
label: tr("Posts"),
),
2021-03-16 18:01:50 +00:00
// About the group
_GroupPageTab(
2021-03-17 15:58:10 +00:00
widget: (c) => AboutGroupSection(group: _group),
2021-03-16 18:01:50 +00:00
label: tr("About"),
)
2021-03-16 17:41:16 +00:00
]..addAll(_group.isAtLeastModerator
? [
_GroupPageTab(
2021-03-17 15:58:10 +00:00
widget: (c) => GroupMembersSection(groupID: _group.id),
2021-03-16 17:41:16 +00:00
label: tr("Members"),
),
]
: []);
2021-03-16 17:27:02 +00:00
@override
void initState() {
_tabController = TabController(
length: _tabs.length,
initialIndex: 0,
vsync: this,
);
super.initState();
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
2020-04-15 16:23:38 +00:00
@override
Widget build(BuildContext context) {
2021-03-16 18:14:49 +00:00
return PostContainer(
child: Column(
children: [
_buildGroupPageHeader(),
2021-03-17 15:58:10 +00:00
Material(
2021-03-16 18:14:49 +00:00
color: _headerColor,
child: TabBar(
tabs: _tabs.map((e) => e.tab).toList(),
controller: _tabController,
),
2021-03-16 17:27:02 +00:00
),
2021-03-16 18:14:49 +00:00
Expanded(
child: TabBarView(
controller: _tabController,
2021-03-17 15:58:10 +00:00
children: _tabs.map((e) => e.widget(context)).toList(),
2021-03-16 18:14:49 +00:00
),
2021-03-16 17:27:02 +00:00
),
2021-03-16 18:14:49 +00:00
],
),
2020-04-15 16:23:38 +00:00
);
}
/// Build group page header
2020-04-16 06:24:34 +00:00
Widget _buildGroupPageHeader() {
2021-03-16 17:36:17 +00:00
return Material(
color: _headerColor,
child: DefaultTextStyle(
style: TextStyle(color: _headerTextColor),
2021-03-16 17:27:02 +00:00
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
GroupIcon(
group: _group,
2021-03-16 16:43:24 +00:00
),
2021-03-16 17:27:02 +00:00
Expanded(
child: Text(
" ${_group.displayName}",
style: TextStyle(fontSize: 20),
2020-04-16 06:52:26 +00:00
),
2021-03-16 17:27:02 +00:00
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GroupMembershipWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
Container(
height: 4,
),
GroupFollowingWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
inactiveColor: Colors.blueAccent,
activeColor: Colors.white,
),
Container(
height: 2,
),
LikeWidget(
inativeColor: Colors.blueAccent,
activeColor: Colors.white,
likeElement: _group,
),
],
),
2021-03-16 17:36:17 +00:00
// Settings button
_group.isAdmin
? IconButton(
icon: Icon(Icons.settings, color: _headerTextColor),
2021-03-16 18:14:49 +00:00
onPressed: () => MainController.of(context).push(
GroupSettingsScreen(groupID: _group.id),
canShowAsDialog: true))
2021-03-16 17:36:17 +00:00
: Container(),
2021-03-16 17:27:02 +00:00
],
),
2020-04-16 06:52:26 +00:00
),
2020-04-15 16:23:38 +00:00
),
);
}
}
2021-03-16 17:27:02 +00:00
class _GroupPageTab {
2021-03-17 15:58:10 +00:00
final WidgetBuilder widget;
2021-03-16 17:27:02 +00:00
final String label;
const _GroupPageTab({
@required this.widget,
@required this.label,
}) : assert(widget != null),
assert(label != null);
Tab get tab => Tab(text: label);
}