This commit is contained in:
Hamza-Ayed
2024-07-07 19:23:54 +03:00
parent 50a89e02cf
commit 1589c215df
18 changed files with 602 additions and 474 deletions

View File

@@ -192,7 +192,8 @@ class UserAccountHeader extends StatelessWidget {
top: 0,
child: IconButton(
onPressed: () {
imageController.choosImage(AppLink.uploadImage1, 'portrait');
imageController.choosImagePicture(
AppLink.uploadImage1, 'portrait');
},
icon: const Icon(Icons.edit),
),

View File

@@ -1,189 +1,189 @@
import 'dart:async';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/main.dart';
import 'package:SEFER/views/widgets/my_scafold.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
// import 'dart:async';
// import 'package:SEFER/constant/box_name.dart';
// import 'package:SEFER/main.dart';
// import 'package:SEFER/views/widgets/my_scafold.dart';
// import 'package:flutter/material.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
// import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import '../../../../constant/api_key.dart';
import '../../../../controller/functions/crud.dart';
// import '../../../../constant/api_key.dart';
// import '../../../../controller/functions/crud.dart';
String appId = AK.agoraAppId;
// String appId = AK.agoraAppId;
class DriverCallPage extends StatefulWidget {
const DriverCallPage({super.key});
// class DriverCallPage extends StatefulWidget {
// const DriverCallPage({super.key});
@override
State<DriverCallPage> createState() => _DriverCallPageState();
}
// @override
// State<DriverCallPage> createState() => _DriverCallPageState();
// }
class _DriverCallPageState extends State<DriverCallPage> {
String channelName = '';
String token = '';
// "00612994c6e707543e68d5638894d04f989IAAlydoFEC3ZeZkeUwl0dSswZTX8n+xyZR8PBWdwXFV6t6MLiA8AAAAAEACCHD/gn3TUZQEAAQAAAAAA";
// class _DriverCallPageState extends State<DriverCallPage> {
// String channelName = '';
// String token = '';
// // "00612994c6e707543e68d5638894d04f989IAAlydoFEC3ZeZkeUwl0dSswZTX8n+xyZR8PBWdwXFV6t6MLiA8AAAAAEACCHD/gn3TUZQEAAQAAAAAA";
// int uid = int.parse(box.read(BoxName.phoneDriver)); // uid of the local user
int uid = 0;
int? _remoteUid; // uid of the remote user
bool _isJoined = false; // Indicates if the local user has joined the channel
late RtcEngine agoraEngine; // Agora engine instance
// // int uid = int.parse(box.read(BoxName.phoneDriver)); // uid of the local user
// int uid = 0;
// int? _remoteUid; // uid of the remote user
// bool _isJoined = false; // Indicates if the local user has joined the channel
// late RtcEngine agoraEngine; // Agora engine instance
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
GlobalKey<ScaffoldMessengerState>(); // Global key to access the scaffold
// final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
// GlobalKey<ScaffoldMessengerState>(); // Global key to access the scaffold
showMessage(String message) {
scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
content: Text(message),
));
}
// showMessage(String message) {
// scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
// content: Text(message),
// ));
// }
initAgora() async {
await fetchToken();
await setupVoiceSDKEngine();
}
// initAgora() async {
// await fetchToken();
// await setupVoiceSDKEngine();
// }
fetchToken() async {
var res = await CRUD()
.getAgoraToken(channelName: channelName, uid: uid.toString());
setState(() {
token = res;
});
}
// fetchToken() async {
// var res = await CRUD()
// .getAgoraToken(channelName: channelName, uid: uid.toString());
// setState(() {
// token = res;
// });
// }
@override
void initState() {
super.initState();
_remoteUid = box.read(BoxName.phone) != null
? int.parse(box.read(BoxName.phone))
: int.parse(box.read(BoxName.phoneDriver));
uid = box.read(BoxName.phoneDriver) != null
? int.parse(box.read(BoxName.phoneDriver))
: int.parse(box.read(BoxName.phone));
// Set up an instance of Agora engine
initAgora();
}
// @override
// void initState() {
// super.initState();
// _remoteUid = box.read(BoxName.phone) != null
// ? int.parse(box.read(BoxName.phone))
// : int.parse(box.read(BoxName.phoneDriver));
// uid = box.read(BoxName.phoneDriver) != null
// ? int.parse(box.read(BoxName.phoneDriver))
// : int.parse(box.read(BoxName.phone));
// // Set up an instance of Agora engine
// initAgora();
// }
Future<void> setupVoiceSDKEngine() async {
// retrieve or request microphone permission
await [Permission.microphone].request();
// Future<void> setupVoiceSDKEngine() async {
// // retrieve or request microphone permission
// await [Permission.microphone].request();
//create an instance of the Agora engine
agoraEngine = createAgoraRtcEngine();
await agoraEngine.initialize(RtcEngineContext(appId: AK.agoraAppId));
// Register the event handler
agoraEngine.registerEventHandler(
RtcEngineEventHandler(
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
showMessage(
"Local user uid:${connection.localUid} joined the channel");
setState(() {
_isJoined = true;
});
},
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
showMessage("Remote user uid:$remoteUid joined the channel");
setState(() {
_remoteUid = remoteUid;
});
},
onUserOffline: (RtcConnection connection, int remoteUid,
UserOfflineReasonType reason) {
showMessage("Remote user uid:$remoteUid left the channel");
setState(() {
_remoteUid = null;
});
},
),
);
}
// //create an instance of the Agora engine
// agoraEngine = createAgoraRtcEngine();
// await agoraEngine.initialize(RtcEngineContext(appId: AK.agoraAppId));
// // Register the event handler
// agoraEngine.registerEventHandler(
// RtcEngineEventHandler(
// onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
// showMessage(
// "Local user uid:${connection.localUid} joined the channel");
// setState(() {
// _isJoined = true;
// });
// },
// onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
// showMessage("Remote user uid:$remoteUid joined the channel");
// setState(() {
// _remoteUid = remoteUid;
// });
// },
// onUserOffline: (RtcConnection connection, int remoteUid,
// UserOfflineReasonType reason) {
// showMessage("Remote user uid:$remoteUid left the channel");
// setState(() {
// _remoteUid = null;
// });
// },
// ),
// );
// }
void join() async {
// Set channel options including the client role and channel profile
ChannelMediaOptions options = const ChannelMediaOptions(
clientRoleType: ClientRoleType.clientRoleBroadcaster,
channelProfile: ChannelProfileType.channelProfileCommunication,
);
// void join() async {
// // Set channel options including the client role and channel profile
// ChannelMediaOptions options = const ChannelMediaOptions(
// clientRoleType: ClientRoleType.clientRoleBroadcaster,
// channelProfile: ChannelProfileType.channelProfileCommunication,
// );
await agoraEngine.joinChannel(
token: token,
channelId: channelName,
options: options,
uid: uid,
);
}
//https://console.agora.io/invite?sign=5e9e22d06f22caeeada9954c9e908572%253A5ba8aed978a35eab5a5113742502ded2a41478b2a81cb19c71a30776e125b58a
// await agoraEngine.joinChannel(
// token: token,
// channelId: channelName,
// options: options,
// uid: uid,
// );
// }
// //https://console.agora.io/invite?sign=5e9e22d06f22caeeada9954c9e908572%253A5ba8aed978a35eab5a5113742502ded2a41478b2a81cb19c71a30776e125b58a
void leave() {
setState(() {
_isJoined = false;
_remoteUid = null;
});
agoraEngine.leaveChannel();
}
// void leave() {
// setState(() {
// _isJoined = false;
// _remoteUid = null;
// });
// agoraEngine.leaveChannel();
// }
// Clean up the resources when you leave
@override
void dispose() async {
await agoraEngine.leaveChannel();
super.dispose();
}
// // Clean up the resources when you leave
// @override
// void dispose() async {
// await agoraEngine.leaveChannel();
// super.dispose();
// }
// Build UI
@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: scaffoldMessengerKey,
home: MyScafolld(
// appBar: AppBar(
// title: const Text('Get started with Voice Calling'),
// ),
title: 'Voice Calling'.tr,
isleading: true,
body: [
ListView(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
children: [
// Status text
Container(height: 40, child: Center(child: _status())),
// Button Row
Row(
children: <Widget>[
Expanded(
child: ElevatedButton(
child: const Text("Join"),
onPressed: () => {join()},
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
child: const Text("Leave"),
onPressed: () => {leave()},
),
),
],
),
],
),
]),
);
}
// // Build UI
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// scaffoldMessengerKey: scaffoldMessengerKey,
// home: MyScafolld(
// // appBar: AppBar(
// // title: const Text('Get started with Voice Calling'),
// // ),
// title: 'Voice Calling'.tr,
// isleading: true,
// body: [
// ListView(
// padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
// children: [
// // Status text
// Container(height: 40, child: Center(child: _status())),
// // Button Row
// Row(
// children: <Widget>[
// Expanded(
// child: ElevatedButton(
// child: const Text("Join"),
// onPressed: () => {join()},
// ),
// ),
// const SizedBox(width: 10),
// Expanded(
// child: ElevatedButton(
// child: const Text("Leave"),
// onPressed: () => {leave()},
// ),
// ),
// ],
// ),
// ],
// ),
// ]),
// );
// }
Widget _status() {
String statusText;
// Widget _status() {
// String statusText;
if (!_isJoined)
statusText = 'Join a channel';
else if (_remoteUid == null)
statusText = 'Waiting for a remote user to join...';
else
statusText = 'Connected to remote user, uid:$_remoteUid';
// if (!_isJoined)
// statusText = 'Join a channel';
// else if (_remoteUid == null)
// statusText = 'Waiting for a remote user to join...';
// else
// statusText = 'Connected to remote user, uid:$_remoteUid';
return Text(
statusText,
);
}
}
// return Text(
// statusText,
// );
// }
// }

