This commit is contained in:
Hamza-Ayed
2024-02-18 13:44:35 +03:00
parent 4d9e76697b
commit 9d839f02ae
17 changed files with 521 additions and 30 deletions

View File

@@ -33,7 +33,7 @@ class AK {
static final String payPalSecret = Env.payPalSecret;
static final String geminiApi = Env.geminiApi;
static const String agoraAppId = '12994c6e707543e68d5638894d04f989';
static const String agoraChannelName = 'seferCall';
static const String agoraChannelName = 'sefer1';
static const String agoraToken =
'007eJxTYCjrVT009+knq6WOp9gqgx77z/CIjHtQ7PBrUdB1CZWUhUcUGAyNLC1Nks1SzQ3MTU2MU80sUkzNjC0sLE1SDEzSLC0sK4XPpjYEMjIEfg5lYWSAQBCfk6E4NS21yDkxJ4eBAQD1PiDo';
'007eJxTYAjpCZ9yKVn8k5S5blKObpxhXtrE5vXtO0+cEjrxUnR3cZ8Cg6GRpaVJslmquYG5qYlxqplFiqmZsYWFpUmKgUmapYVlVeGF1IZARoZFOjkMjFAI4rMxFKempRYZMjAAABlgHmg=';
}

View File

@@ -41,6 +41,21 @@ class CRUD {
}
}
Future<dynamic> getAgora({
required String channelName,
}) async {
var res = await http
.get(Uri.parse('http://localhost:8080/token?channelName=$channelName'));
if (res.statusCode == 200) {
var response = jsonDecode(res.body);
print(await response.stream.bytesToString());
return response['token'];
} else {
print(res.reasonPhrase);
}
}
Future<dynamic> getLlama({
required String link,
required String payload,

View File

@@ -24,6 +24,7 @@ class HomeCaptainController extends GetxController {
Timer? activeTimer;
Map data = {};
bool isLoading = true;
bool isCallOn = false;
String totalMoneyToday = '0';
String totalMoneyInSEFER = '0';
String totalDurationToday = '0';

View File

@@ -631,7 +631,7 @@ class MapDriverController extends GetxController {
LatLngBounds(northeast: northeast, southwest: southwest);
// Fit the camera to the bounds
var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 130);
var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 140);
mapController!.animateCamera(cameraUpdate);
update();
}

View File

@@ -100,7 +100,6 @@ class OrderRequestController extends GetxController {
'order_id': orderID,
'created_at': DateTime.now().toString(),
'driver_id': box.read(BoxName.driverID).toString(),
'rideId': orderID
}, TableName.driverOrdersRefuse);
getRefusedOrderByCaptain();
box.write(BoxName.statusDriverLocation, 'off');

View File

