mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 02:43:50 +02:00
feat: pop before pushing chat screen + fix bug showing wrong chat
This commit is contained in:
parent
79d3de0b35
commit
f800216a9b
7 changed files with 52 additions and 35 deletions
|
@ -39,6 +39,8 @@ class _CommunityChatState extends State<CommunityChat> {
|
|||
MaterialPageRoute(builder: (context) => widget),
|
||||
);
|
||||
|
||||
void _pop(BuildContext context) => Navigator.of(context).pop();
|
||||
|
||||
Future<void> _onPressStartChat(BuildContext context) async {
|
||||
if (!_isFetchingUsers) {
|
||||
_isFetchingUsers = true;
|
||||
|
@ -50,12 +52,11 @@ class _CommunityChatState extends State<CommunityChat> {
|
|||
NewChatScreen(
|
||||
options: widget.options,
|
||||
translations: widget.translations,
|
||||
onPressCreateChat: (user) {
|
||||
_onPressChat(
|
||||
onPressCreateChat: (user) => _onPressChat(
|
||||
context,
|
||||
PersonalChatModel(user: user),
|
||||
);
|
||||
},
|
||||
popBeforePush: true,
|
||||
),
|
||||
users: users,
|
||||
),
|
||||
);
|
||||
|
@ -64,8 +65,15 @@ class _CommunityChatState extends State<CommunityChat> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _onPressChat(BuildContext context, ChatModel chat) async {
|
||||
widget.dataProvider.setChat(chat);
|
||||
Future<void> _onPressChat(
|
||||
BuildContext context,
|
||||
ChatModel chat, {
|
||||
bool popBeforePush = false,
|
||||
}) =>
|
||||
widget.dataProvider.setChat(chat).then((_) {
|
||||
if (popBeforePush) {
|
||||
_pop(context);
|
||||
}
|
||||
_push(
|
||||
context,
|
||||
ChatDetailScreen(
|
||||
|
@ -79,7 +87,7 @@ class _CommunityChatState extends State<CommunityChat> {
|
|||
widget.dataProvider.sendTextMessage(content),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
void _beforeUploadingImage() => ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
|
|
|
@ -179,7 +179,7 @@ packages:
|
|||
description:
|
||||
path: "packages/flutter_community_chat_interface"
|
||||
ref: HEAD
|
||||
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4
|
||||
resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
|
||||
url: "https://github.com/Iconica-Development/flutter_community_chat.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
@ -188,7 +188,7 @@ packages:
|
|||
description:
|
||||
path: "packages/flutter_community_chat_view"
|
||||
ref: HEAD
|
||||
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4
|
||||
resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
|
||||
url: "https://github.com/Iconica-Development/flutter_community_chat.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
@ -235,7 +235,7 @@ packages:
|
|||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -33,11 +33,18 @@ class FirebaseMessageService {
|
|||
ChatModel? _chat;
|
||||
|
||||
Future<void> setChat(ChatModel chat) async {
|
||||
if (chat is PersonalChatModel) {
|
||||
_chat = await chatService.getChatByUser(chat.user) ?? chat;
|
||||
if (chat.id == null && chat is PersonalChatModel) {
|
||||
var chatWithUser = await chatService.getChatByUser(chat.user);
|
||||
|
||||
if (chatWithUser != null) {
|
||||
_chat = chatWithUser;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_chat = chat;
|
||||
}
|
||||
|
||||
Future<void> _beforeSendMessage() async {
|
||||
if (_chat != null) {
|
||||
_chat = await createChatIfNotExists(_chat!);
|
||||
|
@ -116,7 +123,9 @@ class FirebaseMessageService {
|
|||
_subscription = _startListeningForMessages(_chat!);
|
||||
}
|
||||
},
|
||||
onCancel: () => _subscription?.cancel(),
|
||||
onCancel: () {
|
||||
_subscription?.cancel();
|
||||
},
|
||||
);
|
||||
|
||||
return _controller.stream;
|
||||
|
|
|
@ -228,7 +228,7 @@ packages:
|
|||
description:
|
||||
path: "packages/flutter_community_chat_interface"
|
||||
ref: HEAD
|
||||
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4
|
||||
resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
|
||||
url: "https://github.com/Iconica-Development/flutter_community_chat.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
@ -264,7 +264,7 @@ packages:
|
|||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -140,7 +140,7 @@ packages:
|
|||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -186,7 +186,7 @@ packages:
|
|||
description:
|
||||
path: "packages/flutter_community_chat_interface"
|
||||
ref: HEAD
|
||||
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4
|
||||
resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
|
||||
url: "https://github.com/Iconica-Development/flutter_community_chat.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
@ -224,7 +224,7 @@ packages:
|
|||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -179,7 +179,7 @@ packages:
|
|||
description:
|
||||
path: "packages/flutter_community_chat_interface"
|
||||
ref: HEAD
|
||||
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4
|
||||
resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
|
||||
url: "https://github.com/Iconica-Development/flutter_community_chat.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
@ -210,7 +210,7 @@ packages:
|
|||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
Loading…
Reference in a new issue