feature: added custom dialog and the option to make a chat not deletable

This commit is contained in:
mike doornenbal 2023-11-29 10:57:57 +01:00 committed by Freek van de Ven
parent d0933ac252
commit d90185a480
13 changed files with 120 additions and 61 deletions

View file

@ -1,3 +1,7 @@
## 0.5.0 - November 29 2023
- Added the option to add your own dialog on chat delete and addded the option to make the chat not deletable
## 0.4.2 - November 24 2023
- Fix groupchats seen as personal chat when there are unread messages

View file

@ -4,31 +4,29 @@
name: flutter_community_chat
description: A new Flutter package project.
version: 0.4.2
version: 0.5.0
publish_to: none
environment:
sdk: '>=3.1.0 <4.0.0'
sdk: ">=3.1.0 <4.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
flutter_community_chat_view:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_view
ref: 0.4.2
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_view
ref: 0.5.0
flutter_community_chat_interface:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_interface
ref: 0.4.2
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_interface
ref: 0.5.0
dev_dependencies:
flutter_lints: ^2.0.0
flutter:

View file

@ -10,6 +10,7 @@ import 'package:flutter_community_chat_firebase/dto/firebase_message_document.da
class FirebaseChatDocument {
const FirebaseChatDocument({
required this.personal,
required this.canBeDeleted,
this.users = const [],
this.id,
this.lastUsed,
@ -22,6 +23,7 @@ class FirebaseChatDocument {
final String? title;
final String? imageUrl;
final bool personal;
final bool canBeDeleted;
final Timestamp? lastUsed;
final List<String> users;
final FirebaseMessageDocument? lastMessage;
@ -30,6 +32,7 @@ class FirebaseChatDocument {
: title = json['title'],
imageUrl = json['image_url'],
personal = json['personal'],
canBeDeleted = json['can_be_deleted'] ?? true,
lastUsed = json['last_used'],
users = json['users'] != null ? List<String>.from(json['users']) : [],
lastMessage = json['last_message'] == null
@ -44,6 +47,7 @@ class FirebaseChatDocument {
'image_url': imageUrl,
'personal': personal,
'last_used': lastUsed,
'can_be_deleted': canBeDeleted,
'users': users,
};
}

View file

@ -111,6 +111,7 @@ class FirebaseChatService implements ChatService {
user: otherUser,
lastMessage: messages.isNotEmpty ? messages.last : null,
messages: messages,
canBeDeleted: chatData.canBeDeleted,
lastUsed: chatData.lastUsed == null
? null
: DateTime.fromMillisecondsSinceEpoch(
@ -134,6 +135,7 @@ class FirebaseChatService implements ChatService {
lastMessage: messages.isNotEmpty ? messages.last : null,
messages: messages,
users: users,
canBeDeleted: chatData.canBeDeleted,
lastUsed: chatData.lastUsed == null
? null
: DateTime.fromMillisecondsSinceEpoch(
@ -297,6 +299,7 @@ class FirebaseChatService implements ChatService {
return PersonalChatModel(
id: chatId,
user: user!,
canBeDeleted: chatCollection.data()?['can_be_deleted'] ?? true,
);
} else {
var groupChatCollection = await _db
@ -321,6 +324,7 @@ class FirebaseChatService implements ChatService {
title: chat?.title ?? '',
imageUrl: chat?.imageUrl ?? '',
users: users,
canBeDeleted: chat?.canBeDeleted ?? true,
);
}
}
@ -391,6 +395,7 @@ class FirebaseChatService implements ChatService {
.add(
FirebaseChatDocument(
personal: true,
canBeDeleted: chat.canBeDeleted,
users: userIds,
lastUsed: Timestamp.now(),
),
@ -426,6 +431,7 @@ class FirebaseChatService implements ChatService {
.add(
FirebaseChatDocument(
personal: false,
canBeDeleted: chat.canBeDeleted,
users: userIds,
lastUsed: Timestamp.now(),
),

View file

@ -4,11 +4,11 @@
name: flutter_community_chat_firebase
description: A new Flutter package project.
version: 0.4.2
version: 0.5.0
publish_to: none
environment:
sdk: '>=3.1.0 <4.0.0'
sdk: ">=3.1.0 <4.0.0"
flutter: ">=1.17.0"
dependencies:
@ -19,14 +19,13 @@ dependencies:
firebase_storage: ^11.0.5
firebase_auth: ^4.1.2
uuid: ^4.0.0
flutter_community_chat_interface:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_interface
ref: 0.4.2
flutter_community_chat_interface:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_interface
ref: 0.5.0
dev_dependencies:
flutter_lints: ^2.0.0
flutter:

View file

@ -11,6 +11,7 @@ abstract class ChatModel {
this.unreadMessages,
this.lastUsed,
this.lastMessage,
this.canBeDeleted = true,
});
String? id;
@ -18,4 +19,5 @@ abstract class ChatModel {
int? unreadMessages;
DateTime? lastUsed;
ChatMessageModel? lastMessage;
bool canBeDeleted;
}

View file

@ -14,6 +14,7 @@ class GroupChatModel extends ChatModel {
super.lastUsed,
super.lastMessage,
super.unreadMessages,
super.canBeDeleted,
});
final String title;
@ -29,6 +30,7 @@ class GroupChatModel extends ChatModel {
String? title,
String? imageUrl,
List<ChatUserModel>? users,
bool? canBeDeleted,
}) =>
GroupChatModel(
id: id ?? this.id,
@ -39,5 +41,6 @@ class GroupChatModel extends ChatModel {
title: title ?? this.title,
imageUrl: imageUrl ?? this.imageUrl,
users: users ?? this.users,
canBeDeleted: canBeDeleted ?? this.canBeDeleted,
);
}

View file

@ -12,6 +12,7 @@ class PersonalChatModel extends ChatModel {
super.unreadMessages,
super.lastUsed,
super.lastMessage,
super.canBeDeleted,
});
final ChatUserModel user;
@ -23,6 +24,7 @@ class PersonalChatModel extends ChatModel {
DateTime? lastUsed,
ChatMessageModel? lastMessage,
ChatUserModel? user,
bool? canBeDeleted,
}) =>
PersonalChatModel(
id: id ?? this.id,
@ -31,5 +33,6 @@ class PersonalChatModel extends ChatModel {
lastUsed: lastUsed ?? this.lastUsed,
lastMessage: lastMessage ?? this.lastMessage,
user: user ?? this.user,
canBeDeleted: canBeDeleted ?? this.canBeDeleted,
);
}

View file

@ -4,7 +4,7 @@
name: flutter_community_chat_interface
description: A new Flutter package project.
version: 0.4.2
version: 0.5.0
publish_to: none
environment:

View file

@ -5,20 +5,20 @@
name: flutter_community_chat_view_example
description: A standard flutter package.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.1.0 <4.0.0'
sdk: ">=3.1.0 <4.0.0"
dependencies:
flutter:
sdk: flutter
flutter_community_chat_view:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_view
ref: 0.4.2
flutter_community_chat_view:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_view
ref: 0.5.0
dev_dependencies:
flutter_test:

View file

@ -21,6 +21,7 @@ class ChatTranslations {
this.deleteChatModalConfirm = 'Delete',
this.noUsersFound = 'No users found',
this.anonymousUser = 'Anonymous user',
this.chatCantBeDeleted = 'This chat can\'t be deleted',
});
final String chatsTitle;
@ -38,6 +39,7 @@ class ChatTranslations {
final String deleteChatModalCancel;
final String deleteChatModalConfirm;
final String noUsersFound;
final String chatCantBeDeleted;
/// Shown when the user has no name
final String anonymousUser;

View file

@ -13,6 +13,7 @@ class ChatScreen extends StatefulWidget {
required this.onPressStartChat,
required this.onPressChat,
required this.onDeleteChat,
this.deleteChatDialog,
this.unreadChats,
this.translations = const ChatTranslations(),
super.key,
@ -26,6 +27,8 @@ class ChatScreen extends StatefulWidget {
final void Function(ChatModel chat) onDeleteChat;
final void Function(ChatModel chat) onPressChat;
/// Method to optionally change the bottomsheetdialog
final Future<bool?> Function(BuildContext, ChatModel)? deleteChatDialog;
@override
State<ChatScreen> createState() => _ChatScreenState();
}
@ -74,33 +77,69 @@ class _ChatScreenState extends State<ChatScreen> {
for (ChatModel chat in snapshot.data ?? []) ...[
Builder(
builder: (context) => Dismissible(
confirmDismiss: (_) => showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(
translations.deleteChatModalTitle,
),
content: Text(
translations.deleteChatModalDescription,
),
actions: [
TextButton(
child: Text(
translations.deleteChatModalCancel,
),
onPressed: () =>
Navigator.of(context).pop(false),
),
ElevatedButton(
onPressed: () =>
Navigator.of(context).pop(true),
child: Text(
translations.deleteChatModalConfirm,
confirmDismiss: (_) =>
widget.deleteChatDialog?.call(context, chat) ??
showModalBottomSheet(
context: context,
builder: (BuildContext context) => Container(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
chat.canBeDeleted
? translations
.deleteChatModalTitle
: translations.chatCantBeDeleted,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
if (chat.canBeDeleted)
Text(
translations
.deleteChatModalDescription,
style:
const TextStyle(fontSize: 16),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
TextButton(
child: Text(
translations
.deleteChatModalCancel,
style: const TextStyle(
fontSize: 16,
),
),
onPressed: () =>
Navigator.of(context)
.pop(false),
),
if (chat.canBeDeleted)
ElevatedButton(
onPressed: () =>
Navigator.of(context)
.pop(true),
child: Text(
translations
.deleteChatModalConfirm,
style: const TextStyle(
fontSize: 16,
),
),
),
],
),
],
),
),
],
),
),
),
onDismissed: (_) => widget.onDeleteChat(chat),
background: Container(
color: Colors.red,

View file

@ -4,23 +4,23 @@
name: flutter_community_chat_view
description: A standard flutter package.
version: 0.4.2
version: 0.5.0
publish_to: none
environment:
sdk: '>=3.1.0 <4.0.0'
sdk: ">=3.1.0 <4.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
intl: any
flutter_community_chat_interface:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_interface
ref: 0.4.2
flutter_community_chat_interface:
git:
url: https://github.com/Iconica-Development/flutter_community_chat
path: packages/flutter_community_chat_interface
ref: 0.5.0
cached_network_image: ^3.2.2
flutter_image_picker:
git:
@ -33,4 +33,3 @@ dev_dependencies:
flutter_lints: ^2.0.0
flutter: