feat: pop before pushing chat screen + fix bug showing wrong chat

This commit is contained in:
Stein Milder 2022-11-10 13:40:31 +01:00
parent 79d3de0b35
commit f800216a9b
7 changed files with 52 additions and 35 deletions

View file

@ -39,6 +39,8 @@ class _CommunityChatState extends State<CommunityChat> {
MaterialPageRoute(builder: (context) => widget), MaterialPageRoute(builder: (context) => widget),
); );
void _pop(BuildContext context) => Navigator.of(context).pop();
Future<void> _onPressStartChat(BuildContext context) async { Future<void> _onPressStartChat(BuildContext context) async {
if (!_isFetchingUsers) { if (!_isFetchingUsers) {
_isFetchingUsers = true; _isFetchingUsers = true;
@ -50,12 +52,11 @@ class _CommunityChatState extends State<CommunityChat> {
NewChatScreen( NewChatScreen(
options: widget.options, options: widget.options,
translations: widget.translations, translations: widget.translations,
onPressCreateChat: (user) { onPressCreateChat: (user) => _onPressChat(
_onPressChat( context,
context, PersonalChatModel(user: user),
PersonalChatModel(user: user), popBeforePush: true,
); ),
},
users: users, users: users,
), ),
); );
@ -64,22 +65,29 @@ class _CommunityChatState extends State<CommunityChat> {
} }
} }
Future<void> _onPressChat(BuildContext context, ChatModel chat) async { Future<void> _onPressChat(
widget.dataProvider.setChat(chat); BuildContext context,
_push( ChatModel chat, {
context, bool popBeforePush = false,
ChatDetailScreen( }) =>
options: widget.options, widget.dataProvider.setChat(chat).then((_) {
translations: widget.translations, if (popBeforePush) {
chat: chat, _pop(context);
chatMessages: widget.dataProvider.getMessagesStream(), }
onPressSelectImage: (ChatModel chat) => _push(
_onPressSelectImage(context, chat), context,
onMessageSubmit: (ChatModel chat, String content) => ChatDetailScreen(
widget.dataProvider.sendTextMessage(content), options: widget.options,
), translations: widget.translations,
); chat: chat,
} chatMessages: widget.dataProvider.getMessagesStream(),
onPressSelectImage: (ChatModel chat) =>
_onPressSelectImage(context, chat),
onMessageSubmit: (ChatModel chat, String content) =>
widget.dataProvider.sendTextMessage(content),
),
);
});
void _beforeUploadingImage() => ScaffoldMessenger.of(context).showSnackBar( void _beforeUploadingImage() => ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(

View file

@ -179,7 +179,7 @@ packages:
description: description:
path: "packages/flutter_community_chat_interface" path: "packages/flutter_community_chat_interface"
ref: HEAD ref: HEAD
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
url: "https://github.com/Iconica-Development/flutter_community_chat.git" url: "https://github.com/Iconica-Development/flutter_community_chat.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@ -188,7 +188,7 @@ packages:
description: description:
path: "packages/flutter_community_chat_view" path: "packages/flutter_community_chat_view"
ref: HEAD ref: HEAD
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
url: "https://github.com/Iconica-Development/flutter_community_chat.git" url: "https://github.com/Iconica-Development/flutter_community_chat.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@ -235,7 +235,7 @@ packages:
name: glob name: glob
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
http: http:
dependency: transitive dependency: transitive
description: description:

View file

@ -33,9 +33,16 @@ class FirebaseMessageService {
ChatModel? _chat; ChatModel? _chat;
Future<void> setChat(ChatModel chat) async { Future<void> setChat(ChatModel chat) async {
if (chat is PersonalChatModel) { if (chat.id == null && chat is PersonalChatModel) {
_chat = await chatService.getChatByUser(chat.user) ?? chat; var chatWithUser = await chatService.getChatByUser(chat.user);
if (chatWithUser != null) {
_chat = chatWithUser;
return;
}
} }
_chat = chat;
} }
Future<void> _beforeSendMessage() async { Future<void> _beforeSendMessage() async {
@ -116,7 +123,9 @@ class FirebaseMessageService {
_subscription = _startListeningForMessages(_chat!); _subscription = _startListeningForMessages(_chat!);
} }
}, },
onCancel: () => _subscription?.cancel(), onCancel: () {
_subscription?.cancel();
},
); );
return _controller.stream; return _controller.stream;

View file

@ -228,7 +228,7 @@ packages:
description: description:
path: "packages/flutter_community_chat_interface" path: "packages/flutter_community_chat_interface"
ref: HEAD ref: HEAD
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
url: "https://github.com/Iconica-Development/flutter_community_chat.git" url: "https://github.com/Iconica-Development/flutter_community_chat.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@ -264,7 +264,7 @@ packages:
name: glob name: glob
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
http: http:
dependency: transitive dependency: transitive
description: description:

View file

@ -140,7 +140,7 @@ packages:
name: glob name: glob
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
lints: lints:
dependency: transitive dependency: transitive
description: description:

View file

@ -186,7 +186,7 @@ packages:
description: description:
path: "packages/flutter_community_chat_interface" path: "packages/flutter_community_chat_interface"
ref: HEAD ref: HEAD
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
url: "https://github.com/Iconica-Development/flutter_community_chat.git" url: "https://github.com/Iconica-Development/flutter_community_chat.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@ -224,7 +224,7 @@ packages:
name: glob name: glob
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
http: http:
dependency: transitive dependency: transitive
description: description:

View file

@ -179,7 +179,7 @@ packages:
description: description:
path: "packages/flutter_community_chat_interface" path: "packages/flutter_community_chat_interface"
ref: HEAD ref: HEAD
resolved-ref: f3cae1bf88f7f55c485aeab86a95cdff776373d4 resolved-ref: "82b9b0be80eb0d0c36b72432c7517a6d04cecb20"
url: "https://github.com/Iconica-Development/flutter_community_chat.git" url: "https://github.com/Iconica-Development/flutter_community_chat.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
@ -210,7 +210,7 @@ packages:
name: glob name: glob
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
http: http:
dependency: transitive dependency: transitive
description: description: