parent
942703ed32
commit
2619c9dcdf
@ -0,0 +1,67 @@
|
||||
{
|
||||
"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:44f95d2cea26698a8a42a3",
|
||||
"android_client_info": {
|
||||
"package_name": "com.arminta.healthcare_user"
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
@ -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,235 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:healthcare_user/chat/chatzoomable_image.dart';
|
||||
import 'package:healthcare_user/common/settings.dart';
|
||||
import 'package:healthcare_user/pages/index.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 {
|
||||
const ChatPage({Key? key});
|
||||
|
||||
@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="1";
|
||||
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(AppSettings.userName,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_user/common/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,271 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:healthcare_user/common/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