1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Start to create group page tabs

This commit is contained in:
Pierre HUBERT 2021-03-16 18:27:02 +01:00
parent 0920a36cef
commit cc553e803d
3 changed files with 151 additions and 67 deletions

View File

@ -10,6 +10,7 @@ import 'package:comunic/ui/widgets/group_membership_widget.dart';
import 'package:comunic/ui/widgets/like_widget.dart'; import 'package:comunic/ui/widgets/like_widget.dart';
import 'package:comunic/ui/widgets/post_create_form_widget.dart'; import 'package:comunic/ui/widgets/post_create_form_widget.dart';
import 'package:comunic/ui/widgets/posts_list_widget.dart'; import 'package:comunic/ui/widgets/posts_list_widget.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -21,6 +22,10 @@ import 'package:flutter/material.dart';
enum _MenuItems { OPEN_MEMBERS, OPEN_SETTINGS } enum _MenuItems { OPEN_MEMBERS, OPEN_SETTINGS }
Color get _headerTextColor => Colors.white;
Color get _headerColor => Colors.blueAccent.shade700;
class AuthorizedGroupPageScreen extends StatefulWidget { class AuthorizedGroupPageScreen extends StatefulWidget {
final AdvancedGroupInfo advancedGroupInfo; final AdvancedGroupInfo advancedGroupInfo;
final Function() needRefresh; final Function() needRefresh;
@ -38,73 +43,120 @@ class AuthorizedGroupPageScreen extends StatefulWidget {
_AuthorizedGroupPageScreenState(); _AuthorizedGroupPageScreenState();
} }
class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> { class _AuthorizedGroupPageScreenState
extends SafeState<AuthorizedGroupPageScreen>
with SingleTickerProviderStateMixin {
AdvancedGroupInfo get _group => widget.advancedGroupInfo; AdvancedGroupInfo get _group => widget.advancedGroupInfo;
TabController _tabController;
final _postsKey = GlobalKey<PostsListWidgetState>(); final _postsKey = GlobalKey<PostsListWidgetState>();
List<_GroupPageTab> get _tabs => [
_GroupPageTab(widget: _buildGroupPagePostsList(), label: tr("Posts")),
];
@override
void initState() {
_tabController = TabController(
length: _tabs.length,
initialIndex: 0,
vsync: this,
);
super.initState();
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RefreshIndicator( return Column(
onRefresh: () => widget.needRefresh(), children: [
child: _buildGroupPagePostsList(), _buildGroupPageHeader(),
Container(
color: _headerColor,
child: TabBar(
tabs: _tabs.map((e) => e.tab).toList(),
controller: _tabController,
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: _tabs.map((e) => e.widget).toList(),
),
),
],
); );
} }
/// Build group page header /// Build group page header
Widget _buildGroupPageHeader() { Widget _buildGroupPageHeader() {
return Container( return DefaultTextStyle(
color: Colors.black26, style: TextStyle(color: _headerTextColor),
child: Padding( child: Container(
padding: const EdgeInsets.all(8.0), color: _headerColor,
child: Row( child: Padding(
children: <Widget>[ padding: const EdgeInsets.all(8.0),
GroupIcon( child: Row(
group: _group, children: <Widget>[
), GroupIcon(
Expanded( group: _group,
child: Text(
" ${_group.displayName}",
style: TextStyle(fontSize: 20),
), ),
), Expanded(
Column( child: Text(
children: <Widget>[ " ${_group.displayName}",
GroupMembershipWidget( style: TextStyle(fontSize: 20),
group: _group,
onUpdated: () => widget.needRefresh(),
), ),
Container( ),
height: 4, Column(
), crossAxisAlignment: CrossAxisAlignment.start,
GroupFollowingWidget( children: <Widget>[
group: _group, GroupMembershipWidget(
onUpdated: () => widget.needRefresh(), group: _group,
), onUpdated: () => widget.needRefresh(),
Container( ),
height: 2, Container(
), height: 4,
LikeWidget( ),
likeElement: _group, GroupFollowingWidget(
), group: _group,
], onUpdated: () => widget.needRefresh(),
), inactiveColor: Colors.blueAccent,
PopupMenuButton<_MenuItems>( activeColor: Colors.white,
itemBuilder: (c) => [ ),
PopupMenuItem( Container(
child: Text(tr("Group members")), height: 2,
value: _MenuItems.OPEN_MEMBERS, ),
enabled: _group.isAtLeastModerator, LikeWidget(
), inativeColor: Colors.blueAccent,
PopupMenuItem( activeColor: Colors.white,
child: Text(tr("Group settings")), likeElement: _group,
value: _MenuItems.OPEN_SETTINGS, ),
enabled: _group.isAdmin, ],
), ),
], PopupMenuButton<_MenuItems>(
onSelected: _handleMenuSelection, itemBuilder: (c) => [
), PopupMenuItem(
], child: Text(tr("Group members")),
value: _MenuItems.OPEN_MEMBERS,
enabled: _group.isAtLeastModerator,
),
PopupMenuItem(
child: Text(tr("Group settings")),
value: _MenuItems.OPEN_SETTINGS,
enabled: _group.isAdmin,
),
],
onSelected: _handleMenuSelection,
),
],
),
), ),
), ),
); );
@ -125,7 +177,6 @@ class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
return PostsListWidget( return PostsListWidget(
key: _postsKey, key: _postsKey,
topWidgets: <Widget>[ topWidgets: <Widget>[
_buildGroupPageHeader(),
_buildPostCreationArea(), _buildPostCreationArea(),
], ],
getPostsList: () => PostsHelper().getGroupPosts(_group.id), getPostsList: () => PostsHelper().getGroupPosts(_group.id),
@ -149,3 +200,16 @@ class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
} }
} }
} }
class _GroupPageTab {
final Widget widget;
final String label;
const _GroupPageTab({
@required this.widget,
@required this.label,
}) : assert(widget != null),
assert(label != null);
Tab get tab => Tab(text: label);
}