@@ -0,0 +1,97 @@
import 'package:SEFER/constant/box_name.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/home/Captin/home_captain/call_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
import '../../../../main.dart';
class CallPage extends StatelessWidget {
const CallPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(''),
),
body: callPage());
}
}
GetBuilder<HomeCaptainController> callPage() {
CallController callController = Get.put(CallController());
return GetBuilder<HomeCaptainController>(
builder: (controller) => controller.isCallOn == false
? Center(
child: Container(
height: 100,
decoration: AppStyle.boxDecoration,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GestureDetector(
onTap: () async {
// FirebaseMessagesController()
// .sendNotificationToPassengerToken(
// 'Call Income'.tr,
// 'You have call from driver ${box.read(BoxName.nameDriver)}',
// // Get.find<MapDriverController>().tokenPassenger,
// '',
// [],
// );
await callController.initAgoraFull();
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(
'passenger name'), //Get.find<MapDriverController>().passengerId.toString()),
],
),
GestureDetector(
onTap: () async {
FirebaseMessagesController()
.sendNotificationToPassengerToken(
'Call End'.tr,
'Call End',
Get.find<MapDriverController>().tokenPassenger,
[],
);
callController.leave();
},
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
),
)
: const SizedBox(),
);
}

View File

@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:SEFER/views/home/Captin/home_captain/call_controller.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
@@ -38,24 +39,13 @@ void main() async {
}
await GetStorage.init();
// Get.put(DriverCallController());
await AC().gAK();
print(
'local is t ${WidgetsBinding.instance.platformDispatcher.locale.countryCode}');
print(Get.deviceLocale!.countryCode);
Stripe.publishableKey = AK.publishableKey;
// final navigatorKey = GlobalKey<NavigatorState>();
/// 2/5: set navigator key to ZegoUIKitPrebuiltCallInvitationService
// ZegoUIKitPrebuiltCallInvitationService().setNavigatorKey(navigatorKey);
// ZegoUIKit().initLog().then((value) {
// ZegoUIKitPrebuiltCallInvitationService().useSystemCallingUI(
// [ZegoUIKitSignalingPlugin()],
// );
// runApp(MyApp(navigatorKey: navigatorKey));
// });
// StripeKey.publishableKey;
if (Platform.isAndroid || Platform.isIOS) {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,

View File

@@ -56,8 +56,7 @@ class DbSql {
'''
CREATE TABLE IF NOT EXISTS ${TableName.driverOrdersRefuse}(
id INTEGER PRIMARY KEY AUTOINCREMENT,
order_id TEXT,
rideId TEXT UNIQUE,
order_id TEXT UNIQUE,
created_at TEXT,
driver_id TEXT
)

View File

@@ -0,0 +1,127 @@
import 'package:SEFER/constant/api_key.dart';
import 'package:SEFER/controller/functions/crud.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../../../constant/box_name.dart';
import '../../../../main.dart';
class CallController extends GetxController {
String channelName =
'sefer300'; //Get.find<MapDriverController>().passengerId;
String token =
"00612994c6e707543e68d5638894d04f989IAA9fx7yHezOOXPq1l4MwrNgPVOxWj7VnirB9Ks6X37jS6MLiA8AAAAAEABXi+nQ7GjSZQEAAQAAAAAA";
// 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
String status = '';
late RtcEngine agoraEngine; // Agora engine instance
@override
void onInit() {
super.onInit();
// initAgoraFull();
}
initAgoraFull() async {
_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));
print('remoteid is $_remoteUid');
print('uid is $uid');
// await fetchToken();
// Set up an instance of Agora engine
setupVoiceSDKEngine();
}
@override
void onClose() {
agoraEngine.leaveChannel();
super.onClose();
}
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(const RtcEngineContext(appId: AK.agoraAppId));
print('eeeeeeeeeeeeeeeeeeee');
print(agoraEngine);
// Register the event handler
agoraEngine.registerEventHandler(
RtcEngineEventHandler(
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
Get.snackbar(
"Local user uid:${connection.localUid} joined the channel", '');
status = 'joined'.tr;
_isJoined = true;
update();
},
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
status = '${box.read(BoxName.nameDriver) ?? box.read(BoxName.name)}'
' joined'
.tr;
_remoteUid = remoteUid;
update();
},
onUserOffline: (RtcConnection connection, int remoteUid,
UserOfflineReasonType reason) {
Get.snackbar("Remote user uid:$remoteUid left the channel", '');
status = 'Call left'.tr;
_remoteUid = null;
update();
},
),
);
}
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,
);
}
void leave() {
_isJoined = false;
_remoteUid = null;
update();
agoraEngine.leaveChannel();
}
// Clean up the resources when you leave
@override
void dispose() async {
await agoraEngine.leaveChannel();
super.dispose();
}
fetchToken() async {
var res = await CRUD().getAgora(
channelName: 'sefer22'); //Get.find<MapDriverController>().rideId);
print('hhhhhhhhhhhhhhhhhhhhhhh');
print(res);
channelName = 'sefer22';
token = res['token'];
print('token is $token');
update();
}
}

View File

@@ -0,0 +1,173 @@
import 'dart:async';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/main.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import '../../../../constant/api_key.dart';
const String appId = AK.agoraAppId;
class DriverCallPage extends StatefulWidget {
const DriverCallPage({super.key});
@override
State<DriverCallPage> createState() => _DriverCallPageState();
}
class _DriverCallPageState extends State<DriverCallPage> {
String channelName = 'sefer300';
String token =
"00612994c6e707543e68d5638894d04f989IAACchY2SBwRcuw2mt+BocxbF+fmFKvjOS/hekkirRWfuqMLiA8AAAAAEADs3TvfbjrSZQEAAQAAAAAA";
// 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
showMessage(String message) {
scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
content: Text(message),
));
}
@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));
print('remoteid is $_remoteUid');
print('uid is $uid');
// Set up an instance of Agora engine
setupVoiceSDKEngine();
}
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(const RtcEngineContext(appId: AK.agoraAppId));
print('eeeeeeeeeeeeeeeeeeee');
print(agoraEngine);
// 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,
);
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();
}
// 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: Scaffold(
appBar: AppBar(
title: const Text('Get started with Voice Calling'),
),
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;
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,
);
}
}

View File

@@ -1,3 +1,4 @@
import 'package:SEFER/views/home/Captin/home_captain/driver_call_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
@@ -12,8 +13,10 @@ import '../../../../constant/table_names.dart';
import '../../../../controller/functions/location_controller.dart';
import '../../../../controller/home/captin/home_captain_controller.dart';
import '../../../../controller/home/captin/order_request_controller.dart';
import '../../../../controller/home/captin/widget/call_page.dart';
import '../../../../controller/home/captin/widget/connect.dart';
import '../../../../controller/home/captin/widget/left_menu_map_captain.dart';
import '../../../../controller/home/payment/captain_wallet_controller.dart';
import '../../../../controller/local/local_controller.dart';
import '../../../../main.dart';
import '../../../widgets/circle_container.dart';
@@ -27,7 +30,7 @@ class HomeCaptain extends StatelessWidget {
Widget build(BuildContext context) {
Get.put(OrderRequestController());
Get.put(HomeCaptainController());
Get.put(LocationController());
// Get.put(LocationController());
print('local is ${Get.find<LocaleController>().language!.countryCode}');
return Scaffold(
appBar: AppBar(
@@ -143,12 +146,18 @@ class HomeCaptain extends StatelessWidget {
color: AppColor.yellowColor,
),
Text(
' You Have in ${AppInformation.appName} '.tr +
' You Have in'.tr +
' ${AppInformation.appName} '.tr +
homeCaptainController.totalMoneyInSEFER,
style: AppStyle.title,
),
],
),
Text(
'Total points is '.tr +
Get.find<CaptainWalletController>().totalPoints,
style: AppStyle.title,
),
],
))),
),
@@ -187,15 +196,29 @@ class HomeCaptain extends StatelessWidget {
borderRadius: BorderRadius.circular(15)),
child: IconButton(
onPressed: () {
// Get.to(
// () => CameraWidgetCardId(),
// );
Get.to(
() => const DriverCallPage(),
);
},
icon: const Icon(Fontisto.history),
icon: const Icon(Fontisto.phone),
),
),
),
leftMainMenuCaptainIcons(),
// callPage(),
Positioned(
top: Get.height * .2,
// left: 20,
// right: 20,
bottom: Get.height * .4,
child: IconButton(
onPressed: () {
Get.to(() => const CallPage());
},
icon: const Icon(Icons.call),
),
),
],
),
);

View File

@@ -234,6 +234,22 @@ class PassengerInfoWindow extends StatelessWidget {
controller
.isArrivedSend =
false;
} else {
Get.defaultDialog(
title:
'You are not in near to passenger location'
.tr,
middleText:
'please go to picker location exactly'
.tr,
confirm:
MyElevatedButton(
title:
'Ok'.tr,
onPressed:
() {
Get.back();
}));
}
})
: const SizedBox()

View File

@@ -10,7 +10,7 @@ import '../../../constant/colors.dart';
import '../../../controller/firebase/local_notification.dart';
import '../../../controller/functions/tts.dart';
import '../../../controller/home/map_passenger_controller.dart';
import '../Captin/orderCaptin/call.dart';
import '../Captin/home_captain/driver_call_page.dart';
GetBuilder<MapPassengerController> leftMainMenuIcons() {
final textToSpeechController = Get.put(TextToSpeechController());
@@ -110,9 +110,9 @@ GetBuilder<MapPassengerController> leftMainMenuIcons() {
borderRadius: BorderRadius.circular(15)),
child: IconButton(
onPressed: () {
NotificationController()
.showNotification('Order', 'hi this is', 'tone1');
// Get.to(() => CallPage(callID: '111'));
// NotificationController()
// .showNotification('Order', 'hi this is', 'tone1');
Get.to(() => DriverCallPage());
// Get.to(() => CallPage(callID: controller.rideId));
},
icon: const Icon(

View File

@@ -1392,6 +1392,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
sha256: "74e962b7fad7ff75959161bb2c0ad8fe7f2568ee82621c9c2660b751146bfe44"
url: "https://pub.dev"
source: hosted
version: "11.3.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
sha256: "1acac6bae58144b442f11e66621c062aead9c99841093c38f5bcdcc24c1c3474"
url: "https://pub.dev"
source: hosted
version: "12.0.5"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
sha256: bdafc6db74253abb63907f4e357302e6bb786ab41465e8635f362ee71fd8707b
url: "https://pub.dev"
source: hosted
version: "9.4.0"
permission_handler_html:
dependency: transitive
description:
name: permission_handler_html
sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d"
url: "https://pub.dev"
source: hosted
version: "0.1.1"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: "23dfba8447c076ab5be3dee9ceb66aad345c4a648f0cac292c77b1eb0e800b78"
url: "https://pub.dev"
source: hosted
version: "4.2.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e"
url: "https://pub.dev"
source: hosted
version: "0.2.1"
petitparser:
dependency: transitive
description:

View File

@@ -52,8 +52,7 @@ dependencies:
fl_chart: ^0.66.0
agora_rtc_engine: ^6.2.6
flutter_tts: ^3.8.5
# zego_uikit_prebuilt_call: ^4.2.1
# zego_uikit_signaling_plugin: ^2.7.4
permission_handler: ^11.3.0

View File

@@ -14,6 +14,7 @@
#include <geolocator_windows/geolocator_windows.h>
#include <iris_method_channel/iris_method_channel_plugin_c_api.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
@@ -33,6 +34,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("IrisMethodChannelPluginCApi"));
LocalAuthPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalAuthPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

View File

@@ -11,6 +11,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
geolocator_windows
iris_method_channel
local_auth_windows
permission_handler_windows
url_launcher_windows
)