You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
5.6 KiB
Dart
181 lines
5.6 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
import 'package:mc_common_app/models/chat_models/buyers_chat_for_ads_model.dart';
|
|
import 'package:mc_common_app/models/requests_models/request_model.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
|
|
/// Service for handling navigation to different chat types in the app
|
|
/// Provides centralized navigation logic for Request, Advertisement, and General chats
|
|
abstract class ChatNavigationService {
|
|
/// Navigate to Request Offer Chat screen
|
|
Future<void> navigateToRequestOfferChat({
|
|
required BuildContext context,
|
|
required int requestId,
|
|
required String receiverId,
|
|
required String senderId,
|
|
required int requestIndex,
|
|
required int providerIndex,
|
|
required RequestModel requestModel,
|
|
});
|
|
|
|
/// Navigate to Advertisement Chat screen
|
|
Future<void> navigateToAdChat({
|
|
required BuildContext context,
|
|
required int adsId,
|
|
required String receiverUserId,
|
|
});
|
|
|
|
/// Navigate to General Chat screen
|
|
Future<void> navigateToGeneralChat({
|
|
required BuildContext context,
|
|
required String receiverUserId,
|
|
Map<String, dynamic>? additionalData,
|
|
});
|
|
|
|
/// Navigate to Chat List screen based on chat type
|
|
Future<void> navigateToChatList({
|
|
required BuildContext context,
|
|
required ChatTypeEnum chatType,
|
|
Map<String, dynamic>? arguments,
|
|
});
|
|
}
|
|
|
|
class ChatNavigationServiceImp implements ChatNavigationService {
|
|
@override
|
|
Future<void> navigateToRequestOfferChat({
|
|
required BuildContext context,
|
|
required int requestId,
|
|
required String receiverId,
|
|
required String senderId,
|
|
required int requestIndex,
|
|
required int providerIndex,
|
|
required RequestModel requestModel,
|
|
}) async {
|
|
try {
|
|
log("Navigating to Request Offer Chat: requestId=$requestId");
|
|
|
|
ChatViewArgumentsForRequest args = ChatViewArgumentsForRequest(
|
|
chatTypeEnum: ChatTypeEnum.requestOffer,
|
|
requestId: requestId,
|
|
receiverId: receiverId,
|
|
senderId: senderId,
|
|
requestIndex: requestIndex,
|
|
providerIndex: providerIndex,
|
|
requestModel: requestModel,
|
|
);
|
|
|
|
ChatViewArguments chatViewArguments = ChatViewArguments(
|
|
chatTypeEnum: ChatTypeEnum.requestOffer,
|
|
chatViewArgumentsForRequest: args,
|
|
);
|
|
|
|
navigateWithName(context, AppRoutes.chatView, arguments: chatViewArguments);
|
|
} catch (e) {
|
|
log("Error navigating to request offer chat: $e");
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> navigateToAdChat({
|
|
required BuildContext context,
|
|
required int adsId,
|
|
required String receiverUserId,
|
|
}) async {
|
|
try {
|
|
log("Navigating to Ad Chat: adsId=$adsId, receiverId=$receiverUserId");
|
|
|
|
ChatViewArgumentsForAd args = ChatViewArgumentsForAd(
|
|
adsID: adsId,
|
|
receiverUserID: receiverUserId,
|
|
);
|
|
|
|
ChatViewArguments chatViewArguments = ChatViewArguments(
|
|
chatTypeEnum: ChatTypeEnum.ads,
|
|
chatViewArgumentsForAd: args,
|
|
);
|
|
|
|
navigateWithName(context, AppRoutes.chatView, arguments: chatViewArguments);
|
|
} catch (e) {
|
|
log("Error navigating to ad chat: $e");
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> navigateToGeneralChat({
|
|
required BuildContext context,
|
|
required String receiverUserId,
|
|
Map<String, dynamic>? additionalData,
|
|
}) async {
|
|
try {
|
|
log("Navigating to General Chat: receiverId=$receiverUserId");
|
|
|
|
// General chat implementation
|
|
// You can extend this based on your general chat requirements
|
|
ChatViewArguments chatViewArguments = ChatViewArguments(
|
|
chatTypeEnum: ChatTypeEnum.general,
|
|
);
|
|
|
|
navigateWithName(context, AppRoutes.chatView, arguments: chatViewArguments);
|
|
} catch (e) {
|
|
log("Error navigating to general chat: $e");
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> navigateToChatList({
|
|
required BuildContext context,
|
|
required ChatTypeEnum chatType,
|
|
Map<String, dynamic>? arguments,
|
|
}) async {
|
|
try {
|
|
log("Navigating to Chat List: type=$chatType");
|
|
|
|
switch (chatType) {
|
|
case ChatTypeEnum.requestOffer:
|
|
// Navigate to Providers Chat List (for customer side)
|
|
// or Requests list (for provider side)
|
|
if (AppState().currentAppType == AppType.customer) {
|
|
navigateWithName(context, AppRoutes.providersChatListPage);
|
|
} else {
|
|
// For provider, navigate to requests page
|
|
navigateWithName(context, AppRoutes.dashboard);
|
|
}
|
|
break;
|
|
|
|
case ChatTypeEnum.ads:
|
|
// Navigate to Ads Buyers Chat List
|
|
if (arguments != null && arguments['buyers'] != null) {
|
|
navigateWithName(
|
|
context,
|
|
AppRoutes.adsBuyerChatsListView,
|
|
arguments: arguments['buyers'] as List<BuyersChatForAdsModel>,
|
|
);
|
|
} else {
|
|
// Navigate to ads list if buyers not provided
|
|
navigateWithName(context, AppRoutes.dashboard);
|
|
}
|
|
break;
|
|
|
|
case ChatTypeEnum.general:
|
|
// Navigate to General Chats List
|
|
if (arguments != null && arguments['requestId'] != null) {
|
|
navigateWithName(
|
|
context,
|
|
AppRoutes.generalChatsListForProvider,
|
|
arguments: arguments['requestId'] as int,
|
|
);
|
|
} else {
|
|
navigateWithName(context, AppRoutes.dashboard);
|
|
}
|
|
break;
|
|
}
|
|
} catch (e) {
|
|
log("Error navigating to chat list: $e");
|
|
}
|
|
}
|
|
}
|