View File

@ -12,10 +12,16 @@ import 'package:flutter/material.dart';
class GroupFollowingWidget extends StatefulWidget { class GroupFollowingWidget extends StatefulWidget {
final Group group; final Group group;
final Function() onUpdated; final Function() onUpdated;
final Color inactiveColor;
final Color activeColor;
const GroupFollowingWidget( const GroupFollowingWidget({
{Key key, @required this.group, @required this.onUpdated}) Key key,
: assert(group != null), @required this.group,
@required this.onUpdated,
this.activeColor,
this.inactiveColor,
}) : assert(group != null),
assert(onUpdated != null), assert(onUpdated != null),
super(key: key); super(key: key);
@ -31,9 +37,17 @@ class _GroupFollowingWidgetState extends SafeState<GroupFollowingWidget> {
if (!_group.isAtLeastMember) return Container(); if (!_group.isAtLeastMember) return Container();
return InkWell( return InkWell(
child: Text( child: RichText(
_group.following ? tr("Following") : tr("Follow"), text: TextSpan(children: [
style: TextStyle(color: Colors.blue), WidgetSpan(
child: Icon(
Icons.notifications,
size: 16.0,
color: _group.following ? widget.activeColor : widget.inactiveColor,
)),
TextSpan(
text: " " + (_group.following ? tr("Following") : tr("Follow"))),
]),
), ),
onTap: () => _toggleFollowing(), onTap: () => _toggleFollowing(),
); );

View File

@ -16,12 +16,16 @@ typedef UpdatedLikingCallBack = Function(int, bool);
class LikeWidget extends StatefulWidget { class LikeWidget extends StatefulWidget {
final LikeElement likeElement; final LikeElement likeElement;
final double buttonIconSize; final double buttonIconSize;
final Color activeColor;
final Color inativeColor;
const LikeWidget({ const LikeWidget(
Key key, {Key key,
@required this.likeElement, @required this.likeElement,
this.buttonIconSize = 15.0, this.buttonIconSize = 15.0,
}) : assert(likeElement != null), this.activeColor,
this.inativeColor})
: assert(likeElement != null),
super(key: key); super(key: key);
@override @override
@ -54,7 +58,9 @@ class _LikeWidgetState extends SafeState<LikeWidget> {
children: <Widget>[ children: <Widget>[
Icon( Icon(
Icons.thumb_up, Icons.thumb_up,
color: elem.userLike ? Colors.blue : null, color: elem.userLike
? (widget.activeColor ?? Colors.blue)
: widget.inativeColor,
size: widget.buttonIconSize, size: widget.buttonIconSize,
), ),
SizedBox( SizedBox(