View File

@@ -1,84 +1,84 @@
import 'package:SEFER/constant/colors.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/firebase/firbase_messge.dart';
import 'package:SEFER/controller/home/captin/map_driver_controller.dart';
import 'package:SEFER/views/widgets/my_scafold.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
// import 'package:SEFER/constant/colors.dart';
// import 'package:SEFER/constant/style.dart';
// import 'package:SEFER/controller/firebase/firbase_messge.dart';
// import 'package:SEFER/controller/home/captin/map_driver_controller.dart';
// import 'package:SEFER/views/widgets/my_scafold.dart';
// import 'package:flutter/material.dart';
// import 'package:get/get.dart';
// import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
import '../../../../../controller/functions/call_controller.dart';
// import '../../../../../controller/functions/call_controller.dart';
class CallPage extends StatelessWidget {
const CallPage({super.key});
// class CallPage extends StatelessWidget {
// const CallPage({super.key});
@override
Widget build(BuildContext context) {
return MyScafolld(
title: 'Call Page'.tr, isleading: true, body: [callPage()]);
}
}
// @override
// Widget build(BuildContext context) {
// return MyScafolld(
// title: 'Call Page'.tr, isleading: true, body: [callPage()]);
// }
// }
GetBuilder<HomeCaptainController> callPage() {
CallController callController = Get.put(CallController());
Get.put(MapDriverController());
// callController.join();
return GetBuilder<HomeCaptainController>(
builder: (controller) => Positioned(
top: Get.height * .2,
child: Container(
height: 100, width: Get.width,
decoration: AppStyle.boxDecoration,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GestureDetector(
onTap: () async {
callController.join();
},
child: Container(
width: 50,
height: 50,
decoration: const BoxDecoration(
shape: BoxShape.circle, color: AppColor.greenColor),
child: const Icon(
Icons.phone,
size: 35,
color: AppColor.secondaryColor,
)),
),
Column(
children: [
Text(callController.status),
Text(Get.find<MapDriverController>().passengerName.toString()),
],
),
GestureDetector(
onTap: () async {
FirebaseMessagesController().sendNotificationToPassengerToken(
'Call End'.tr,
'Call End',
Get.find<MapDriverController>().tokenPassenger,
[],
'iphone_ringtone.wav');
callController.leave();
Get.back();
},
child: Container(
width: 50,
height: 50,
decoration: const BoxDecoration(
shape: BoxShape.circle, color: AppColor.redColor),
child: const Icon(
Icons.phone_disabled_sharp,
size: 35,
color: AppColor.secondaryColor,
)),
)
],
),
// ignore: prefer_const_constructors
),
),
);
}
// GetBuilder<HomeCaptainController> callPage() {
// CallController callController = Get.put(CallController());
// Get.put(MapDriverController());
// // callController.join();
// return GetBuilder<HomeCaptainController>(
// builder: (controller) => Positioned(
// top: Get.height * .2,
// child: Container(
// height: 100, width: Get.width,
// decoration: AppStyle.boxDecoration,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: [
// GestureDetector(
// onTap: () async {
// callController.join();
// },
// child: Container(
// width: 50,
// height: 50,
// decoration: const BoxDecoration(
// shape: BoxShape.circle, color: AppColor.greenColor),
// child: const Icon(
// Icons.phone,
// size: 35,
// color: AppColor.secondaryColor,
// )),
// ),
// Column(
// children: [
// Text(callController.status),
// Text(Get.find<MapDriverController>().passengerName.toString()),
// ],
// ),
// GestureDetector(
// onTap: () async {
// FirebaseMessagesController().sendNotificationToPassengerToken(
// 'Call End'.tr,
// 'Call End',
// Get.find<MapDriverController>().tokenPassenger,
// [],
// 'iphone_ringtone.wav');
// callController.leave();
// Get.back();
// },
// child: Container(
// width: 50,
// height: 50,
// decoration: const BoxDecoration(
// shape: BoxShape.circle, color: AppColor.redColor),
// child: const Icon(
// Icons.phone_disabled_sharp,
// size: 35,
// color: AppColor.secondaryColor,
// )),
// )
// ],
// ),
// // ignore: prefer_const_constructors
// ),
// ),
// );
// }