2022-11-01 08:33:32 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-10-14 15:00:22 +02:00
|
|
|
library flutter_community_chat;
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_community_chat_interface/flutter_community_chat_interface.dart';
|
|
|
|
import 'package:flutter_community_chat_view/flutter_community_chat_view.dart';
|
|
|
|
export 'package:flutter_community_chat_view/flutter_community_chat_view.dart';
|
2022-11-22 11:41:09 +01:00
|
|
|
export 'package:flutter_community_chat_interface/flutter_community_chat_interface.dart';
|
2022-10-14 15:00:22 +02:00
|
|
|
|
2022-12-16 13:10:57 +01:00
|
|
|
class CommunityChat extends StatefulWidget {
|
2022-10-14 15:00:22 +02:00
|
|
|
const CommunityChat({
|
2022-12-16 13:10:57 +01:00
|
|
|
required this.dataProvider,
|
|
|
|
this.translations = const ChatTranslations(),
|
|
|
|
this.options = const ChatOptions(),
|
2022-10-14 15:00:22 +02:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
2022-12-16 13:10:57 +01:00
|
|
|
final ChatDataProvider dataProvider;
|
|
|
|
final ChatOptions options;
|
|
|
|
final ChatTranslations translations;
|
2022-10-14 15:00:22 +02:00
|
|
|
|
|
|
|
@override
|
2022-12-16 13:10:57 +01:00
|
|
|
State<CommunityChat> createState() => _CommunityChatState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CommunityChatState extends State<CommunityChat> {
|
|
|
|
bool _isFetchingUsers = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Future<void> push(Widget widget) => Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => widget),
|
|
|
|
);
|
|
|
|
|
|
|
|
void pop() => Navigator.of(context).pop();
|
|
|
|
|
|
|
|
Future<void> onPressChat(
|
|
|
|
ChatModel chat, {
|
|
|
|
bool popBeforePush = false,
|
|
|
|
}) async {
|
|
|
|
if (popBeforePush) {
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
// push(
|
|
|
|
// ChatDetailScreen(
|
|
|
|
// options: widget.options,
|
|
|
|
// translations: widget.translations,
|
|
|
|
// chat: chat,
|
|
|
|
// chatMessages: widget.dataProvider.messageService.getMessagesStream(),
|
|
|
|
// onUploadImage: widget.dataProvider.messageService.sendImageMessage,
|
|
|
|
// onMessageSubmit: widget.dataProvider.messageService.sendTextMessage,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> onPressStartChat() async {
|
|
|
|
if (!_isFetchingUsers) {
|
|
|
|
_isFetchingUsers = true;
|
|
|
|
await widget.dataProvider.userService.getAllUsers().then(
|
|
|
|
(users) {
|
|
|
|
_isFetchingUsers = false;
|
|
|
|
push(
|
|
|
|
NewChatScreen(
|
|
|
|
options: widget.options,
|
|
|
|
translations: widget.translations,
|
|
|
|
onPressCreateChat: (user) => onPressChat(
|
|
|
|
PersonalChatModel(user: user),
|
|
|
|
popBeforePush: true,
|
|
|
|
),
|
|
|
|
users: users,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ChatScreen(
|
|
|
|
chats: widget.dataProvider.chatService.getChatsStream(),
|
|
|
|
onPressStartChat: () => onPressStartChat(),
|
|
|
|
onPressChat: (chat) => onPressChat(chat),
|
|
|
|
onDeleteChat: (PersonalChatModel chat) =>
|
|
|
|
widget.dataProvider.chatService.deleteChat(chat),
|
|
|
|
options: widget.options,
|
|
|
|
translations: widget.translations,
|
|
|
|
);
|
|
|
|
}
|
2022-10-14 15:00:22 +02:00
|
|
|
}
|