mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 02:43:50 +02:00
fix: add missing screen route
This commit is contained in:
parent
169818e981
commit
8e51a4d3fd
5 changed files with 94 additions and 33 deletions
|
@ -163,12 +163,13 @@ List<GoRoute> getChatStoryRoutes(
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: ChatUserStoryRoutes.newGroupChatScreen,
|
path: ChatUserStoryRoutes.newGroupChatScreen,
|
||||||
pageBuilder: (context, state) {
|
pageBuilder: (context, state) {
|
||||||
var newChatScreen = NewGroupChatScreen(
|
var newGroupChatScreen = NewGroupChatScreen(
|
||||||
options: configuration.chatOptionsBuilder(context),
|
options: configuration.chatOptionsBuilder(context),
|
||||||
translations: configuration.translations,
|
translations: configuration.translations,
|
||||||
service: configuration.chatService,
|
service: configuration.chatService,
|
||||||
onPressGroupChatOverview: (user) async => context.push(
|
onPressGroupChatOverview: (users) async => context.push(
|
||||||
ChatUserStoryRoutes.newGroupChatOverviewScreen,
|
ChatUserStoryRoutes.newGroupChatOverviewScreen,
|
||||||
|
extra: users,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return buildScreenWithoutTransition(
|
return buildScreenWithoutTransition(
|
||||||
|
@ -176,10 +177,51 @@ List<GoRoute> getChatStoryRoutes(
|
||||||
state: state,
|
state: state,
|
||||||
child: configuration.chatPageBuilder?.call(
|
child: configuration.chatPageBuilder?.call(
|
||||||
context,
|
context,
|
||||||
newChatScreen,
|
newGroupChatScreen,
|
||||||
) ??
|
) ??
|
||||||
Scaffold(
|
Scaffold(
|
||||||
body: newChatScreen,
|
body: newGroupChatScreen,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: ChatUserStoryRoutes.newGroupChatOverviewScreen,
|
||||||
|
pageBuilder: (context, state) {
|
||||||
|
var users = state.extra! as List<ChatUserModel>;
|
||||||
|
var newGroupChatOverviewScreen = NewGroupChatOverviewScreen(
|
||||||
|
options: configuration.chatOptionsBuilder(context),
|
||||||
|
translations: configuration.translations,
|
||||||
|
service: configuration.chatService,
|
||||||
|
users: users,
|
||||||
|
onPressCompleteGroupChatCreation: (users, groupChatName) async {
|
||||||
|
configuration.onPressCompleteGroupChatCreation
|
||||||
|
?.call(users, groupChatName);
|
||||||
|
var chat = await configuration.chatService.chatOverviewService
|
||||||
|
.storeChatIfNot(
|
||||||
|
GroupChatModel(
|
||||||
|
canBeDeleted: true,
|
||||||
|
title: groupChatName,
|
||||||
|
imageUrl: 'https://picsum.photos/200/300',
|
||||||
|
users: users,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (context.mounted) {
|
||||||
|
await context.push(
|
||||||
|
ChatUserStoryRoutes.chatDetailViewPath(chat.id ?? ''),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return buildScreenWithoutTransition(
|
||||||
|
context: context,
|
||||||
|
state: state,
|
||||||
|
child: configuration.chatPageBuilder?.call(
|
||||||
|
context,
|
||||||
|
newGroupChatOverviewScreen,
|
||||||
|
) ??
|
||||||
|
Scaffold(
|
||||||
|
body: newGroupChatOverviewScreen,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -144,22 +144,25 @@ class FirebaseChatOverviewService implements ChatOverviewService {
|
||||||
imageUrl: chat.imageUrl ?? '',
|
imageUrl: chat.imageUrl ?? '',
|
||||||
unreadMessages: unread,
|
unreadMessages: unread,
|
||||||
users: users,
|
users: users,
|
||||||
lastMessage: chat.lastMessage != null &&
|
lastMessage: chat.lastMessage != null
|
||||||
chat.lastMessage!.imageUrl == null
|
? chat.lastMessage!.imageUrl == null
|
||||||
? ChatTextMessageModel(
|
? ChatTextMessageModel(
|
||||||
sender: otherUser!,
|
sender: otherUser!,
|
||||||
text: chat.lastMessage!.text!,
|
text: chat.lastMessage!.text!,
|
||||||
timestamp: DateTime.fromMillisecondsSinceEpoch(
|
timestamp: DateTime.fromMillisecondsSinceEpoch(
|
||||||
chat.lastMessage!.timestamp.millisecondsSinceEpoch,
|
chat.lastMessage!.timestamp
|
||||||
|
.millisecondsSinceEpoch,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: ChatImageMessageModel(
|
: ChatImageMessageModel(
|
||||||
sender: otherUser!,
|
sender: otherUser!,
|
||||||
imageUrl: chat.lastMessage!.imageUrl!,
|
imageUrl: chat.lastMessage!.imageUrl!,
|
||||||
timestamp: DateTime.fromMillisecondsSinceEpoch(
|
timestamp: DateTime.fromMillisecondsSinceEpoch(
|
||||||
chat.lastMessage!.timestamp.millisecondsSinceEpoch,
|
chat.lastMessage!.timestamp
|
||||||
),
|
.millisecondsSinceEpoch,
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
canBeDeleted: chat.canBeDeleted,
|
canBeDeleted: chat.canBeDeleted,
|
||||||
lastUsed: chat.lastUsed == null
|
lastUsed: chat.lastUsed == null
|
||||||
? null
|
? null
|
||||||
|
@ -381,7 +384,7 @@ class FirebaseChatOverviewService implements ChatOverviewService {
|
||||||
];
|
];
|
||||||
|
|
||||||
var reference = await _db
|
var reference = await _db
|
||||||
.collection(_options.chatsCollectionName)
|
.collection(_options.chatsMetaDataCollectionName)
|
||||||
.withConverter(
|
.withConverter(
|
||||||
fromFirestore: (snapshot, _) =>
|
fromFirestore: (snapshot, _) =>
|
||||||
FirebaseChatDocument.fromJson(snapshot.data()!, snapshot.id),
|
FirebaseChatDocument.fromJson(snapshot.data()!, snapshot.id),
|
||||||
|
@ -390,6 +393,8 @@ class FirebaseChatOverviewService implements ChatOverviewService {
|
||||||
.add(
|
.add(
|
||||||
FirebaseChatDocument(
|
FirebaseChatDocument(
|
||||||
personal: false,
|
personal: false,
|
||||||
|
title: chat.title,
|
||||||
|
imageUrl: chat.imageUrl,
|
||||||
canBeDeleted: chat.canBeDeleted,
|
canBeDeleted: chat.canBeDeleted,
|
||||||
users: userIds,
|
users: userIds,
|
||||||
lastUsed: Timestamp.now(),
|
lastUsed: Timestamp.now(),
|
||||||
|
@ -404,7 +409,6 @@ class FirebaseChatOverviewService implements ChatOverviewService {
|
||||||
.doc(reference.id)
|
.doc(reference.id)
|
||||||
.set({'users': userIds}, SetOptions(merge: true));
|
.set({'users': userIds}, SetOptions(merge: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
chat.id = reference.id;
|
chat.id = reference.id;
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Chat type not supported for firebase');
|
throw Exception('Chat type not supported for firebase');
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
abstract class ChatUserModelInterface {
|
abstract class ChatUserModelInterface {
|
||||||
String? get id;
|
String? get id;
|
||||||
String? get firstName;
|
String? get firstName;
|
||||||
|
@ -14,6 +16,7 @@ abstract class ChatUserModelInterface {
|
||||||
|
|
||||||
/// A concrete implementation of [ChatUserModelInterface]
|
/// A concrete implementation of [ChatUserModelInterface]
|
||||||
/// representing a chat user.
|
/// representing a chat user.
|
||||||
|
@immutable
|
||||||
class ChatUserModel implements ChatUserModelInterface {
|
class ChatUserModel implements ChatUserModelInterface {
|
||||||
/// Constructs a [ChatUserModel] instance.
|
/// Constructs a [ChatUserModel] instance.
|
||||||
///
|
///
|
||||||
|
@ -24,7 +27,8 @@ class ChatUserModel implements ChatUserModelInterface {
|
||||||
/// [lastName]: The last name of the user.
|
/// [lastName]: The last name of the user.
|
||||||
///
|
///
|
||||||
/// [imageUrl]: The URL of the user's image.
|
/// [imageUrl]: The URL of the user's image.
|
||||||
ChatUserModel({
|
///
|
||||||
|
const ChatUserModel({
|
||||||
this.id,
|
this.id,
|
||||||
this.firstName,
|
this.firstName,
|
||||||
this.lastName,
|
this.lastName,
|
||||||
|
@ -57,4 +61,12 @@ class ChatUserModel implements ChatUserModelInterface {
|
||||||
|
|
||||||
return fullName == '' ? null : fullName;
|
return fullName == '' ? null : fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) || other is ChatUserModel && id == other.id;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
id.hashCode ^ firstName.hashCode ^ lastName.hashCode ^ imageUrl.hashCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,13 @@ class LocalChatDetailService with ChangeNotifier implements ChatDetailService {
|
||||||
int pageSize,
|
int pageSize,
|
||||||
String chatId,
|
String chatId,
|
||||||
) async {
|
) async {
|
||||||
await chatOverviewService.getChatById(chatId).then((value) {
|
var value = await chatOverviewService.getChatById(chatId);
|
||||||
_cumulativeMessages.clear();
|
_cumulativeMessages.clear();
|
||||||
|
if (value.messages != null) {
|
||||||
_cumulativeMessages.addAll(value.messages!);
|
_cumulativeMessages.addAll(value.messages!);
|
||||||
|
}
|
||||||
_controller.add(_cumulativeMessages);
|
_controller.add(_cumulativeMessages);
|
||||||
});
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return Future.value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -48,9 +48,11 @@ class LocalChatDetailService with ChangeNotifier implements ChatDetailService {
|
||||||
_controller.onListen = () async {
|
_controller.onListen = () async {
|
||||||
_subscription =
|
_subscription =
|
||||||
chatOverviewService.getChatById(chatId).asStream().listen((event) {
|
chatOverviewService.getChatById(chatId).asStream().listen((event) {
|
||||||
|
if (event.messages != null) {
|
||||||
_cumulativeMessages.clear();
|
_cumulativeMessages.clear();
|
||||||
_cumulativeMessages.addAll(event.messages!);
|
_cumulativeMessages.addAll(event.messages!);
|
||||||
_controller.add(_cumulativeMessages);
|
_controller.add(_cumulativeMessages);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -150,12 +150,13 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
|
||||||
itemCount: filteredUsers.length,
|
itemCount: filteredUsers.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
var user = filteredUsers[index];
|
var user = filteredUsers[index];
|
||||||
var isSelected = selectedUserList.contains(user);
|
var isSelected =
|
||||||
|
selectedUserList.any((selectedUser) => selectedUser == user);
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (isSelected) {
|
if (selectedUserList.contains(user)) {
|
||||||
selectedUserList.remove(user);
|
selectedUserList.remove(user);
|
||||||
} else {
|
} else {
|
||||||
selectedUserList.add(user);
|
selectedUserList.add(user);
|
||||||
|
|
Loading…
Reference in a new issue