parent
d28a3a7148
commit
61b97c5635
@ -0,0 +1,48 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "60196905754",
|
||||
"project_id": "health-pharma-67443",
|
||||
"storage_bucket": "health-pharma-67443.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:60196905754:android:05ea9ecef5280e578a42a3",
|
||||
"android_client_info": {
|
||||
"package_name": "com.arminta.healthcare_pharmacy"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyC89L-Xg53Bd_mdCPvKOu7BcC9Ya6UZeds"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:60196905754:android:a35c084e291315488a42a3",
|
||||
"android_client_info": {
|
||||
"package_name": "com.arminta.healthparma"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyC89L-Xg53Bd_mdCPvKOu7BcC9Ya6UZeds"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
After Width: | Height: | Size: 16 KiB |
@ -0,0 +1,6 @@
|
||||
|
||||
class ChatMessage{
|
||||
String message;
|
||||
String type;
|
||||
ChatMessage({required this.message,required this.type});
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
||||
class PushNotificationService {
|
||||
final FirebaseMessaging _fcm = FirebaseMessaging.instance;
|
||||
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
|
||||
// Constructor to initialize the FCM token
|
||||
PushNotificationService() {
|
||||
_initFCMToken();
|
||||
}
|
||||
|
||||
Future<void> _initFCMToken() async {
|
||||
// Get the stored FCM token
|
||||
AppSettings.fcmId = await _getStoredFCMToken();
|
||||
|
||||
// If FCM token is not available, request a new one
|
||||
if (AppSettings.fcmId.isEmpty) {
|
||||
await _fcm.getToken().then((token) {
|
||||
print('FCM Token: $token');
|
||||
// Store the FCM token directly in AppSettings
|
||||
AppSettings.fcmId = token!;
|
||||
_storeFCMToken(token);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _storeFCMToken(String token) async {
|
||||
// Store the FCM token using SharedPreferences
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('fcmToken', token);
|
||||
}
|
||||
|
||||
Future<String> _getStoredFCMToken() async {
|
||||
// Retrieve the stored FCM token from SharedPreferences
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString('fcmToken') ?? '';
|
||||
}
|
||||
Future<void> initialize() async {
|
||||
// Request permission for user notifications
|
||||
await _fcm.requestPermission();
|
||||
|
||||
// Get the FCM token and handle incoming messages while the app is in the foreground
|
||||
_fcm.getToken().then((token) {
|
||||
print('FCM Token: $token');
|
||||
// Do something with the token (e.g., send it to your server)
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Listen to incoming messages while the app is in the foreground
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print("data::::$message");
|
||||
// var payload = message.data.toString();
|
||||
// // Handle the incoming message
|
||||
// Map<String, dynamic> notificationPayload = jsonDecode(payload);
|
||||
// Access the extra data using the keys
|
||||
var payload=message.data;
|
||||
var extramessage;
|
||||
if(payload.isNotEmpty){
|
||||
extramessage = message.data['extraKey1'];
|
||||
String? extraValue2 = message.data['extraKey2'];
|
||||
|
||||
}
|
||||
|
||||
// Show a local notification with the received message
|
||||
_showNotification(message.notification?.title, message.notification?.body,extramessage);
|
||||
});
|
||||
|
||||
// Handle messages when the app is in the background or terminated
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
var payload = message.data.toString();
|
||||
if (payload != null) {
|
||||
// Parse the JSON payload
|
||||
Map<String, dynamic> notificationPayload = jsonDecode(payload);
|
||||
// Access the extra data using the keys
|
||||
String? extraValue1 = notificationPayload['extraKey1'];
|
||||
String? extraValue2 = notificationPayload['extraKey2'];
|
||||
// Do something with the extra data, e.g., display it in a dialog or use it in your app logic.
|
||||
}
|
||||
|
||||
// Show a local notification with the received message
|
||||
// _showNotification(message.notification?.title, message.notification?.body);
|
||||
});
|
||||
}
|
||||
|
||||
// Method to show a local notification using flutter_local_notifications
|
||||
Future<void> _showNotification(String? title, String? body,String extramessage) async {
|
||||
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
||||
AndroidNotificationDetails(
|
||||
'healthpharma', // Replace with your channel ID
|
||||
'healthpharmanotifications', // Replace with your channel name
|
||||
importance: Importance.high,
|
||||
priority: Priority.high,
|
||||
showWhen: false,
|
||||
icon: "logo"
|
||||
|
||||
);
|
||||
|
||||
const NotificationDetails platformChannelSpecifics =
|
||||
NotificationDetails(android: androidPlatformChannelSpecifics);
|
||||
Map<String, dynamic> notificationPayload = {
|
||||
"body": body,
|
||||
"title": title,
|
||||
"extraKey1": extramessage,
|
||||
"extraKey2": "Extra Value 2",
|
||||
// Add more key-value pairs as needed
|
||||
};
|
||||
await _flutterLocalNotificationsPlugin.show(
|
||||
0, // notification ID (can be any unique ID)
|
||||
title, // notification title
|
||||
body, // notification body
|
||||
platformChannelSpecifics,
|
||||
payload: jsonEncode(notificationPayload), // optional, you can pass data or identifier related to the notification
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'chatmessage.dart';
|
||||
|
||||
|
||||
class ChatController extends GetxController {
|
||||
final CollectionReference _messagesCollection =
|
||||
FirebaseFirestore.instance.collection('messages');
|
||||
|
||||
// Observable list of messages
|
||||
RxList<ChatMessage> messages = <ChatMessage>[].obs;
|
||||
|
||||
void sendMessage(String messageContent, String messageType, bool isText) async {
|
||||
try {
|
||||
await _messagesCollection.add({
|
||||
'messageContent': messageContent,
|
||||
'messageType': messageType,
|
||||
'isText': isText,
|
||||
'timestamp': Timestamp.now(),
|
||||
});
|
||||
print("Message sent successfully");
|
||||
} catch (e) {
|
||||
print('Error sending message: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> uploadImage(File image, String id) async {
|
||||
try {
|
||||
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
Reference storageReference =
|
||||
FirebaseStorage.instance.ref().child('products/$fileName');
|
||||
SettableMetadata metadata = SettableMetadata(contentType: 'image/jpeg');
|
||||
UploadTask uploadTask = storageReference.putFile(image, metadata);
|
||||
|
||||
String temporaryMessageId = UniqueKey().toString();
|
||||
messages.add(ChatMessage(
|
||||
messageContent: 'Uploading...',
|
||||
messageType: id,
|
||||
isText: true,
|
||||
temporaryMessageId: temporaryMessageId,
|
||||
));
|
||||
|
||||
TaskSnapshot taskSnapshot = await uploadTask;
|
||||
String downloadURL = await storageReference.getDownloadURL();
|
||||
|
||||
// Replace the temporary message with the uploaded image
|
||||
int index = messages.indexWhere((message) => message.temporaryMessageId == temporaryMessageId);
|
||||
if (index != -1) {
|
||||
messages[index] = ChatMessage(
|
||||
messageContent: downloadURL,
|
||||
messageType: id,
|
||||
isText: false,
|
||||
temporaryMessageId: '',
|
||||
);
|
||||
}
|
||||
|
||||
print('Image uploaded successfully. Download URL: $downloadURL');
|
||||
return downloadURL;
|
||||
} catch (e) {
|
||||
print('Error uploading image: $e');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Stream<QuerySnapshot> getMessagesStream() {
|
||||
return _messagesCollection.orderBy('timestamp').snapshots();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// Listen for changes in the messages collection and update the local list
|
||||
getMessagesStream().listen((QuerySnapshot snapshot) {
|
||||
messages.assignAll(snapshot.docs.map((doc) => ChatMessage(
|
||||
messageContent: doc['messageContent'],
|
||||
messageType: doc['messageType'],
|
||||
isText: doc['isText'],
|
||||
temporaryMessageId: '',
|
||||
)));
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class ChatMessage {
|
||||
String messageContent;
|
||||
String messageType;
|
||||
bool isText;
|
||||
String temporaryMessageId; // New property for temporary message identifier
|
||||
|
||||
ChatMessage({
|
||||
required this.messageContent,
|
||||
required this.messageType,
|
||||
required this.isText,
|
||||
required this.temporaryMessageId, // Include in the constructor
|
||||
});
|
||||
}
|
@ -0,0 +1,241 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:healthcare_pharmacy/chat/chatzoomable_image.dart';
|
||||
import 'package:healthcare_pharmacy/pages/index.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'chat_controller.dart';
|
||||
import 'chatmessage.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
|
||||
class ChatPage extends StatefulWidget {
|
||||
var pharmacyName;
|
||||
var profilePictureUrl;
|
||||
|
||||
|
||||
ChatPage({
|
||||
this.pharmacyName,this.profilePictureUrl
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChatPage> createState() => _ChatPageState();
|
||||
}
|
||||
|
||||
class _ChatPageState extends State<ChatPage> {
|
||||
final ChatController chatController = Get.put(ChatController());
|
||||
final TextEditingController content = TextEditingController();
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
XFile? _image;
|
||||
var id="2";
|
||||
bool _sending = false;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor:Colors.green,
|
||||
elevation: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
flexibleSpace: SafeArea(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(right: 16),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
onPressed: (){
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back,color: Colors.black,),
|
||||
),
|
||||
SizedBox(width: 2,),
|
||||
CircleAvatar(
|
||||
backgroundImage: NetworkImage(AppSettings.profilePictureUrl),
|
||||
maxRadius: 20,
|
||||
),
|
||||
SizedBox(width: 12,),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(widget.pharmacyName,style: TextStyle( fontSize: 16 ,fontWeight: FontWeight.w600),),
|
||||
// SizedBox(height: 6,),
|
||||
// Text("Online",style: TextStyle(color: Colors.grey.shade600, fontSize: 13),),
|
||||
],
|
||||
),
|
||||
),
|
||||
/*IconButton(
|
||||
onPressed: () {
|
||||
UrlLauncher.launch("tel://8328206298");
|
||||
},
|
||||
icon: Icon(Icons.call, color: Colors.black),
|
||||
),*/
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => IndexPage()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.videocam, color: Colors.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Obx(() => ListView.builder(
|
||||
itemCount: chatController.messages.length,
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(top: 10, bottom: 80), // Adjust bottom padding to accommodate the input field
|
||||
physics: ScrollPhysics(),
|
||||
controller: _scrollController,
|
||||
itemBuilder: (context, index) {
|
||||
final data = chatController.messages[index];
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 14, right: 14, top: 10, bottom: 10),
|
||||
child: Align(
|
||||
alignment: (data.messageType != id ? Alignment.topLeft : Alignment.topRight),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChatZoomableImage(data.messageContent),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: (data.messageType != id
|
||||
? Colors.grey.shade200
|
||||
: Colors.blue[200]),
|
||||
),
|
||||
padding: EdgeInsets.all(16),
|
||||
child: data.isText
|
||||
? Text(data.messageContent, style: TextStyle(fontSize: 15))
|
||||
: Image.network(
|
||||
data.messageContent,
|
||||
scale: 3,
|
||||
width: 100,
|
||||
height: 100,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
},
|
||||
)),
|
||||
Align(alignment: Alignment.bottomCenter,child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
color: Colors.white,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
onTap: getImage,
|
||||
child: Container(
|
||||
height: 30,
|
||||
width: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.lightBlue,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
child: Icon(Icons.add, color: Colors.white, size: 20),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 15),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: content,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Write message...",
|
||||
hintStyle: TextStyle(color: Colors.black54),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 15),
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
sendMessage();
|
||||
},
|
||||
child: Icon(Icons.send, color: Colors.white, size: 18),
|
||||
backgroundColor: Colors.blue,
|
||||
elevation: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
Future.delayed(Duration(milliseconds: 300), () {
|
||||
if (_scrollController.hasClients) {
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future getImage() async {
|
||||
final XFile? image =
|
||||
await _picker.pickImage(source: ImageSource.gallery);
|
||||
if (image != null) {
|
||||
setState(() {
|
||||
_image = image;
|
||||
});
|
||||
sendMessage(); // Call sendMessage function to send the selected image immediately
|
||||
}
|
||||
}
|
||||
|
||||
void sendMessage() async {
|
||||
String messageContent = content.text.trim();
|
||||
if (messageContent.isNotEmpty || _image != null) {
|
||||
setState(() {
|
||||
_sending = true;
|
||||
});
|
||||
try {
|
||||
if (_image != null) {
|
||||
String imageUrl =
|
||||
await chatController.uploadImage(File(_image!.path),'$id');
|
||||
chatController.sendMessage(imageUrl, '$id', false);
|
||||
_image = null; // Clear the selected image after sending
|
||||
}
|
||||
if (messageContent.isNotEmpty) {
|
||||
chatController.sendMessage(messageContent, '$id', true);
|
||||
content.clear();
|
||||
}
|
||||
} finally {
|
||||
setState(() {
|
||||
_sending = false;
|
||||
});
|
||||
}
|
||||
_scrollToBottom(); // Scroll to the bottom after sending message
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
|
||||
class ChatZoomableImage extends StatelessWidget {
|
||||
final String imageUrl;
|
||||
|
||||
ChatZoomableImage(this.imageUrl);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor, // Set the background color
|
||||
title: Text('Preview Image'), // Set the title text
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.close),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: imageUrl.isNotEmpty
|
||||
? PhotoView(
|
||||
imageProvider: NetworkImage(imageUrl),
|
||||
minScale: PhotoViewComputedScale.contained,
|
||||
maxScale: PhotoViewComputedScale.contained * 3.0,
|
||||
)
|
||||
: Image.asset(
|
||||
'images/mobilebg.png', // Path to your default image
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,201 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:healthcare_pharmacy/models/chatconversation_model.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
import 'ChatMessage.dart';
|
||||
|
||||
class ChatUIconvoid extends StatefulWidget {
|
||||
const ChatUIconvoid({super.key});
|
||||
|
||||
@override
|
||||
State<ChatUIconvoid> createState() => _ChatUIconvoidState();
|
||||
}
|
||||
|
||||
class _ChatUIconvoidState extends State<ChatUIconvoid> {
|
||||
|
||||
TextEditingController _messageController = TextEditingController();
|
||||
bool isLoading=false;
|
||||
List<GetCoversatitonIdModel> chatCoversatitonIdList = [];
|
||||
List<ChatMessage> messages = [
|
||||
ChatMessage(message: "Hello", type: "receiver"),
|
||||
ChatMessage(message: "How have you?", type: "receiver"),
|
||||
ChatMessage(
|
||||
message: "I am doing fine.How have you?",
|
||||
type: "sender"),
|
||||
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
isLoading=true;
|
||||
getConversasionId();
|
||||
super.initState();
|
||||
}
|
||||
Future<void> getConversasionId() async {
|
||||
isLoading = true;
|
||||
try {
|
||||
var response = await AppSettings.getChatId();
|
||||
setState(() {
|
||||
chatCoversatitonIdList =
|
||||
((jsonDecode(response)['newConversation']) as List).map((dynamic model) {
|
||||
return GetCoversatitonIdModel.fromJson(model);
|
||||
}).toList();
|
||||
|
||||
// Extracting the conversation_id from the response
|
||||
String conversationId =
|
||||
jsonDecode(response)['newConversation']['conversation_id'];
|
||||
|
||||
// Use the conversationId as needed in your code
|
||||
print('Conversation ID: $conversationId');
|
||||
|
||||
isLoading = false;
|
||||
isLoading = false;
|
||||
});
|
||||
|
||||
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
backgroundColor: Colors.white,
|
||||
flexibleSpace: SafeArea(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(right: 16),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
onPressed: (){
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back,color: Colors.black,),
|
||||
),
|
||||
SizedBox(width: 2,),
|
||||
CircleAvatar(
|
||||
backgroundImage: NetworkImage("https://www.shutterstock.com/image-photo/pharmacist-holding-medicine-box-capsule-260nw-717437125.jpg"),
|
||||
maxRadius: 20,
|
||||
),
|
||||
SizedBox(width: 12,),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text("Arminta pharma",style: TextStyle( fontSize: 16 ,fontWeight: FontWeight.w600),),
|
||||
// SizedBox(height: 6,),
|
||||
// Text("Online",style: TextStyle(color: Colors.grey.shade600, fontSize: 13),),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.settings,color: Colors.black54,),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
ListView.builder(
|
||||
itemCount: messages.length,
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(top: 10,bottom: 60),
|
||||
itemBuilder: (context, index){
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 14,right: 14,top: 10,bottom: 10),
|
||||
child: Align(
|
||||
alignment: (messages[index].type == "receiver"?Alignment.topLeft:Alignment.topRight),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: (messages[index].type == "receiver"?Colors.grey.shade200:Colors.blue[200]),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16,vertical: 10),
|
||||
child: Text(messages[index].message, style: TextStyle(fontSize: 15),),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 10, bottom: 10, top: 10),
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
color: Colors.white,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
onTap: () {},
|
||||
child: Container(
|
||||
height: 30,
|
||||
width: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.lightBlue,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _messageController,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Write message...",
|
||||
hintStyle: TextStyle(color: Colors.black54),
|
||||
border: InputBorder.none),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
String newMessage = _messageController.text;
|
||||
if (newMessage.isNotEmpty) {
|
||||
// Add the new message to the list
|
||||
setState(() {
|
||||
messages.add(
|
||||
ChatMessage(
|
||||
message: newMessage,
|
||||
type: "sender",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
// Clear the text field
|
||||
_messageController.clear();
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
Icons.send,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
),
|
||||
backgroundColor: Colors.blue,
|
||||
elevation: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,395 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:healthcare_pharmacy/pages/index.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
|
||||
import 'package:web_socket_channel/io.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import 'models/ChatMessage.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:flutter_callkeep/flutter_callkeep.dart';
|
||||
|
||||
|
||||
class ChatUI extends StatefulWidget {
|
||||
|
||||
const ChatUI({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChatUI> createState() => _ChatUIState();
|
||||
}
|
||||
|
||||
class _ChatUIState extends State<ChatUI> {
|
||||
WebSocketChannel channel=IOWebSocketChannel.connect(
|
||||
"wss://socketsbay.com/wss/v2/1/demo/",
|
||||
);
|
||||
// WebSocket channel for call signaling
|
||||
late WebSocketChannel callChannel;
|
||||
|
||||
WebSocketConnectionState _connectionState = WebSocketConnectionState.connecting;
|
||||
late ScrollController _scrollController;
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
// Store messages
|
||||
final List<ChatMessage> _messages = [];
|
||||
String myUserId = 'user456';
|
||||
String otherUserId = 'user123';
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
Future pickImageFromGallery() async {
|
||||
try {
|
||||
final image = await _picker.pickImage(source: ImageSource.gallery);
|
||||
if (image == null) return;
|
||||
final imageTemp = File(image.path);
|
||||
setState(() {
|
||||
AppSettings.updatedImage = imageTemp;
|
||||
});
|
||||
// uploadProfileApi(AppSettings.updatedImage);
|
||||
AppSettings.saveProfile(image.path);
|
||||
|
||||
|
||||
} on PlatformException catch (e) {
|
||||
print('Failed to pick image: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future takeImageFromCamera() async {
|
||||
try {
|
||||
final image = await _picker.pickImage(source: ImageSource.camera);
|
||||
if (image == null) return;
|
||||
final imageTemp = File(image.path);
|
||||
setState(() {
|
||||
AppSettings.updatedImage = imageTemp;
|
||||
});
|
||||
|
||||
//uploadProfileApi(AppSettings.updatedImage);
|
||||
AppSettings.saveProfile(image.path);
|
||||
|
||||
} on PlatformException catch (e) {
|
||||
print('Failed to pick image: $e');
|
||||
}
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: _connectionState == WebSocketConnectionState.error ? Colors.red : _connectionState == WebSocketConnectionState.closed ? Colors.red : Colors.green,
|
||||
elevation: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
flexibleSpace: SafeArea(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(right: 16),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
onPressed: (){
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back,color: Colors.black,),
|
||||
),
|
||||
SizedBox(width: 2,),
|
||||
CircleAvatar(
|
||||
backgroundImage: NetworkImage("https://ehealth.eletsonline.com/wp-content/uploads/2020/12/pharma-industry-in-2021.jpg"),
|
||||
maxRadius: 20,
|
||||
),
|
||||
SizedBox(width: 12,),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text("Suresh",style: TextStyle( fontSize: 16 ,fontWeight: FontWeight.w600),),
|
||||
// SizedBox(height: 6,),
|
||||
// Text("Online",style: TextStyle(color: Colors.grey.shade600, fontSize: 13),),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
UrlLauncher.launch("tel://8328206298");
|
||||
},
|
||||
icon: Icon(Icons.call, color: Colors.black),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => IndexPage()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.videocam, color: Colors.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
ListView.builder(
|
||||
controller: _scrollController,
|
||||
itemCount: _messages.length,
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(top: 10,bottom: 60),
|
||||
itemBuilder: (context, index){
|
||||
bool isSentByMe = _messages[index].senderId == myUserId;
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 14,right: 14,top: 10,bottom: 10),
|
||||
child: Align(
|
||||
alignment: (isSentByMe?Alignment.topRight:Alignment.topLeft),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: (isSentByMe?Colors.blue[200]:Colors.grey[200]),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16,vertical: 10),
|
||||
child: Text(_messages[index].messageContent, style: TextStyle(fontSize: 15),),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 10, bottom: 10, top: 10),
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
color: Colors.white,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 200,
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
child: Icon(
|
||||
Icons.camera_alt_outlined,
|
||||
size: 100,
|
||||
color: greyColor,
|
||||
),
|
||||
onTap: () async {
|
||||
await takeImageFromCamera();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
width:
|
||||
MediaQuery.of(context).size.width * .20,
|
||||
),
|
||||
GestureDetector(
|
||||
child: Icon(
|
||||
Icons.photo,
|
||||
size: 100,
|
||||
color: greyColor,
|
||||
),
|
||||
onTap: () async {
|
||||
await pickImageFromGallery();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
height: 30,
|
||||
width: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.lightBlue,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Write message...",
|
||||
hintStyle: TextStyle(color: Colors.black54),
|
||||
border: InputBorder.none),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
String newMessage = _controller.text;
|
||||
if (newMessage.isNotEmpty) {
|
||||
// Add the new message to the list
|
||||
setState(() {
|
||||
_sendMessage();
|
||||
});
|
||||
|
||||
// Clear the text field
|
||||
_controller.clear();
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
Icons.send,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
),
|
||||
backgroundColor: Colors.blue,
|
||||
elevation: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _sendMessage() {
|
||||
if (_controller.text.isNotEmpty) {
|
||||
var message = ChatMessage(
|
||||
senderId: myUserId,
|
||||
receiverId: otherUserId,
|
||||
messageType: 'text',
|
||||
messageContent: _controller.text,
|
||||
);
|
||||
channel.sink.add(chatMessageToJson(message));
|
||||
_messages.add(message);
|
||||
_controller.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize the WebSocket channel for call signaling
|
||||
callChannel = IOWebSocketChannel.connect(
|
||||
"wss://socketsbay.com/wss/v2/1/demo/call", // adjust the URL accordingly
|
||||
);
|
||||
_scrollController = ScrollController();
|
||||
channel.stream.listen((message) {
|
||||
if (message is String) {
|
||||
var receivedMessage = chatMessageFromJson(message);
|
||||
setState(() {
|
||||
_messages.add(receivedMessage);
|
||||
});
|
||||
_scrollToBottom();
|
||||
}
|
||||
}, onError: (error) {
|
||||
setState(() {
|
||||
_connectionState = WebSocketConnectionState.error;
|
||||
});
|
||||
},onDone: (){
|
||||
setState(() {
|
||||
_connectionState = WebSocketConnectionState.closed;
|
||||
});
|
||||
},);
|
||||
}
|
||||
|
||||
|
||||
// ... existing code ...
|
||||
|
||||
void startCall(String callId) {
|
||||
// Send a call initiation message to the other user
|
||||
var callMessage = {
|
||||
'type': 'call',
|
||||
'callId': callId,
|
||||
'senderId': myUserId,
|
||||
'receiverId': otherUserId,
|
||||
};
|
||||
callChannel.sink.add(jsonEncode(callMessage));
|
||||
|
||||
// Update UI or perform other actions as needed
|
||||
// ...
|
||||
|
||||
// For simplicity, let's assume the call is accepted after a short delay
|
||||
Future.delayed(Duration(seconds: 2), () {
|
||||
// Handle call accepted
|
||||
onCallAccepted(callId);
|
||||
});
|
||||
}
|
||||
|
||||
void onCallAccepted(String callId) {
|
||||
// Update UI or perform other actions as needed
|
||||
// ...
|
||||
|
||||
// Send a call accepted message to the other user
|
||||
var acceptedMessage = {
|
||||
'type': 'call_accepted',
|
||||
'callId': callId,
|
||||
'senderId': myUserId,
|
||||
'receiverId': otherUserId,
|
||||
};
|
||||
callChannel.sink.add(jsonEncode(acceptedMessage));
|
||||
|
||||
// Start the actual call
|
||||
// ...
|
||||
}
|
||||
|
||||
void endCall(String callId) {
|
||||
// Send a call end message to the other user
|
||||
var endMessage = {
|
||||
'type': 'call_end',
|
||||
'callId': callId,
|
||||
'senderId': myUserId,
|
||||
'receiverId': otherUserId,
|
||||
};
|
||||
callChannel.sink.add(jsonEncode(endMessage));
|
||||
|
||||
// Update UI or perform other actions as needed
|
||||
// ...
|
||||
|
||||
// For simplicity, let's assume the call is ended immediately
|
||||
onCallEnded(callId);
|
||||
}
|
||||
|
||||
void onCallEnded(String callId) {
|
||||
// Update UI or perform other actions as needed
|
||||
// ...
|
||||
|
||||
// Close the call WebSocket channel
|
||||
callChannel.sink.close();
|
||||
|
||||
// For simplicity, let's assume the call ended immediately
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _scrollToBottom() {
|
||||
// Scroll to the bottom of the list
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
channel.sink.close();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
enum WebSocketConnectionState { connecting, open, closing, closed, error }
|
@ -0,0 +1,37 @@
|
||||
import 'package:meta/meta.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
// Define chatMessageFromJson and chatMessageToJson at the top level
|
||||
ChatMessage chatMessageFromJson(String str) => ChatMessage.fromJson(json.decode(str));
|
||||
|
||||
String chatMessageToJson(ChatMessage data) => json.encode(data.toJson());
|
||||
|
||||
class ChatMessage {
|
||||
String senderId;
|
||||
String receiverId;
|
||||
String messageType;
|
||||
String messageContent;
|
||||
|
||||
ChatMessage({
|
||||
required this.senderId,
|
||||
required this.receiverId,
|
||||
required this.messageType,
|
||||
required this.messageContent,
|
||||
});
|
||||
|
||||
factory ChatMessage.fromJson(Map<String, dynamic> json) => ChatMessage(
|
||||
senderId: json["senderId"],
|
||||
receiverId: json["receiverId"],
|
||||
messageType: json["messageType"],
|
||||
messageContent: json["messageContent"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"senderId": senderId,
|
||||
"receiverId": receiverId,
|
||||
"messageType": messageType,
|
||||
"messageContent": messageContent,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,56 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
|
||||
class BiddingRequestsModel {
|
||||
String? custumerid_bidding = '';
|
||||
String? pharmacyid_bidding='';
|
||||
String? amount_bidding='';
|
||||
String? bidding_bookingid='';
|
||||
String? bidding_firstName='';
|
||||
String? bidding_contactNumber='';
|
||||
String? bidding_address='';
|
||||
String orderStatus='';
|
||||
String status='';
|
||||
|
||||
|
||||
Color cardColor=Colors.white;
|
||||
Color textColor=Colors.black;
|
||||
|
||||
class PrescriptionPicture {
|
||||
late String id;
|
||||
late String url;
|
||||
|
||||
PrescriptionPicture({
|
||||
required this.id,
|
||||
required this.url,
|
||||
});
|
||||
|
||||
BiddingRequestsModel();
|
||||
|
||||
factory BiddingRequestsModel.fromJson(Map<String, dynamic> json){
|
||||
BiddingRequestsModel rtvm = new BiddingRequestsModel();
|
||||
factory PrescriptionPicture.fromJson(Map<String, dynamic> json) {
|
||||
return PrescriptionPicture(
|
||||
id: json['_id'],
|
||||
url: json['url'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
rtvm.custumerid_bidding = json['customerId'].toString() ??'';
|
||||
rtvm.pharmacyid_bidding = json['pharmacyId'].toString() ?? '';
|
||||
rtvm.amount_bidding = json['biddingAmount'].toString() ?? '';
|
||||
rtvm.bidding_bookingid = json['bookingId'].toString() ?? '';
|
||||
rtvm.bidding_firstName = json['customerDetails']["firstName"].toString() ?? '';
|
||||
rtvm.bidding_firstName = json['customerDetails']["address1"].toString() ?? '';
|
||||
rtvm.bidding_firstName = json['customerDetails']["firstName"].toString() ?? '';
|
||||
class BiddingRequestsModel {
|
||||
String? customerId = '';
|
||||
String? pharmacyId = '';
|
||||
String? amount = '';
|
||||
String? bookingId = '';
|
||||
String? profilePicture = '';
|
||||
String? firstName = '';
|
||||
String? address = '';
|
||||
String orderStatus = '';
|
||||
String status = '';
|
||||
|
||||
rtvm.status = json['status'] ;
|
||||
List<PrescriptionPicture> PrescriptionPictures = [];
|
||||
|
||||
Color cardColor = Colors.white;
|
||||
Color textColor = Colors.black;
|
||||
|
||||
// rtvm.bidding_contactNumber = json['customerDetails']['profile']["contactNumber"].toString() ?? '';
|
||||
BiddingRequestsModel();
|
||||
|
||||
// rtvm.bidding_contactNumber = json['contactNumber'].toString() ?? '';
|
||||
// rtvm.bidding_address1 = json['address1'].toString() ?? '';
|
||||
factory BiddingRequestsModel.fromJson(Map<String, dynamic> json) {
|
||||
BiddingRequestsModel rtvm = BiddingRequestsModel();
|
||||
|
||||
rtvm.customerId = json['customerId'].toString() ?? '';
|
||||
rtvm.pharmacyId = json['pharmacyId'].toString() ?? '';
|
||||
rtvm.amount = json['biddingAmount'].toString() ?? '';
|
||||
rtvm.bookingId = json['bookingId'].toString() ?? '';
|
||||
rtvm.profilePicture = json['profilePicture'] ?? '';
|
||||
rtvm.firstName = json['customerDetails']["firstName"].toString() ?? '';
|
||||
rtvm.address = json['customerDetails']["address1"].toString() ?? '';
|
||||
rtvm.status = json['status'];
|
||||
|
||||
// rtvm.prescription_url = json['pictureUrl'][0] ?? '';
|
||||
if(rtvm.status.toString().toLowerCase()=='accepted'){
|
||||
rtvm.textColor=Colors.green;
|
||||
}
|
||||
else if(rtvm.status.toString().toLowerCase()=='rejected'){
|
||||
rtvm.textColor=Colors.red;
|
||||
if (json['PrescriptionPictures'] != null) {
|
||||
var pictures = json['PrescriptionPictures'] as List;
|
||||
rtvm.PrescriptionPictures =
|
||||
pictures.map((picture) => PrescriptionPicture.fromJson(picture)).toList();
|
||||
}
|
||||
else{
|
||||
rtvm.textColor=primaryColor;
|
||||
|
||||
if (rtvm.status.toString().toLowerCase() == 'accepted') {
|
||||
rtvm.textColor = Colors.green;
|
||||
} else if (rtvm.status.toString().toLowerCase() == 'rejected') {
|
||||
rtvm.textColor = Colors.red;
|
||||
} else {
|
||||
rtvm.textColor = primaryColor;
|
||||
}
|
||||
|
||||
return rtvm;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
import 'dart:convert';
|
||||
|
||||
List<GetCoversatitonIdModel> listdadFromJson(String str) => List<GetCoversatitonIdModel >.from(json.decode(str).map((x) => GetCoversatitonIdModel .fromJson(x)));
|
||||
|
||||
String listdadToJson(List<GetCoversatitonIdModel > data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
|
||||
|
||||
class GetCoversatitonIdModel {
|
||||
String ? conversation_id;
|
||||
|
||||
GetCoversatitonIdModel ({
|
||||
required this.conversation_id,
|
||||
|
||||
});
|
||||
|
||||
factory GetCoversatitonIdModel .fromJson(Map<String, dynamic> json) => GetCoversatitonIdModel (
|
||||
conversation_id: json["conversation_id"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"conversation_id": conversation_id,
|
||||
};
|
||||
}
|
@ -0,0 +1,271 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:healthcare_pharmacy/settings.dart';
|
||||
import 'dart:async';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import 'package:agora_rtc_engine/rtc_engine.dart';
|
||||
import 'package:agora_rtc_engine/rtc_engine.dart' as rtc_engine;
|
||||
import 'package:agora_rtc_engine/rtc_local_view.dart' as rtc_local_view;
|
||||
import 'package:agora_rtc_engine/rtc_remote_view.dart' as rtc_remote_view;
|
||||
|
||||
class CallPage extends StatefulWidget {
|
||||
final String? channelName;
|
||||
final ClientRole? role;
|
||||
const CallPage({Key? key, this.channelName, this.role}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CallPage> createState() => _CallPageState();
|
||||
}
|
||||
|
||||
class _CallPageState extends State<CallPage> {
|
||||
final _users = <int>[];
|
||||
final _infoString = <String>[];
|
||||
late RtcEngine _engine;
|
||||
bool muted = false; // Define the muted variable
|
||||
bool viewPanel = true;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initialize();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_users.clear();
|
||||
_engine.leaveChannel();
|
||||
_engine.destroy();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> initialize() async {
|
||||
if (appId.isEmpty) {
|
||||
setState(() {
|
||||
_infoString.add('AppId is missing please provide AppId');
|
||||
_infoString.add('Agora Engine is not starting');
|
||||
});
|
||||
return;
|
||||
}
|
||||
_engine = await rtc_engine.RtcEngine.create(appId);
|
||||
await _engine.enableVideo();
|
||||
await _engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
|
||||
await _engine.setClientRole(widget.role!);
|
||||
_addAgoraEventHandler();
|
||||
VideoEncoderConfiguration configuration = VideoEncoderConfiguration(
|
||||
dimensions: VideoDimensions(width: 1920, height: 1080),
|
||||
);
|
||||
await _engine.setVideoEncoderConfiguration(configuration);
|
||||
await _engine.joinChannel(token, widget.channelName!, null, 0);
|
||||
}
|
||||
|
||||
void _addAgoraEventHandler() {
|
||||
_engine.setEventHandler(
|
||||
rtc_engine.RtcEngineEventHandler(
|
||||
error: (code) {
|
||||
setState(() {
|
||||
final info = 'Error: $code';
|
||||
_infoString.add(info);
|
||||
});
|
||||
},
|
||||
joinChannelSuccess: (channel, uid, elapsed) {
|
||||
setState(() {
|
||||
final info = 'Join Channel: $channel, uid:$uid';
|
||||
_infoString.add(info);
|
||||
});
|
||||
},
|
||||
leaveChannel: (stats) {
|
||||
setState(() {
|
||||
_infoString.add('Leave Channel');
|
||||
_users.clear();
|
||||
});
|
||||
},
|
||||
userJoined: (uid, elapsed) {
|
||||
setState(() {
|
||||
final info = 'User joined: $uid';
|
||||
_infoString.add(info);
|
||||
_users.add(uid);
|
||||
});
|
||||
},
|
||||
userOffline: (uid, elapsed) {
|
||||
setState(() {
|
||||
final info = 'User Offline: $uid';
|
||||
_infoString.add(info);
|
||||
_users.remove(uid);
|
||||
});
|
||||
},
|
||||
firstRemoteVideoFrame: (uid, width, height, elapsed) {
|
||||
setState(() {
|
||||
final info = 'First Remote Video: $uid $width*$height';
|
||||
_infoString.add(info);
|
||||
_users.remove(uid);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Widget _viewRows() {
|
||||
final List<StatefulWidget> list = [];
|
||||
if (widget.role == ClientRole.Broadcaster) {
|
||||
list.add(const rtc_local_view.SurfaceView());
|
||||
}
|
||||
for (var uid in _users) {
|
||||
list.add(rtc_remote_view.SurfaceView(
|
||||
uid: uid,
|
||||
channelId: widget.channelName!,
|
||||
));
|
||||
}
|
||||
final views=list;
|
||||
return Column(
|
||||
children: List.generate(
|
||||
views.length,
|
||||
(index) => Expanded(
|
||||
child: views[index],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _toolbar() {
|
||||
if (widget.role == ClientRole.Audience) return SizedBox();
|
||||
|
||||
return Container(
|
||||
alignment: Alignment.bottomCenter,
|
||||
padding: const EdgeInsets.symmetric(vertical: 48),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
RawMaterialButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
muted = !muted;
|
||||
});
|
||||
_engine.muteLocalAudioStream(muted);
|
||||
},
|
||||
child: Icon(
|
||||
muted ? Icons.mic_off : Icons.mic,
|
||||
color: muted ? Colors.white : Colors.blueAccent,
|
||||
size: 20.0,
|
||||
),
|
||||
shape: CircleBorder(),
|
||||
elevation: 2.0,
|
||||
fillColor: muted ? Colors.blueAccent : Colors.white,
|
||||
padding: EdgeInsets.all(12.0),
|
||||
),
|
||||
RawMaterialButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Icon(
|
||||
Icons.call_end,
|
||||
color: Colors.white,
|
||||
size: 35.0,
|
||||
),
|
||||
shape: CircleBorder(),
|
||||
elevation: 2.0,
|
||||
fillColor: Colors.redAccent,
|
||||
padding: EdgeInsets.all(15.0),
|
||||
),
|
||||
RawMaterialButton(
|
||||
onPressed: () {
|
||||
_engine.switchCamera();
|
||||
},
|
||||
child: Icon(
|
||||
Icons.switch_camera,
|
||||
color: Colors.blueAccent,
|
||||
size: 20.0,
|
||||
),
|
||||
shape: CircleBorder(),
|
||||
elevation: 2.0,
|
||||
fillColor: Colors.white,
|
||||
padding: EdgeInsets.all(12.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _panel()
|
||||
{
|
||||
return Visibility(
|
||||
visible: viewPanel,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 48),
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FractionallySizedBox(
|
||||
heightFactor: 0.5,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 48),
|
||||
child: ListView.builder(
|
||||
reverse: true,
|
||||
itemCount: _infoString.length,
|
||||
itemBuilder:(BuildContext context,int index)
|
||||
{
|
||||
if(_infoString.isEmpty)
|
||||
{
|
||||
return const Text("null");
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3,horizontal: 10),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(5)
|
||||
),
|
||||
child: Text(
|
||||
_infoString[index],
|
||||
style: const TextStyle(color:Colors.blueGrey),
|
||||
),
|
||||
),
|
||||
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("VideoCall"),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(onPressed:()
|
||||
{
|
||||
setState(() {
|
||||
viewPanel=!viewPanel;
|
||||
});
|
||||
}, icon: const Icon(Icons.ice_skating))
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.black,
|
||||
body: Center(
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
_viewRows(),
|
||||
_panel(),
|
||||
_toolbar(),
|
||||
]
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
import 'package:agora_rtc_engine/rtc_engine.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:async/async.dart';
|
||||
import 'dart:developer';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import './call.dart';
|
||||
import 'package:flutter/material.dart' hide Size;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
class IndexPage extends StatefulWidget {
|
||||
const IndexPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<IndexPage> createState() => _IndexPageState();
|
||||
}
|
||||
|
||||
class _IndexPageState extends State<IndexPage> {
|
||||
|
||||
TextEditingController _channelController = TextEditingController(text: 'call');
|
||||
|
||||
bool _validateError=false;
|
||||
ClientRole? _role= ClientRole.Broadcaster;
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_channelController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("VideoCall"),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children:<Widget> [
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
controller: _channelController,
|
||||
decoration: InputDecoration(
|
||||
errorText: _validateError ? 'Chanel Name is Mondatory' : null,
|
||||
border: UnderlineInputBorder(borderSide: BorderSide(width: 1),),
|
||||
hintText: 'channel name',
|
||||
),
|
||||
),
|
||||
RadioListTile(
|
||||
title: const Text('Broadcaster'),
|
||||
onChanged: (ClientRole? value)
|
||||
{
|
||||
setState(() {
|
||||
_role=value;
|
||||
});
|
||||
},
|
||||
value: ClientRole.Broadcaster,
|
||||
groupValue: _role,
|
||||
),
|
||||
RadioListTile(
|
||||
title: const Text('Audience'),
|
||||
onChanged: (ClientRole? value)
|
||||
{
|
||||
setState(() {
|
||||
_role=value;
|
||||
});
|
||||
},
|
||||
value: ClientRole.Audience,
|
||||
groupValue: _role,
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: onjoin,
|
||||
child: const Text('Join'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const ui.Size(double.infinity, 40),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> onjoin() async {
|
||||
setState(() {
|
||||
_channelController.text.isEmpty
|
||||
? _validateError=true:
|
||||
_validateError=false; // This line doesn't actually update any state
|
||||
});
|
||||
|
||||
if(_channelController.text.isNotEmpty)
|
||||
{
|
||||
await _handlecameraAndMic(Permission.camera);
|
||||
await _handlecameraAndMic(Permission.microphone);
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (__) => CallPage(
|
||||
channelName: _channelController.text, // Passes the text from _channelController as channelName
|
||||
role: _role, // Passes the value of _role as role
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Future <void> _handlecameraAndMic(Permission permission) async
|
||||
{
|
||||
final status=await permission.request();
|
||||
log(status.toString());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue