add mute and delete channel

This commit is contained in:
Salvatore Giordano
2020-07-20 15:33:21 +02:00
parent 2541d5e474
commit d99afe7e63
4 changed files with 154 additions and 22 deletions
+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 11C14.2091 11 16 9.20914 16 7C16 4.79086 14.2091 3 12 3C9.79086 3 8 4.79086 8 7C8 9.20914 9.79086 11 12 11ZM12 9C13.1046 9 14 8.10457 14 7C14 5.89543 13.1046 5 12 5C10.8954 5 10 5.89543 10 7C10 8.10457 10.8954 9 12 9Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 12C6.4686 12 4 15.6324 4 18C4 18.5523 3.55228 19 3 19C2.44771 19 2 18.5523 2 18C2 14.3676 5.5314 10 12 10C13.9955 10 15.7139 10.4121 17.1402 11.0991C17.6378 11.3387 17.8469 11.9363 17.6072 12.4339C17.3676 12.9315 16.7699 13.1406 16.2724 12.9009C15.1351 12.3532 13.716 12 12 12Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M22 16V18H16V16H22Z" fill="black"/>
</svg>

After

Width:  |  Height:  |  Size: 822 B

+68 -17
View File
@@ -1,6 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:line_awesome_icons/line_awesome_icons.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter/src/utils.dart';
import 'channel_info.dart';
import 'channel_name.dart';
@@ -70,26 +73,74 @@ class ChannelBottomSheet extends StatelessWidget {
stream: channel.isMutedStream,
initialData: channel.isMuted,
builder: (context, snapshot) {
return SwitchListTile(
onChanged: (bool muted) async {
if (muted) {
await channel.mute();
} else {
await channel.unmute();
}
},
value: snapshot.data,
title: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 22.0),
child: Icon(LineAwesomeIcons.volume_off),
),
Text('Mute'),
],
return ListTile(
leading: Icon(
LineAwesomeIcons.volume_off,
size: 22,
color: StreamChatTheme.of(context).primaryIconTheme.color,
),
title: Text('Mute ${channel.isGroup ? 'group' : 'user'}'),
trailing: Switch(
onChanged: (bool muted) async {
if (muted) {
await channel.mute();
} else {
await channel.unmute();
}
},
value: snapshot.data,
),
);
}),
Divider(),
if (channel.isGroup && !channel.isDistinct)
ListTile(
leading: SvgPicture.asset(
'assets/icon_user_minus.svg',
package: 'stream_chat_flutter',
width: 22,
),
title: Text('Leave Group'),
onTap: () async {
final confirm = await showConfirmationDialog(
context,
'Do you want to leave the group?',
);
if (confirm == true) {
await channel.removeMembers(channel.state.members
.where((element) =>
element.userId == StreamChat.of(context).user.id)
.toList());
Navigator.pop(context);
}
},
),
if (!channel.isGroup && !channel.isDistinct)
ListTile(
leading: Icon(
Icons.delete_outline,
color: Color(0xFFFF3742),
),
title: Text(
'Delete chat',
style: TextStyle(
color: Color(0xFFFF3742),
),
),
onTap: () async {
final confirm = await showConfirmationDialog(
context,
'Do you want to delete the chat?',
);
if (confirm == true) {
await channel.removeMembers(channel.state.members
.where((element) =>
element.userId == StreamChat.of(context).user.id)
.toList());
Navigator.pop(context);
}
},
),
],
),
),
+51 -5
View File
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:line_awesome_icons/line_awesome_icons.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter/src/channels_bloc.dart';
import 'package:stream_chat_flutter/src/utils.dart';
import '../stream_chat_flutter.dart';
import 'channel_bottom_sheet.dart';
@@ -307,12 +310,55 @@ class _ChannelListViewState extends State<ChannelListView>
),
IconSlideAction(
color: Color(0xffEBEBEB),
icon: Icons.notifications_none,
),
IconSlideAction(
color: Color(0xffEBEBEB),
icon: Icons.delete,
icon: LineAwesomeIcons.volume_off,
onTap: () async {
if (!channel.isMuted) {
await channel.mute();
} else {
await channel.unmute();
}
},
),
if (channel.isGroup && !channel.isDistinct)
IconSlideAction(
color: Color(0xffEBEBEB),
iconWidget: SvgPicture.asset(
'assets/icon_user_minus.svg',
package: 'stream_chat_flutter',
width: 22,
),
onTap: () async {
final confirm = await showConfirmationDialog(
context,
'Do you want to leave the group?',
);
if (confirm == true) {
await channel.removeMembers(channel.state.members
.where((element) =>
element.userId ==
StreamChat.of(context).user.id)
.toList());
}
},
),
if (!channel.isGroup && !channel.isDistinct)
IconSlideAction(
color: Color(0xffEBEBEB),
icon: Icons.delete_outline,
onTap: () async {
final confirm = await showConfirmationDialog(
context,
'Do you want to delete the chat?',
);
if (confirm == true) {
await channel.removeMembers(channel.state.members
.where((element) =>
element.userId ==
StreamChat.of(context).user.id)
.toList());
}
},
),
],
child: Container(
color: StreamChatTheme.of(context).backgroundColor,
+30
View File
@@ -12,3 +12,33 @@ Future<void> launchURL(BuildContext context, String url) async {
);
}
}
Future<bool> showConfirmationDialog(
BuildContext context,
String question,
) {
return showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
title: Text(question),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () => Navigator.pop(
context,
true,
),
),
FlatButton(
child: Text('Cancel'),
onPressed: () => Navigator.pop(
context,
false,
),
),
],
);
},
);
}