Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
OT-450 Removing a user from Groupchat (is broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
florianhaar authored and Boehrsi committed Oct 25, 2019
1 parent 388deff commit 691f95d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 103 deletions.
213 changes: 111 additions & 102 deletions lib/src/chat/chat_profile_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ox_coi/src/adaptiveWidgets/adaptive_ink_well.dart';
import 'package:ox_coi/src/chat/chat_change_bloc.dart';
import 'package:ox_coi/src/chat/chat_change_event_state.dart';
import 'package:ox_coi/src/chat/chat_profile_group_contact_item.dart';
Expand All @@ -53,17 +54,15 @@ import 'package:ox_coi/src/navigation/navigatable.dart';
import 'package:ox_coi/src/navigation/navigation.dart';
import 'package:ox_coi/src/ui/color.dart';
import 'package:ox_coi/src/ui/dimensions.dart';
import 'package:ox_coi/src/utils/keyMapping.dart';
import 'package:ox_coi/src/widgets/profile_body.dart';
import 'package:ox_coi/src/widgets/profile_header.dart';
import 'package:ox_coi/src/utils/keyMapping.dart';

import 'chat_add_group_participants.dart';
import 'chat_bloc.dart';
import 'chat_event_state.dart';
import 'edit_name.dart';

import 'package:ox_coi/src/adaptiveWidgets/adaptive_ink_well.dart';

class ChatProfileGroup extends StatefulWidget {
final int chatId;
final Color chatColor;
Expand All @@ -78,6 +77,7 @@ class ChatProfileGroup extends StatefulWidget {
class _ChatProfileGroupState extends State<ChatProfileGroup> {
ContactListBloc _contactListBloc = ContactListBloc();
ChatChangeBloc _chatChangeBloc = ChatChangeBloc();

// Ignoring false positive https://github.com/felangel/bloc/issues/587
// ignore: close_sinks
ChatBloc _chatBloc;
Expand All @@ -101,128 +101,137 @@ class _ChatProfileGroupState extends State<ChatProfileGroup> {
Widget build(BuildContext context) {
_chatBloc = BlocProvider.of<ChatBloc>(context);
return BlocBuilder(
bloc: _contactListBloc,
builder: (context, state) {
if (state is ContactListStateSuccess) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
BlocBuilder(
bloc: _chatBloc,
builder: (context, state) {
if (state is ChatStateSuccess) {
_chatName = state.name;
return ProfileData(
color: widget.chatColor,
text: state.name,
textStyle: Theme.of(context).textTheme.title,
iconData: state.isVerified ? Icons.verified_user : null,
imageActionCallback: _editPhotoCallback,
child: Column(
children: <Widget>[
Align(
alignment: Alignment.center,
child: ProfileAvatar(
imagePath: state.avatarPath,
),
),
Padding(
padding: EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ProfileHeaderText(),
IconButton(
icon: Icon(
Icons.edit,
key: Key(keyChatProfileGroupEditIcon),
color: accent,
),
onPressed: _goToEditName)
],
),
),
],
));
} else {
return Container();
}
},
),
Padding(
padding: EdgeInsets.only(left: 20.0),
child: ProfileData(
text: L10n.getFormatted(L.participantXP, [state.contactIds.length], count: state.contactIds.length),
child: ProfileMemberHeaderText(),
)),
Divider(),
AdaptiveInkWell(
onTap: () => _navigation.push(
context, MaterialPageRoute(builder: (context) => ChatAddGroupParticipants(chatId: widget.chatId, contactIds: state.contactIds))),
child: Container(
padding: const EdgeInsets.only(left: 16.0, bottom: 12.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
bloc: _chatBloc,
builder: (context, chatState) {
if (chatState is ChatStateSuccess) {
_chatName = chatState.name;
return BlocBuilder(
bloc: _contactListBloc,
builder: (context, state) {
if (state is ContactListStateSuccess) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
radius: listAvatarRadius,
backgroundColor: accent,
foregroundColor: onAccent,
child: Icon(Icons.group_add),
key: Key(keyChatProfileGroupAddParticipant),
),
buildProfileImageAndTitle(chatState),
Padding(
padding: EdgeInsets.only(left: 4.0),
child: Text(
L10n.get(L.participantAdd),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subhead.apply(color: accent),
padding: EdgeInsets.only(left: 20.0),
child: ProfileData(
text: L10n.getFormatted(L.participantXP, [state.contactIds.length], count: state.contactIds.length),
child: ProfileMemberHeaderText(),
)),
Divider(),
Visibility(
visible: !chatState.isRemoved,
child: AdaptiveInkWell(
onTap: () => _navigation.push(context,
MaterialPageRoute(builder: (context) => ChatAddGroupParticipants(chatId: widget.chatId, contactIds: state.contactIds))),
child: Container(
padding: const EdgeInsets.only(left: 16.0, bottom: 12.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
CircleAvatar(
radius: listAvatarRadius,
backgroundColor: accent,
foregroundColor: onAccent,
child: Icon(Icons.group_add),
key: Key(keyChatProfileGroupAddParticipant),
),
Padding(
padding: EdgeInsets.only(left: 4.0),
child: Text(
L10n.get(L.participantAdd),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subhead.apply(color: accent),
),
)
],
),
),
),
)
),
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: _buildGroupMemberList(state, chatState.isRemoved),
),
Divider(
height: dividerHeight,
),
ProfileAction(
iconData: Icons.delete,
key: Key(keyChatProfileGroupDelete),
text: L10n.get(L.groupLeave),
onTap: () => showActionDialog(context, ProfileActionType.leave, _leaveGroup),
color: error,
),
],
),
),
),
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: _buildGroupMemberList(state),
),
Divider(
height: dividerHeight,
),
ProfileAction(
iconData: Icons.delete,
key: Key(keyChatProfileGroupDelete),
text: L10n.get(L.groupLeave),
onTap: () => showActionDialog(context, ProfileActionType.leave, _leaveGroup),
color: Colors.red,
),
],
);
);
} else {
return Container();
}
});
} else {
return Container();
}
},
);
}

ProfileData buildProfileImageAndTitle(ChatStateSuccess state) {
return ProfileData(
color: widget.chatColor,
text: state.name,
textStyle: Theme.of(context).textTheme.title,
iconData: state.isVerified ? Icons.verified_user : null,
imageActionCallback: state.isRemoved ? null : _editPhotoCallback,
child: Column(
children: <Widget>[
Align(
alignment: Alignment.center,
child: ProfileAvatar(
imagePath: state.avatarPath,
),
),
Padding(
padding: EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ProfileHeaderText(),
Visibility(
visible: !state.isRemoved,
child: IconButton(
icon: Icon(
Icons.edit,
key: Key(keyChatProfileGroupEditIcon),
color: accent,
),
onPressed: _goToEditName,
)),
],
),
),
],
));
}

_editPhotoCallback(String avatarPath) {
_chatChangeBloc.add(SetImagePath(chatId: widget.chatId, newPath: avatarPath));
}

ListView _buildGroupMemberList(ContactListStateSuccess state) {
ListView _buildGroupMemberList(ContactListStateSuccess state, bool isRemoved) {
return ListView.separated(
separatorBuilder: (context, index) => Divider(
height: dividerHeight,
color: onBackground.withOpacity(barely),
),
height: dividerHeight,
color: onBackground.withOpacity(barely),
),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: state.contactIds.length,
itemBuilder: (BuildContext context, int index) {
var contactId = state.contactIds[index];
var key = "$contactId-${state.contactLastUpdateValues[index]}";
return ChatProfileGroupContactItem(chatId: widget.chatId, contactId: contactId, showMoreButton: true, key: key);
return ChatProfileGroupContactItem(chatId: widget.chatId, contactId: contactId, showMoreButton: !isRemoved, key: key);
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/chat/chat_profile_group_contact_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _ChatProfileGroupContactItemState extends State<ChatProfileGroupContactIte

@override
Widget build(BuildContext context) {
return getAvatarItemBlocBuilder(bloc: _contactBloc, onContactTapped: goToProfile, moreButton: getMoreButton());
return getAvatarItemBlocBuilder(bloc: _contactBloc, onContactTapped: goToProfile, moreButton: widget.showMoreButton ? getMoreButton() : null);
}

goToProfile(String title, String subtitle) {
Expand Down

0 comments on commit 691f95d

Please sign in to comment.